X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2FOriginView.java;h=c347bf93c1d24f33c0bda8967435d16fefc43335;hb=c8da8eb79910c7ea33dc2970ebd8d1d1db234a89;hp=2402e5fea6232f49326437c443ec1c4b1bb3a611;hpb=883508cad71557d375580ce52a4e093f131405db;p=Persons_Comparator.git diff --git a/src/OriginView.java b/src/OriginView.java index 2402e5f..c347bf9 100644 --- a/src/OriginView.java +++ b/src/OriginView.java @@ -1,17 +1,25 @@ import javax.swing.*; +import java.awt.event.ItemEvent; +import java.awt.event.ItemListener; -public class OriginView extends JComponent { +public class OriginView extends JPanel implements ItemListener { private Origin originObj; private JLabel label; + private JComboBox comboBox; + private JLabel continentLabel; - OriginView() { + 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); - } - - OriginView(Origin originObj) { - setOriginObj(originObj); + add(comboBox); + add(continentLabel); } public Origin getOriginObj() { @@ -21,4 +29,13 @@ public class OriginView extends JComponent { public void setOriginObj(Origin originObj) { this.originObj = originObj; } + + @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() + ")"); + } + } }