Created
December 9, 2014 11:22
-
-
Save mickeypash/e7ed23a587f03e45ae4d to your computer and use it in GitHub Desktop.
Programming Tutorial 13 Question 4
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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