Reputation: 5
I'm trying to set a combobox in my GUI to print the the information about a student in a JLabel.
private void studentComboBoxMouseClicked(java.awt.event.MouseEvent evt) {
if combobox1="student1"{
println.jlabel."name:a";
println.jlabel.""age:12";
println.jlabel."course:english";
}
if combobox1="student2"{
println.jlabel."name:b";
println.jlabel.""age:11";
println.jlabel."course:maths";
}
if combobox1="student3"{
println.jlabel."name:c";
println.jlabel.""age:10";
println.jlabel."course:science";
}
}
Upvotes: 0
Views: 292
Reputation: 2872
You are on the right track but you need to read more tutorials. Start with the one suggested by Babban Shikaari. Your code should be something similar to this:
if (combobox.getSelectedItem().equals("student1")){
jlabel.setText("Your new information");
}
Upvotes: 0
Reputation: 240870
You have to listen for itemstatechange on your combobox, Upon selecting your student , fetch the selected item and operate on to display appropriate messages.
Upvotes: 1
Reputation: 43088
If it is a pseudocode, then it's correct. But in java the same code would be:
if ("student1".equals(combobox1)) {
jlabel.setText("name:a age:12 course:english");
} else if ("student2".equals(combobox1)) {
jlabel.setText(...);
} else if ("student3".equals(combobox1)) {
jlabel.setText(...);
}
Of course, it works if combobox1
is String, which holds the value of your combobox.
Upvotes: 0