Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,147,902 members, 7,799,027 topics. Date: Tuesday, 16 April 2024 at 02:05 PM

Please I Need Help On This Task on java - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / Please I Need Help On This Task on java (714 Views)

Programming Competition: Search Engine Task. Rewards up for grabs. / Programmers How Would You Approach This Task? / Help On Java (2) (3) (4)

(1) (Reply) (Go Down)

Please I Need Help On This Task on java by xtianh(m): 10:27am On Nov 07, 2013
I am developing a gp calculator. How can i assign a value to selected item on the jcombobox. For example i created a jcombobox, and added A,B,C to it as its item, i want if A is selected let A be equals to 5 and multiplied by 2 and the result be pasted in a Jtextfield.

just like A = 5*2 and the result be pasted to a textfield.
I will be waiting for your reply please kindly help me out.
please don't mind my expression
Re: Please I Need Help On This Task on java by codeaddict(m): 10:42am On Nov 07, 2013
What exactly do you want answers to?
How to assign values based on a selected item? Or how to append text to a JTextField?
Re: Please I Need Help On This Task on java by chykmoni(m): 10:55am On Nov 07, 2013
Visit W3Cschool.com

1 Like

Re: Please I Need Help On This Task on java by xtianh(m): 12:32pm On Nov 07, 2013
codeaddict: What exactly do you want answers to?
How to assign values based on a selected item? Or how to append text to a JTextField?

how to assign values to a selected item. like if the items are A,B,C. when the user selects A, i want A = 5 * 2;
then the result which is 10 be displayed on a jtextfield
Re: Please I Need Help On This Task on java by jboy01(m): 12:40pm On Nov 07, 2013
xtianh: I am developing a gp calculator. How can i assign a value to selected item on the jcombobox. For example i created a jcombobox, and added A,B,C to it as its item, i want if A is selected let A be equals to 5 and multiplied by 2 and the result be pasted in a Jtextfield.

just like A = 5*2 and the result be pasted to a textfield.
I will be waiting for your reply please kindly help me out.
please don't mind my expression

create an event listener for the combox box, and if u are using an ide, in the itemStateChanged event, put

Switch (gradeComboBox.getSelectedIndex()){
Case 0:
JTextBoxResult.setText(String.valueOf(5 x 2));
break;
Case 1:
JTextBoxResult.setText(String.valueOf(4 x 2));
break;
Case 2:
JTextBoxResult.setText(String.valueOf(3 x 2));
break;
Case 3:
JTextBoxResult.setText(String.valueOf(2 x 2));
break;
Case 4:
JTextBoxResult.setText(String.valueOf(1 x 2));
break;
}
Re: Please I Need Help On This Task on java by codeaddict(m): 1:56pm On Nov 07, 2013
xtianh:

how to assign values to a selected item. like if the items are A,B,C. when the user selects A, i want A = 5 * 2;
then the result which is 10 be displayed on a jtextfield
Something similar to this:

import javax.swing.JTextArea;
import javax.swing.JFrame;
import javax.swing.JComboBox;
import java.awt.event.*;
import java.awt.FlowLayout;
public class GPA extends JFrame implements ItemListener
{
private JComboBox<String> combo;
private JTextArea textArea;
public GPA()
{
setLayout(new FlowLayout());
String[] options = {"A", "B", "C", "grin", "E"};
combo = new JComboBox<String>(options);
add(combo);
textArea = new JTextArea(2,15);
combo.addItemListener(this);
add(textArea);
textArea.setText(10 + ""wink;
pack();
setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public void itemStateChanged(ItemEvent e)
{
switch(combo.getSelectedIndex())
{
case 0:
textArea.setText(10 + ""wink;
break;
case 1:
textArea.setText(8 + ""wink;
break;
case 2:
textArea.setText(6 + ""wink;
break;
case 3:
textArea.setText(4 + ""wink;
break;
case 4:
textArea.setText(2 + ""wink;
break;
default:
break;
}
}
public static void main(String[] args)
{
GPA newV = new GPA();
}
}



Replace grin with D
Replace wink with )

1 Like

Re: Please I Need Help On This Task on java by xtianh(m): 8:43am On Nov 08, 2013
thanks to u guys.
I will be posting my area of difficulty here please i would like you to always visit and render a helping hand
Re: Please I Need Help On This Task on java by dsypha(m): 11:03pm On Nov 09, 2013
chykmoni: Visit W3Cschool.com

Not sure how u think or reason, But i thought u should remind you that commentin is not by force, W3schools for java? na wa oo

(1) (Reply)

Flight Booking Application / Can I Be A Guru In Go Progamming Without Knowledge In C++ Or Python / A Beginner's Python Tutorial/Very Simple Programs

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 15
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.