₦airaland Forum

Welcome, Guest: RegisterLoginWith GoogleTrendingRecentNew

Stats: 3,325,113 members, 8,420,423 topics. Date: Thursday, 04 June 2026 at 07:11 PM

Toggle theme

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

Nairaland ForumScience/TechnologyProgrammingPlease I Need Help On This Task on java (774 Views)

1 Reply (Go Down)

Please I Need Help On This Task on java by xtianh(op): 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
Re: Please I Need Help On This Task on java by xtianh(op): 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 )
Re: Please I Need Help On This Task on java by xtianh(op): 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

Programming Competition: Search Engine Task. Rewards up for grabs.Programmers How Would You Approach This Task?Help On Java234

Top 400 Python Projects With Source Code. Learn About Them, Make Yours & SellPython The MythPls Programmers And Web Developers Help Out