2 import java
.awt
.event
.ItemEvent
;
3 import java
.awt
.event
.ItemListener
;
5 public class WeightView
extends JPanel
implements ItemListener
{
6 private Weight weightObj
;
8 private JComboBox
<Integer
> comboBox
;
10 WeightView(Weight weightObj
) {
11 setWeightObj(weightObj
);
12 this.label
= new JLabel();
13 this.label
.setText("Weight (kilograms)");
14 this.comboBox
= new JComboBox
<>(this.getWeightObj().getValuesArray());
15 if (this.getWeightObj().getWeight() != 0)
16 this.comboBox
.setSelectedItem(this.getWeightObj().getWeight());
18 this.comboBox
.setSelectedItem(this.getWeightObj().getDefaultWeight());
19 this.comboBox
.addItemListener(this);
24 public Weight
getWeightObj() {
28 public void setWeightObj(Weight weightObj
) {
29 this.weightObj
= weightObj
;
32 public JComboBox
<Integer
> getComboBox() {
37 public void itemStateChanged(ItemEvent event
) {
38 if (event
.getStateChange() == ItemEvent
.SELECTED
) {
39 Object item
= event
.getItem();
40 PersonLeftPanel personLeftPanel
= MainWindowsView
.getInstance().getCurrentPersonView().getPersonPanel().getLeftPanel();
41 personLeftPanel
.drawWeight((int) item
);