从java中的另一个单选按钮激活一个单选按钮 [英] activate a radio button from another radio button in java

查看:62
本文介绍了从java中的另一个单选按钮激活一个单选按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好!



我的GUI和两个单选按钮 choco gecode 以及每个按钮(巧克力或地理代码)我有2个单选按钮解决方案最佳可行解决方案:我的问题在于选择按钮。让我解释一下:



当我点击单选按钮choco,我想拥有模型choco的最佳解决方案,所以我点击最佳解决方案,但收音机按钮choco不再被选中,但我需要它被选中,相同的gecode按钮。

这里是一段代码,但它不能正常工作:

Hi everyone!

I have in my GUI and two radio button choco and gecode and under each button (choco or gecode)I have 2 radio buttons solution optimal and Feasible solution: my problem lies in the selection buttons. Let me explain:

when I click the radio button choco, I want to have the optimal solution of the model choco so I click on the optimal solution, but the radio button choco is no longer selected but i need it to be selected , the same for the gecode button.
here is a piece of code but it does not work incorrectly:

if ( radio1.isSelected())// button for choco model
 {
    {

/////code
  if ( radio3.isSelected())// button for choco optimal solution
 {
       res=model.find_Optimal_Solution(n, m, R1, C1, B1, Dr1, Dc1, Db1, GainMatrix1);
       for(int i=0;i<n;i++)
       {
        for(int j=0;j<m;j++)
    System.out.print(res[i][j]+" " );
        System.out.println();
 }
 }
       else if ( radio4.isSelected())// button for choco fesable solution  
 {
       res2=model.find_realizable_solution(n, m, R1, C1, B1, Dr1, Dc1, Db1);
       System.out.println("///////////////////////////" );
       for(int i=0;i<n;i++)
       {
        for(int j=0;j<m;j++)
    System.out.print(res2[i][j]+" " );
        System.out.println();
 }}
 }
else if ( radio2.isSelected())  // button for Gocode model
 {
    if( radio5.isSelected())// button for gecode optimal solution   
    {
////some code
    }
 else if( radio6.isSelected())// button for gecode fesable solution  
   {
   }
}





我想要的是当我选择单选按钮时,当我选择属于这个choco按钮的fesable或Optimal解决方案时,choco仍然被选中(单选按钮gecode相同)



你可以帮我解决这个问题??



最好选择除了收音机按钮以外的其他方式这些satsfaire这些条件吗?



非常感谢您的帮助



what I want is that when I select the radio button choco remains selected when I select fesable or Optimal solution that belong to this choco button (same thing for the radio button gecode)

Can YOU help me to solve this problem??

is it preferable to choose another way other than the radio buttons to these satsfaire these conditions?

Thank you very much for your help

推荐答案

如果您检查JavaDoc是否有JRadioButton,您会看到它建议将单选按钮放入 ButtonGroup [ ^ ]。 ButtonGroups中的按钮只允许选择每组一个JRadioButton。



或者,您可以将按钮放在单独的容器中以达到相同的效果。
If you check the JavaDoc for a JRadioButton, you would see it suggests putting radio buttons into a ButtonGroup[^]. Buttons in ButtonGroups allow only one JRadioButton per group to be selected.

Alternatively, you can put the buttons in separate containers to achieve the same effect.


这篇关于从java中的另一个单选按钮激活一个单选按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆