[英]How can I enable/activate a radio button after a button is clicked?
Using a jFrame in Java and I have a set of radio buttons however I want these radio buttons to be activated once I have selected a certain button. 在Java中使用jFrame,我有一组单选按钮,但是我希望一旦选择了某个按钮,就可以激活这些单选按钮。 What's the simplest way to do this?
最简单的方法是什么? Thanks
谢谢
ActionListener
to the button. ActionListener
添加到按钮。 actionPerformed()
to enable the radio buttons. actionPerformed()
以启用单选按钮。 Here is the Oracle tutorial . 这是Oracle教程 。
Here is the TutorialsPoint tutorial . 这是TutorialsPoint教程 。
This is small example to disable radio buttons. 这是禁用单选按钮的小示例。
JButton button = new JButton("Click");
JRadioButton one= new JRadioButton("one");
JRadioButton two= new JRadioButton("two");
JRadioButton three = new JRadioButton("three");
one.setEnabled(false);
two.setEnabled(false);
three.setEnabled(false);
//Group the radio buttons.
ButtonGroup group = new ButtonGroup();
group.add(one);
group.add(two);
group.add(three);
//Add action listener to button
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
// enable radion buttons.
one.setEnabled(true);
two.setEnabled(true);
three.setEnabled(true);
}
});
This is a demo idea how this thing working. 这是一个演示想法,这件事是如何工作的。 This is just a basic demo.
这只是一个基本的演示。 Button and radio buttons generated.
生成的按钮和单选按钮。 And when click button you can enable them.
当单击按钮时,您可以启用它们。
01. Generate button and three radio buttons to jframe. 01.生成按钮和三个用于jframe的单选按钮。
02. Generate button-group and add those radio buttons. 02.生成按钮组并添加这些单选按钮。
03. In buttons action listener add that " enable radio button " code. 03.在按钮动作侦听器中添加“ 启用单选按钮 ”代码。
This link will be really helpful to you. 该链接将对您确实有帮助。 Take a good look at that.
好好看一下。
You tube link 你管链接
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.