Skip to content

Instantly share code, notes, and snippets.

@mickeypash
Created December 9, 2014 11:22
Show Gist options
  • Save mickeypash/e7ed23a587f03e45ae4d to your computer and use it in GitHub Desktop.
Save mickeypash/e7ed23a587f03e45ae4d to your computer and use it in GitHub Desktop.
Programming Tutorial 13 Question 4
import java.x.swing *;
import java.awt *;
import java.awt.event *;
public Class ThreeColorsComboBox extends JFrame implements ActionListener{
private JComboBox colorCombo;
private JPanel colorPanel;
public ThreeColorsComboBox () {
colorPanel = new JPanel;
add(colorPanel, Border-Layout.CENTER);
colorCombo = new JComboBox ("Color");
colorCombo = addItem("red");
colorCombo = addItem("green");
colorCombo = addItem("blue");
JPanel southPanel = new JPanel();
southPanel.addColorCombo;
colorCombo.addActionListener(this);
}
public void actionPerformed(ActionEvent e){
String choice = (String) colorCombo.getSelectedItem();
if (choice.equals("red")){
colorPanel.setBackground(Color.RED);
}
else if (choice.equals("green")){
colorPanel.setBackground(Color.GREEN);
}
else {
colorPanel.setBackground(Color.BLUE);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment