chooseteam.java

来自「21天学JAVA源代码」· Java 代码 · 共 30 行

JAVA
30
字号
import javax.swing.*;

public class ChooseTeam extends JFrame {
    JRadioButton[] teams = new JRadioButton[4];

    public ChooseTeam() {
        super("Choose Team");
        setSize(140, 190);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        teams[0] = new JRadioButton("Colorado");
        teams[1] = new JRadioButton("Dallas", true);
        teams[2] = new JRadioButton("New Jersey");
        teams[3] = new JRadioButton("Philadelphia");
        JPanel pane = new JPanel();
        ButtonGroup group = new ButtonGroup();
        for (int i = 0; i < teams.length; i++) {
            group.add(teams[i]);
            pane.add(teams[i]);
        }
        setContentPane(pane);
        show();
    }

    public static void main(String[] arguments) {
        ChooseTeam ct = new ChooseTeam();
    }
}


⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?