/** * Author: Josiah Yoder et al. * Class: SE1021-031 * Date: 1/7/14 10:31 AM * Lesson: Week 4, Day 1 */ package example4_3_3; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import java.awt.FlowLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; public class GUI extends JFrame { private JButton button; private JLabel label; private final static int WIDTH = 250; private final static int HEIGHT = 100; public static void main(String[] args) { JFrame gui = new GUI(); } /* Constructor */ public GUI() { setTitle("Dog and Pony Show"); setSize(WIDTH, HEIGHT); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setLayout(new FlowLayout()); label = new JLabel("Dog"); add(label); // Things you can do with label // label.setText("Pony"); // label.setVisible(false); ButtonListener listener = new ButtonListener(); button = new JButton(); button.addActionListener(listener); add(button); setVisible(true); } private class ButtonListener implements ActionListener { @Override public void actionPerformed(ActionEvent e) { System.out.println("Button Listener called"); label.setText("Pony"); } } }