import java.awt.Color; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton; public class StartButton extends JButton implements ActionListener { private static final Color DEFAULT_COLOR = Color.GREEN; private AnimatedPanel squarePanel; private boolean hasBeenPressed; public StartButton(String title, AnimatedPanel panel) { super(title); this.squarePanel = panel; this.hasBeenPressed = false; this.setBackground(StartButton.DEFAULT_COLOR); this.addActionListener(this); } public void actionPerformed(ActionEvent e) { // Create a new thread for the panel and start it running, all in one shot (new Thread(this.squarePanel)).start(); this.hasBeenPressed = true; } public boolean hasBeenPressed() { return this.hasBeenPressed; } }