return stringArrayList.toArray(rtArray);
}
- private String getContinentFromCountry(String country) {
+ public String getContinentFromCountry(String country) {
int continentKey = -1;
for (int i = 0; i < content2DArray.length; i++) {
if (Arrays.asList(content2DArray[i]).indexOf(country) != -1) {
import javax.swing.*;
+import java.awt.event.ItemEvent;
+import java.awt.event.ItemListener;
-public class OriginView extends JPanel {
+public class OriginView extends JPanel implements ItemListener {
private Origin originObj;
private JLabel label;
private JComboBox<String> comboBox;
- //FIXME: this label should be refreshed on country selection.
private JLabel continentLabel;
OriginView(Origin originObj) {
this.label.setText("Origin");
this.comboBox = new JComboBox<>(this.getOriginObj().getCountriesArray());
this.comboBox.setSelectedItem(this.getOriginObj().getCountry());
+ this.comboBox.addItemListener(this);
this.continentLabel = new JLabel();
this.continentLabel.setText("(" + this.getOriginObj().getContinent() + ")");
add(label);
public void setOriginObj(Origin originObj) {
this.originObj = originObj;
}
+
+ @Override
+ public void itemStateChanged(ItemEvent event) {
+ if (event.getStateChange() == ItemEvent.SELECTED) {
+ Object item = event.getItem();
+ getOriginObj().setContinent(getOriginObj().getContinentFromCountry(item.toString()));
+ this.continentLabel.setText("(" + this.getOriginObj().getContinent() + ")");
+ }
+ }
}
import javax.swing.*;
import java.awt.*;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
-public class PersonView extends JPanel {
+public class PersonView extends JPanel implements ActionListener {
private int width = 400;
private int height = 600;
private Person personObj;
setWeightView(new WeightView(this.personObj.getWeight()));
setEyeView(new EyeView(this.personObj.getEye()));
+ this.compareButton.addActionListener(this);
JLabel personLabel = new JLabel("Closest person found");
personPanel.add(personLabel);
setPreferredSize(new Dimension(this.width, this.height));
public EyeView getEyeView() {
return eyeView;
}
+
+ @Override
+ public void actionPerformed(ActionEvent actionEvent) {
+
+ }
}