| 1 | import javax.swing.*; |
| 2 | import java.util.Arrays; |
| 3 | |
| 4 | public class EyeView extends JPanel { |
| 5 | private Eye eyeObj; |
| 6 | private JLabel label; |
| 7 | private JList colorsList; |
| 8 | |
| 9 | /** |
| 10 | * @param eyeObj |
| 11 | */ |
| 12 | EyeView(Eye eyeObj) { |
| 13 | setEyeObj(eyeObj); |
| 14 | this.label = new JLabel(); |
| 15 | this.label.setText("Eyes color"); |
| 16 | this.colorsList = new JList<>(this.getEyeObj().getColorsList()); |
| 17 | this.colorsList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); |
| 18 | this.colorsList.setLayoutOrientation(JList.VERTICAL); |
| 19 | this.colorsList.setSelectedIndex(Arrays.asList(this.getEyeObj().getColorsList()).indexOf(this.getEyeObj().getStrColor())); |
| 20 | add(label); |
| 21 | add(colorsList); |
| 22 | } |
| 23 | |
| 24 | /** |
| 25 | * @return |
| 26 | */ |
| 27 | public Eye getEyeObj() { |
| 28 | return eyeObj; |
| 29 | } |
| 30 | |
| 31 | /** |
| 32 | * @param eyeObj |
| 33 | */ |
| 34 | public void setEyeObj(Eye eyeObj) { |
| 35 | this.eyeObj = eyeObj; |
| 36 | } |
| 37 | } |