知道GUI框架怎么写就行
1.定义jFRame
2.分开写测试类
3.给几个按钮
4.负责提供测试器
这样就把框架打好了
主程序-继承某个类
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;public class RadioButtonApp {public static void main(String[] args) {JFrame frame = new JFrame("单选按钮");frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);frame.setSize(300, 200);frame.setLayout(new FlowLayout());JRadioButton radioButton1 = new JRadioButton("选项1");JRadioButton radioButton2 = new JRadioButton("选项2");JRadioButton radioButton3 = new JRadioButton("选项3");// 创建一个组,确保只能选择一个按钮ButtonGroup group = new ButtonGroup();group.add(radioButton1);group.add(radioButton2);group.add(radioButton3);radioButton1.addActionListener(new ActionListener() {@Overridepublic void actionPerformed(ActionEvent e) {JOptionPane.showMessageDialog(frame, "你选择了选项1");radioButton1.setVisible(false);}});radioButton2.addActionListener(new ActionListener() {@Overridepublic void actionPerformed(ActionEvent e) {JOptionPane.showMessageDialog(frame, "你选择了选项2");radioButton2.setVisible(false);}});radioButton3.addActionListener(new ActionListener() {@Overridepublic void actionPerformed(ActionEvent e) {JOptionPane.showMessageDialog(frame, "你选择了选项3");radioButton3.setVisible(false);}});frame.add(radioButton1);frame.add(radioButton2);frame.add(radioButton3);frame.setVisible(true);}
}