X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2FOriginView.java;h=cef40402ad8f302f6add239ddf8957ca647f77c4;hb=9b3bfcdd95253a04ed12a676ee29a9d777c1e496;hp=3c3b5183367901c7062e77b33ca7beaad310052c;hpb=d119e60d58d8431de3ff29090d7048b0eb7d9f9e;p=Persons_Comparator.git diff --git a/src/OriginView.java b/src/OriginView.java index 3c3b518..cef4040 100644 --- a/src/OriginView.java +++ b/src/OriginView.java @@ -1,14 +1,25 @@ 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; + private JLabel continentLabel; OriginView(Origin originObj) { setOriginObj(originObj); this.label = new JLabel(); 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); + add(comboBox); + add(continentLabel); } public Origin getOriginObj() { @@ -18,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() + ")"); + } + } }