Java Code

import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class ButtonNoArr extends JApplet 
implements ActionListener 
{
     JLabel label;
     JButton mybuttons1 = new JButton( "one" );
     JButton mybuttons2 = new JButton( "two" );
     JButton mybuttons3 = new JButton( "three" );
     JButton mybuttons4 = new JButton( "four" );
    public void init( )
    {
        setLayout( new FlowLayout( )  );
        label = new JLabel( "Hello" );
        add( label ) ;
        
        mybuttons1.addActionListener( this );
        mybuttons2.addActionListener( this );
        mybuttons3.addActionListener( this );
        mybuttons4.addActionListener( this );

        add( mybuttons1 );
        add( mybuttons2 );
        add( mybuttons3 );
        add( mybuttons4 );
   
    }
    public void actionPerformed( ActionEvent ae )
    {
        Object obj = ae.getSource( );
        if( obj == mybuttons1 )
        {
            label.setText( "first button" );
        }
        else if ( obj == mybuttons2 )
        {
            label.setText( "second button" );
        }
        else if( obj == mybuttons3 )
        {
            label.setText( "third" );
        }
        else if( obj == mybuttons4 )
        {
            label.setText( "fourth" );
        }
    }
}


©2006 by E.S.Boese. All Rights Reserved