谁能凋试一下
import javax.swing.*;import java.awt.*;
import java.awt.event.*;
class RadioButton extends JFrame implements ItemListener
{
JLabel label;
JRadioButton eastButton;
JRadioButton southButton;
JRadioButton westButton;
JRadioButton northButton;
JPanel panel;
RadioButon(String s)
{
super(s);
panel=new JPanel();
eastButton=new JRadioButton("EAST");
southButton=new JRadioButton("SOUTH");
westButton=new JRadioButton("WEST");
northButton=new JRadioButton("NORTH");
ButtonGroup group=new ButtonGroup();
group.add(eastButton);
group.add(southButton);
group.add(westButton);
group.add(northButton);
Container con=getContentPane();
con.add(label);
con.add(panel,BorderLayout.SOUTH);
panel.add(eastButton);
panel.add(southButton);
panel.add(westButton);
panel.add(northButton);
eastButton.addItemListener(this);
southButton.addItemListener(this);
westButton.addItemListener(this);
northButton.addItemListener(this);
label=new JLabel("you choose:");
setSize(300,200);
setVisible(true);
}
public void itemStateChanged(ItemEvent e)
{
if(e.getItemSelectLable()==eastButton)
label.setText("you choosed EAST");
if(e.getItemSelectLable()==southButton)
label.setText("you choosed SOUTH");
if(e.getItemSelectLable()==westButton)
label.setText("you choosed WEST");
if(e.getItemSelectLable()==northButton)
label.setText("you choosed NORTH");
}
}
public class Bh35
{
public static void main(String args[])
{
RadioButon a=new RadioButon("小程序");
a.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}