Java Code

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class IfButton extends JApplet 
		implements ActionListener
{
   JButton  go, stop;
   JTextArea textarea;

   public void init( )
   {
		setLayout( new FlowLayout( ) );

		setupButtons( );

		textarea = new JTextArea( 3,10);
		add( textarea );
   }

   public void setupButtons( )
   {
    	go = new JButton( "Go!" );
    	stop = new JButton( "Stop!" );

		//add events
		go.addActionListener( this );
		stop.addActionListener( this );

		// add to applet
		add( go );
		add( stop );
   }

   public void actionPerformed( ActionEvent ae )
   {
		Object obj = ae.getSource( );
		if( obj == go )
		{
			textarea.setText( "Go GO GOOO!!!!" );
		}
		else if ( obj == stop )
		{
			textarea.setText( "STOP." );
		}
   }
} 

Back to Code Examples
©2006- by E.S.Boese. All Rights Reserved