Start the implementation of inputs gathering and the comparator code (still buggy...
[Persons_Comparator.git] / src / OriginView.java
1 import javax.swing.*;
2 import java.awt.event.ItemEvent;
3 import java.awt.event.ItemListener;
4
5 public class OriginView extends JPanel implements ItemListener {
6 private Origin originObj;
7 private JLabel label;
8 private JComboBox<String> comboBox;
9 private JLabel continentLabel;
10
11 OriginView(Origin originObj) {
12 setOriginObj(originObj);
13 this.label = new JLabel();
14 this.label.setText("Origin");
15 this.comboBox = new JComboBox<>(this.getOriginObj().getCountriesArray());
16 this.comboBox.setSelectedItem(this.getOriginObj().getCountry());
17 this.comboBox.addItemListener(this);
18 this.continentLabel = new JLabel();
19 this.continentLabel.setText("(" + this.getOriginObj().getContinent() + ")");
20 add(label);
21 add(comboBox);
22 add(continentLabel);
23 }
24
25 public Origin getOriginObj() {
26 return originObj;
27 }
28
29 public void setOriginObj(Origin originObj) {
30 this.originObj = originObj;
31 }
32
33 public JComboBox<String> getComboBox() {
34 return comboBox;
35 }
36
37 @Override
38 public void itemStateChanged(ItemEvent event) {
39 if (event.getStateChange() == ItemEvent.SELECTED) {
40 Object item = event.getItem();
41 getOriginObj().setContinent(getOriginObj().getContinentFromCountry(item.toString()));
42 this.continentLabel.setText("(" + this.getOriginObj().getContinent() + ")");
43 }
44 }
45 }