简体   繁体   English

单击按钮后如何启用/激活单选按钮?

[英]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 谢谢

  1. Keep the radio buttons disabled initially. 最初使单选按钮处于禁用状态。
  2. Add an ActionListener to the button. ActionListener添加到按钮。
  3. Implement 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.

相关问题 单击单选按钮后如何更新Firebase中的数据? - How can I update the data in Firebase after clicked the radio button? 单击按钮时如何启用文本字段? - How can I enable a text field when a button is clicked? 如何仅在Java JFrame中按下单选按钮后才启用按钮 - How to enable a button only after a radio button was pressed in java JFrame 单击另一个按钮后如何启用/禁用按钮? - How to enable/disable button after the other button is clicked? 单击确定按钮后如何获取输入? - How can I get the inputs after the OK button is clicked? 选择单选按钮后启用复选框 - Enable CheckBoxes after Radio Button is selected 如何检查 selenium 中的单选按钮是否被单击? - How do I check if a radio button is clicked or not in selenium? 单击以启用 Java Android 开发中的按钮时,如何处理两个复选框? - How can I handle two checkbox when clicked to enable a button in Java Android develop? firefox驱动程序无法单击单选按钮 - radio button can't be clicked by firefox driver 我应如何防止Tab键激活我的单选按钮,但仍应能够专注于单选按钮的文本 - How should i prevent tab key to activate my radio button, but it still should be able to focus on text of radio button
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM