import java.awt.*;
import javax.swing.*;
class GUI extends JFrame
{
JButton btn1 = new JButton("Button 1");
JButton btn2 = new JButton("Button 2");
JRadioButton radYes=new JRadioButton("Yes",true);
JRadioButton radNo=new JRadioButton("No",false);
ButtonGroup radioGroup1 = new ButtonGroup();
RadioButtonListener rbListener=new RadioButtonListener();
ButtonListener btListener=new ButtonListener();
GUI()
{
Container c=getContentPane();
c.setLayout(null);
c.add(btn1);
c.add(btn2);
c.add(radYes);
c.add(radNo);
radioGroup1.add(radYes);
radioGroup1.add(radNo);
radYes.addActionListener(rbListener);
radNo.addActionListener(rbListener);
btn1.addActionListener(btnListener);
btn2.addActionListener(btnListener);
radYes.setBounds(30,30,50,40);
radNo.setBounds(30,80,50,40);
btn1.setBounds(130,30,200,40);
btn2.setBounds(130,80,200,40);
setSize(380,200);
setTitle("GUI Demo with Radio Button "+"and Button Listener");
setVisible(true);
setResizable(false);
}
}
不知道怎么搞的,我怎么编译都出现错误,楼主能不能帮帮我啊!小弟这里先谢谢了!