X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2FOriginView.java;h=cef40402ad8f302f6add239ddf8957ca647f77c4;hb=ea1d42c94f53ccb6d17c2014589e12a273e7a7ee;hp=a5df1ad987e4e353ad939763d51856f2c1f0bfc0;hpb=1a2ddb852431259fab5dc522d8caf5b74bb3acd8;p=Persons_Comparator.git diff --git a/src/OriginView.java b/src/OriginView.java index a5df1ad..cef4040 100644 --- a/src/OriginView.java +++ b/src/OriginView.java @@ -1,10 +1,11 @@ import javax.swing.*; +import java.awt.event.ItemEvent; +import java.awt.event.ItemListener; -public class OriginView extends JPanel { +public class OriginView extends JPanel implements ItemListener { private Origin originObj; private JLabel label; private JComboBox comboBox; - //FIXME: this label should be refreshed on country selection. private JLabel continentLabel; OriginView(Origin originObj) { @@ -13,6 +14,7 @@ public class OriginView extends JPanel { this.label.setText("Origin"); this.comboBox = new JComboBox<>(this.getOriginObj().getCountriesArray()); this.comboBox.setSelectedItem(this.getOriginObj().getCountry()); + this.comboBox.addItemListener(this); this.continentLabel = new JLabel(); this.continentLabel.setText("(" + this.getOriginObj().getContinent() + ")"); add(label); @@ -27,4 +29,17 @@ public class OriginView extends JPanel { public void setOriginObj(Origin originObj) { this.originObj = originObj; } + + public JComboBox getComboBox() { + return comboBox; + } + + @Override + public void itemStateChanged(ItemEvent event) { + if (event.getStateChange() == ItemEvent.SELECTED) { + Object item = event.getItem(); + getOriginObj().setContinent(getOriginObj().getContinentFromCountry(item.toString())); + this.continentLabel.setText("(" + this.getOriginObj().getContinent() + ")"); + } + } }