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