Why doesn't this work?
String [] auswahlmöglichkeiten_währung2 = {"Euro", "Dollar", "Yen"};
JComboBox zweite_Combobox = new JComboBox(auswahlmöglichkeiten_währung2);
zweite_Combobox.setVisible(true);
zweite_Combobox.setBounds(200,65,120,45);
zweite_Combobox.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
}
});
String[] auswahlmöglichkeiten_währung = {"Euro", "Dollar", "Yen"};
JComboBox erste_Combobox = new JComboBox(auswahlmöglichkeiten_währung);
erste_Combobox.setVisible(true);
erste_Combobox.setBounds(20, 65, 120, 45);
erste_Combobox.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (e.getSource() == erste_Combobox) {
JComboBox neue_Combobox = (JComboBox)e.getSource();
String währung1 = (String)neue_Combobox.getSelectedItem();
switch (währung1){
case "Euro":
if (e.getSource() == zweite_Combobox){
JComboBox neue_Combobox1 = (JComboBox)e.getSource();
String währung2 = (String)neue_Combobox1.getSelectedItem();
switch (währung2){
case "Euro":
System.out.println("You picked euro two times");
break;
}
What Im trying to do here is print out the line "You picked euro two times", but only if the user selected "Euro" in the first Combobox and in the second. There's no error, but doesn work. What did I do wrong or how can I "connect" two Strings of two different Comboboxes?
Aucun commentaire:
Enregistrer un commentaire