Commit | Line | Data |
---|---|---|
089fcbfc | 1 | import javax.swing.*; |
c8da8eb7 JB |
2 | import java.awt.event.ItemEvent; |
3 | import java.awt.event.ItemListener; | |
089fcbfc | 4 | |
c8da8eb7 | 5 | public class OriginView extends JPanel implements ItemListener { |
6977e614 | 6 | private Origin originObj; |
883508ca | 7 | private JLabel label; |
1a2ddb85 | 8 | private JComboBox<String> comboBox; |
1a2ddb85 | 9 | private JLabel continentLabel; |
6977e614 | 10 | |
b974e749 JB |
11 | OriginView(Origin originObj) { |
12 | setOriginObj(originObj); | |
883508ca JB |
13 | this.label = new JLabel(); |
14 | this.label.setText("Origin"); | |
1a2ddb85 JB |
15 | this.comboBox = new JComboBox<>(this.getOriginObj().getCountriesArray()); |
16 | this.comboBox.setSelectedItem(this.getOriginObj().getCountry()); | |
c8da8eb7 | 17 | this.comboBox.addItemListener(this); |
1a2ddb85 JB |
18 | this.continentLabel = new JLabel(); |
19 | this.continentLabel.setText("(" + this.getOriginObj().getContinent() + ")"); | |
883508ca | 20 | add(label); |
1a2ddb85 JB |
21 | add(comboBox); |
22 | add(continentLabel); | |
089fcbfc JB |
23 | } |
24 | ||
6977e614 JB |
25 | public Origin getOriginObj() { |
26 | return originObj; | |
27 | } | |
28 | ||
29 | public void setOriginObj(Origin originObj) { | |
30 | this.originObj = originObj; | |
31 | } | |
c8da8eb7 | 32 | |
9b3bfcdd JB |
33 | public JComboBox<String> getComboBox() { |
34 | return comboBox; | |
35 | } | |
36 | ||
c8da8eb7 JB |
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 | } | |
6977e614 | 45 | } |