previous
contents
next

Adding a Start/Stop Button

In the Controller class:
	Panel buttonPanel = new Panel ();
	Button runButton = new Button ("  Start  ");
In the Controller class's init() method:
    buttonPanel.add (runButton);
    buttonPanel.setBackground(Color.lightGray);
    this.add (BorderLayout.SOUTH, buttonPanel);

	// Attach actions to components
    runButton.addActionListener (new ActionListener () {
      public void actionPerformed (ActionEvent event) {
        if (view.okToRun) {
          view.okToRun = false;
          showStatus ("Animation is stopped.");
          runButton.setLabel ("  Start  ");
        }
        else {
          view.okToRun = true;
          showStatus ("Animation is running.");
          runButton.setLabel ("  Stop   ");
       }
      }});