X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2FWeightView.java;h=7e029fa1799330896cd685bfec04b3d68d806c42;hb=e16e3b1587a729dd1e2d39bd4426831136376aa7;hp=239c437556dededfbbaf3839a0dba0b5c528d89b;hpb=883508cad71557d375580ce52a4e093f131405db;p=Persons_Comparator.git diff --git a/src/WeightView.java b/src/WeightView.java index 239c437..7e029fa 100644 --- a/src/WeightView.java +++ b/src/WeightView.java @@ -1,17 +1,24 @@ import javax.swing.*; +import java.awt.event.ItemEvent; +import java.awt.event.ItemListener; -public class WeightView extends JComponent { +public class WeightView extends JPanel implements ItemListener { private Weight weightObj; private JLabel label; - - WeightView() { - this.label = new JLabel(); - this.label.setText("Weight"); - add(label); - } + private JComboBox comboBox; WeightView(Weight weightObj) { setWeightObj(weightObj); + this.label = new JLabel(); + this.label.setText("Weight (kilograms)"); + this.comboBox = new JComboBox<>(this.getWeightObj().getValuesArray()); + if (this.getWeightObj().getWeight() != 0) + this.comboBox.setSelectedItem(this.getWeightObj().getWeight()); + else + this.comboBox.setSelectedItem(this.getWeightObj().getDefaultWeight()); + this.comboBox.addItemListener(this); + add(label); + add(comboBox); } public Weight getWeightObj() { @@ -21,4 +28,17 @@ public class WeightView extends JComponent { public void setWeightObj(Weight weightObj) { this.weightObj = weightObj; } + + public JComboBox getComboBox() { + return comboBox; + } + + @Override + public void itemStateChanged(ItemEvent event) { + if (event.getStateChange() == ItemEvent.SELECTED) { + Object item = event.getItem(); + PersonLeftPanel personLeftPanel = MainWindowsView.getInstance().getCurrentPersonView().getPersonPanel().getLeftPanel(); + personLeftPanel.drawWeight((int) item); + } + } }