import java.awt.FlowLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing.JLabel; import javax.swing.JPanel; public class Controller extends JPanel implements ActionListener { InvadersWindow parent; JButton start = new JButton("Start"); JButton quit = new JButton("Quit"); JButton fire = new JButton("Fire"); JLabel score = new JLabel("Score: 0"); public Controller(InvadersWindow _parent) { parent = _parent; setLayout(new FlowLayout()); add(quit); add(score); add(fire); add(start); quit.addActionListener(this); start.addActionListener(this); fire.addActionListener(this); } public void updateScore(int newScore) { score.setText("Score: " + newScore); } @Override public void actionPerformed(ActionEvent e) { if (e.getSource() == quit) System.exit(0); else if (e.getSource() == start) parent.start(); else if (e.getSource() == fire) parent.fire(); } }