public class GUI extends JFrame {
private JPanel contentPane;
private Boolean finished = false;
public Boolean isFinished() {
return finished;
}
public Rock getSelection() {
return (Rock) comboBox.getSelectedItem();
}
JComboBox<Rock> comboBox;
public GUI() {
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
setBounds(100, 100, 450, 300);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
contentPane.setLayout(new BorderLayout(0, 0));
setContentPane(contentPane);
JButton btnNewButton = new JButton("Start");
btnNewButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
finished = true;
}
});
contentPane.add(btnNewButton, BorderLayout.WEST);
comboBox = new JComboBox<Rock>();
comboBox.setModel(new DefaultComboBoxModel<Rock>(Rock.values()));
contentPane.add(comboBox, BorderLayout.CENTER);
setVisible(true);
}
}
Where Rock.java is defined as
public enum Rock {
TIN(3151), IRON(215), CLAY(45), COAL(211);
private int color;
Rock(int color) {
this.color=color;
}
public int getColor() {
return color;
}
}
Using modified color is a much better way to distinguish rocks. Every rock type has lots of ids based on the mesh but the color is the same for all of them, hence it's a better approach. You can either use the enum model comboboxes or get enum fields using the Enum#valueOf() on a String based model.
EDIT: those rock colors are not real, it's just for the sake of the example, I can't be bothered opening eclipse and looking through my projects for my actual Rock enum