Start the implementation of inputs gathering and the comparator code (still buggy...
[Persons_Comparator.git] / src / OriginView.java
index 58dec5d18477301742624be2325ca961576eca92..cef40402ad8f302f6add239ddf8957ca647f77c4 100644 (file)
@@ -1,8 +1,25 @@
-public class OriginView {
+import javax.swing.*;
+import java.awt.event.ItemEvent;
+import java.awt.event.ItemListener;
+
+public class OriginView extends JPanel implements ItemListener {
     private Origin originObj;
+    private JLabel label;
+    private JComboBox<String> 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() {
@@ -12,4 +29,17 @@ public class OriginView {
     public void setOriginObj(Origin originObj) {
         this.originObj = originObj;
     }
+
+    public JComboBox<String> 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() + ")");
+        }
+    }
 }