首页 > 解决方案 > 多个意图取决于选择的单选按钮

问题描述

可以根据选择的单选按钮转到特定课程吗?是否可以在 onClick 中为新意图创建 if-else 语句?

例如,

圆形、方形、三角形单选组按钮。圈子已被选中。

在 "onClick" 中有一个 if-else 语句有 "circle.class", "square.class", "triangle.class" 意图会转到 "circle.class"

标签: javaandroidif-statement

解决方案


是的,很有可能!你要做的就是调用所需类的mainn方法(或任何其他方法)如果方法是静态的,直接通过类引用调用它,它是非静态的,然后使用该类的对象(注意NullPointerException 虽然)

1)确保您的圆形或三角形(或其他)类已创建

您可以:在 jRadioButton1 的 ActionPerformed() 事件下

   // should be the name of your button, say CircleActionPerformed() 
   private void jRadioButton1ActionPerformed(java.awt.event.ActionEvent evt) 
    {  
       
        if(jRadioButton.isSelected() == true)
        {
                circle.main() // 
        }
    }

    

推荐阅读