import java.awt.Color;
-import java.util.List;
-import java.util.Arrays;
public class Eye implements Comparable<Eye> {
private Color color;
- private List<String> colorList = Arrays.asList("black", "green", "blue", "brown");
+ private String[] colorsList = {"black", "green", "blue", "brown"};
+
+ Eye() {
+ }
/**
* @param color
setColor(color);
}
+ public String[] getColorsList() {
+ return colorsList;
+ }
+
/**
* @return
*/
this.color = Color.getColor(color);
} else {
- throw new IllegalArgumentException("Color must be " + colorList.toString());
+ throw new IllegalArgumentException("Color must be " + colorsList);
}
}
* @return
*/
private boolean validateColor(String color) {
- return colorList.contains(color);
+ for (String c : colorsList) {
+ if (color.equals(c)) {
+ return true;
+ }
+ }
+ return false;
}
/**
public class EyeView extends JComponent {
private Eye eyeObj;
+ private JLabel label;
+ private JList colorsList;
EyeView() {
+ setEyeObj(new Eye());
+ this.label = new JLabel();
+ this.label.setText("Eyes color");
+ this.colorsList = new JList(getEyeObj().getColorsList());
+ this.colorsList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
+ add(label);
+ add(colorsList);
}
/**
this.label = new JLabel();
this.label.setText("Firstname");
this.textField = new JTextField(length);
+ if (firstnameObj != null) {
+ this.textField.setText(this.firstnameObj.getFirstname());
+ }
add(label);
add(textField);
}
setLocationRelativeTo(null);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
+ //Main pane
JPanel panel = new PersonView();
//Get all Swing/AWT primitive components in the views and add them to the panel.
public class OriginView extends JComponent {
private Origin originObj;
+ private JLabel label;
OriginView() {
+ this.label = new JLabel();
+ this.label.setText("Origin");
+ add(label);
}
OriginView(Origin originObj) {
import javax.swing.*;
public class PersonView extends JPanel {
+ private Person personObj;
private FirstnameView firstnameView;
private OriginView originView;
private SizeView sizeView;
add(eyeView);
}
- PersonView(FirstnameView firstnameView, OriginView originView, SizeView sizeView, WeightView weightView, EyeView eyeView) {
+ /* PersonView(FirstnameView firstnameView, OriginView originView, SizeView sizeView, WeightView weightView, EyeView eyeView) {
setFirstnameView(firstnameView);
setOriginView(originView);
setSizeView(sizeView);
setWeightView(weightView);
setEyeView(eyeView);
+ }*/
+
+ public Person getPersonObj() {
+ return personObj;
+ }
+
+ public void setPersonObj(Person personObj) {
+ this.personObj = personObj;
}
/**
public class SizeView extends JComponent {
private Size sizeObj;
+ private JLabel label;
SizeView() {
+ this.label = new JLabel();
+ this.label.setText("Size");
+ add(label);
}
SizeView(Size sizeObj) {
public class WeightView extends JComponent {
private Weight weightObj;
+ private JLabel label;
WeightView() {
+ this.label = new JLabel();
+ this.label.setText("Weight");
+ add(label);
}
WeightView(Weight weightObj) {