Create a Swing Applet
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class MySwing extends JApplet
{
JButton jbtn1;
JButton jbtn2;
JLabel jlab;
public void init()
{
try
{
SwingUtilities.invokeAndWait(new Runnable()
{
public void run()
{
makeGUI();
}
});
}
catch(Exception exc)
{
System.out.println("Can't create because of "+ exc);
}
}
private void makeGUI()
{
setLayout(new FlowLayout());
jbtn1 = new JButton("Alpha");
jbtn2 = new JButton("Beta");
jbtn1.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent le)
{
jlab.setText("Alpha was pressed.");
}
});
jbtn2.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent le)
{
jlab.setText("Beta was pressed.");
}
});
add(jbtn1);
add(jbtn2);
jlab = new JLabel("Press a button.");
add(jlab);
}
}