View Single Post
Old 04-23-2003, 08:36 AM   #6 (permalink)
sno2dude
Registered User
 
sno2dude's Avatar
 
Join Date: Apr 2003
Location: Michigan Tech
Posts: 38
sno2dude is on a distinguished road
Send a message via AIM to sno2dude Send a message via Yahoo to sno2dude
okay..... your main class has to extend JApplet (you can go here to see what you inherit from JApplet class) other than that its MOSTLY the same
EXAMPLE:

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

public class TwoButtons2 extends JApplet {

    //-------------------------------------------
    //
    // init - This method will be called 
    //         to set everything up
    //
    //-------------------------------------------

    public void init() {

	// set up window
        Container window = getContentPane();
	window.setLayout(new FlowLayout(FlowLayout.LEFT));

	// set up red button
	JButton red = new JButton("red");
	red.setBackground(Color.red);
	window.add(red);

	// set up green button
	JButton green = new JButton("green");
	green.setBackground(Color.green);
	window.add(green);

	// set up label
	JLabel which = new JLabel("which one?");
	which.setOpaque(true);
	which.setBackground(Color.white);
	window.add(which);

	// set up listeners
	ButtonListener redLstner =
		new ButtonListener(which, Color.red);
	red.addActionListener(redLstner);
	ButtonListener greenLstner =
		new ButtonListener(which, Color.green);
	green.addActionListener(greenLstner);

	} // end of init method

    } //end of TwoButtons2 class
    
//-------------------------------------------------------------
//
//-------------------------------------------------------------
    
class ButtonListener implements ActionListener {

    // properties
    private JLabel theLabel;
    private Color theColor;
    
    // constructor
    public ButtonListener(JLabel lbl, Color c) {
    
        theLabel = lbl;
        theColor = c;
        } // end of constructor
        
    //-------------------------------------------
    //
    // actionPerformed - called on and sent an 
    //                   ActionEvent and does 'something'
    //                   with it.
    //
    //-------------------------------------------

    public void actionPerformed(ActionEvent event) {

        theLabel.setBackground(theColor);
        } // end of actionPerformed

    } // end of ButtonListener class
sno2dude is offline   Reply With Quote