Java 给定jRadioButton选项的jButton的ActionEvent

Java 给定jRadioButton选项的jButton的ActionEvent,java,swing,jbutton,actionlistener,jradiobutton,Java,Swing,Jbutton,Actionlistener,Jradiobutton,因此,基本上,我尝试在这里用GUI制作一个简单的程序,让我们在给定两个JradioButton的情况下进行选择,这两个JradioButton中的哪一个以类似于视觉小说的方式引导相应的故事情节。然而,问题是我很难将jButton的概念与jRadioButton的选择联系起来 这个概念是这样的:在一个框架中,有一个jTextArea,它显示形成一个故事情节的文本字符串,它提供了两个选项供选择,由两个jRadioButton表示,然后必须由一个jButton执行 到目前为止,我在ActionList

因此,基本上,我尝试在这里用GUI制作一个简单的程序,让我们在给定两个JradioButton的情况下进行选择,这两个JradioButton中的哪一个以类似于视觉小说的方式引导相应的故事情节。然而,问题是我很难将jButton的概念与jRadioButton的选择联系起来

这个概念是这样的:在一个框架中,有一个jTextArea,它显示形成一个故事情节的文本字符串,它提供了两个选项供选择,由两个jRadioButton表示,然后必须由一个jButton执行


到目前为止,我在ActionListener中为这两个jRadioButton设置的唯一逻辑是,一旦单击jRadioButton,而jButton故意为空,就必须禁用另一个jRadioButton。任何人有任何类似的程序或模块,他/她想分享,至少,从程序上讲,这个模块的逻辑?

我们通常使用单选按钮在几个选项中选择一个,一次只能选择一个按钮。要获得此功能,您需要将按钮添加到。下面是一个简单的例子:

 //Fields declared in your main GUI class
 JRadioButton option1,option2;
 JButton goButton; //executes the "Story"

 //Constructor code or place in init() method that constructor calls:
 {
    //initialize buttons and place them in your frame.
    ButtonGroup buttonGroup = new javax.swing.ButtonGroup();
    buttonGroup.add(option1);
    buttonGroup.add(option2);
    buttonGroup1.setSelected(option1.getModel(), true);
    goButton.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            goButtonActionPerformed(evt);
        }
    });

}

private void goButtonActionPerformed(java.awt.event.ActionEvent evt) {                                             
     if(option1.isSelected()) {                
         //place text in your text area
     }
     if(option2.isSelected()) {                
         //place different text in your text area
     }
}                                            

看。将它们放入
按钮组
中,您将获得默认选择,此时jButton作为按钮的行为应如何确定操作?您可以通过radiobutton API查看选择了哪个单选按钮。我不确定我是否完全理解这里的问题,我需要一个示例程序来显示:给定两个选项,选择一个。通过使用jRadioButton选择一个,其中两个将在触发jRadioButton和单击jButton后执行。需要一个示例程序来显示swing tag wiki中引用的教程中的相应章节-它包含所有swing组件的所有基本用例的示例代码+1
按钮组
;同时考虑引用相关教程和重新格式化来减少虚假空白。谢谢,我现在很明白了。