/* ============================================================= * BouncingCircles.java : Extends JApplet and contains a JPanel * where circles are drawn and animated to bounce around on the * screen. Also contains a start and a stop button that start a * new circle and stop all circles, respectively. * * Written by : Vasilios Lagakos March, 2001 * ============================================================== */ import javax.swing.*; import java.awt.*; import java.awt.event.*; public class BouncingCircles extends JApplet { BouncePanel panel; JButton startButton, stopButton; public void init() { Container content = new JPanel(new BorderLayout()); panel = new BouncePanel(); content.add(panel, BorderLayout.CENTER); startButton = new JButton("Start a circle"); startButton.addActionListener(new ButtonListener()); stopButton = new JButton("Stop all circles"); stopButton.setEnabled(false); stopButton.addActionListener(new ButtonListener()); JPanel p = new JPanel(); p.add(startButton); p.add(stopButton); content.add(p, BorderLayout.SOUTH); setContentPane(content); } class ButtonListener implements ActionListener { public void actionPerformed(ActionEvent e) { if(e.getSource() == startButton){ stopButton.setEnabled(true); panel.start(); }else if (e.getSource() == stopButton) { panel.stop(); } } } } // end of class BouncingCircles