/*
 *  =============================================================
 *  BouncingCircle.java : Extends JApplet and contains a panel where
 *  circles bounce around on the screen. Also contains start and stop
 *  buttons that start circles and stop circles respectively. The JPanel
 *  component in a JApplet implements double buffering and gets rid of
 *  the flickering problem.
 *
 *  Written by : Vasilios Lagakos                     March, 2001
 *  ==============================================================
 */

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class BouncingCircle 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 circle");
	startButton.addActionListener(new ButtonListener());
	stopButton = new JButton("Stop circle");
	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){
		startButton.setEnabled(false);
		stopButton.setEnabled(true);
		panel.start();
	   }else if (e.getSource() == stopButton) {
	 	stopButton.setEnabled(false);
		startButton.setEnabled(true);
		panel.stop();
	   }
	}
   }		

   

} // end of class BouncingCircle

