Created
September 5, 2014 13:13
-
-
Save ornirus/3d144908366736f521c5 to your computer and use it in GitHub Desktop.
This file contains 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.awt.*; | |
import java.awt.event.*; | |
import javax.swing.*; | |
public class HappyOrSad extends JFrame implements ActionListener | |
{ | |
private JButton happyButton, sadButton; | |
private JPanel panel; | |
private ImageIcon happyImage, sadImage; | |
public static void main(String[] args) | |
{ | |
HappyOrSad demo = new HappyOrSad(); | |
demo.setSize(100000,110); | |
demo.createGUI(); | |
demo.setVisible(true); | |
} | |
private void createGUI() | |
{ | |
setDefaultCloseOperation(EXIT_ON_CLOSE); | |
Container window = getContentPane(); | |
window.setLayout(new FlowLayout()); | |
panel = new JPanel(); | |
panel.setPreferredSize(new Dimension(100000, 10)); | |
panel.setBackground(Color.white); | |
window.add(panel); | |
happyButton = new JButton("Haaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaappy"); | |
window.add(happyButton); | |
happyButton.addActionListener(this); | |
sadButton = new JButton("Saaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaad"); | |
window.add(sadButton); | |
sadButton.addActionListener(this); | |
} | |
public void actionPerformed(ActionEvent event) | |
{ | |
Graphics paper = panel.getGraphics(); | |
Object source = event.getSource(); | |
if (source == happyButton) { | |
paper.setColor(Color.green); | |
paper.fillOval(0, 0, 100000, 10); | |
} | |
else { | |
paper.setColor(Color.red); | |
paper.fillOval(0, 0, 100000, 10); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment