我正在使用 swing 库学习 java GUI。我知道如何制作JFrame
和添加JButton
、添加ActionListener
等,但今天JFrame
没有显示。我像往常一样做所有事情。请查看我的代码并建议我在哪里做错了..
import javax.swing.*;
import java.awt.*;
import java.util.concurrent.TimeUnit;
public class MyGroup extends JFrame {
private ButtonGroup myGroup = new ButtonGroup();
public MyGroup(){
setSize(500, 500);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLayout(new FlowLayout());
JRadioButton b1 = new JRadioButton("check1");
JRadioButton b2 = new JRadioButton("check2");
JRadioButton b3 = new JRadioButton("check3");
JRadioButton b4 = new JRadioButton("check4");
add(b1);
add(b2);
add(b3);
add(b4);
myGroup.add(b1);
myGroup.add(b2);
myGroup.add(b3);
myGroup.add(b4);
setVisible(true);
}
public static void main(String[] args) throws Exception{
ButtonGroup m = new ButtonGroup();
}
}