Java Swing 想要在重启后保留单选按钮选择
Java Swing want to keep Radio button selection after Restart
好友
我是初学者,正在尝试开发系统级别的 java swing 软件。
我在 RadioButton 组 bg 中有 2 个 JRadio 按钮,即 A 和 B。
我想在重新启动后或在进一步选择之前保留单选按钮选择。
在网上搜索了这么长时间,但得到了 PHP、HTML 等的代码。
有人请帮助我。
rdbtA = new JRadioButton("A");
contentPane.add(rdbtA);
rdbtB = new JRadioButton("B");
contentPane.add(rdbtB);
ButtonGroup bg = new ButtonGroup();
bg.add(A);
bg.add(B);
当您启动您的应用程序时,所有图形组件都会重新创建,因此您必须在关闭程序或选择发生变化时以某种方式保存选择 (最简单的方法是将您的选择保存在一个文件中)并在软件启动时(在创建按钮后)恢复它。
让我用代码解释一下:
rdbtA = new JRadioButton("A");
contentPane.add(rdbtA);
rdbtB = new JRadioButton("B");
contentPane.add(rdbtB);
/*
1. If exists a save-file, open it (else, ignore 2. and 3.)
2. read the value of previous A and previous B
3. Set these values to rdbtA and rdbtB
*/
//Rest of the code
好友
我是初学者,正在尝试开发系统级别的 java swing 软件。
我在 RadioButton 组 bg 中有 2 个 JRadio 按钮,即 A 和 B。
我想在重新启动后或在进一步选择之前保留单选按钮选择。
在网上搜索了这么长时间,但得到了 PHP、HTML 等的代码。 有人请帮助我。
rdbtA = new JRadioButton("A");
contentPane.add(rdbtA);
rdbtB = new JRadioButton("B");
contentPane.add(rdbtB);
ButtonGroup bg = new ButtonGroup();
bg.add(A);
bg.add(B);
当您启动您的应用程序时,所有图形组件都会重新创建,因此您必须在关闭程序或选择发生变化时以某种方式保存选择 (最简单的方法是将您的选择保存在一个文件中)并在软件启动时(在创建按钮后)恢复它。
让我用代码解释一下:
rdbtA = new JRadioButton("A");
contentPane.add(rdbtA);
rdbtB = new JRadioButton("B");
contentPane.add(rdbtB);
/*
1. If exists a save-file, open it (else, ignore 2. and 3.)
2. read the value of previous A and previous B
3. Set these values to rdbtA and rdbtB
*/
//Rest of the code