home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Java 1.2 How-To
/
JavaHowTo.iso
/
javafile
/
ch08
/
Action1.java
next >
Wrap
Text File
|
1998-12-14
|
2KB
|
82 lines
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Action1 extends JPanel implements ActionListener
{
public Action1()
{
JButton button1;
JRadioButton radioButton1;
JRadioButton radioButton2;
ButtonGroup grp;
//Buffer to reduce flicker
setDoubleBuffered(true);
button1 = new JButton("Button");
button1.addActionListener(this);
button1.setActionCommand("Button Activated");
add(button1);
grp = new ButtonGroup();
radioButton1 = new JRadioButton("One");
radioButton1.addActionListener(this);
radioButton1.setActionCommand("One Activated");
grp.add(radioButton1);
add(radioButton1);
radioButton2 = new JRadioButton("Two");
radioButton2.addActionListener(this);
radioButton2.setActionCommand("Two Activated");
grp.add(radioButton2);
add(radioButton2);
}//constructor
public void actionPerformed(ActionEvent e)
{
String cmd;
Object source;
source = e.getSource();
cmd = e.getActionCommand();
System.out.println("Action: "+cmd+"\n\tperformed by: "+source);
System.out.println();
}//actionPerformed
public static void main(String s[])
{
JFrame f = new JFrame("Action1 ");
Action1 panel = new Action1();
f.getContentPane().add(panel, "Center");
f.setSize(200,100);
f.setVisible(true);
f.addWindowListener(new WindowCloser());
}//main
}//class Actions
class WindowCloser extends WindowAdapter
{
public void windowClosing(WindowEvent e)
{
Window win = e.getWindow();
win.setVisible(false);
win.dispose();
System.exit(0);
}//windowClosing
}//class WindowCloser