Results 1 to 5 of 5
  1. #1
    _rapt0r_ is offline Member
    Join Date
    Nov 2011
    Posts
    24
    Rep Power
    0

    Default problem with radiobutton

    well I wanted to select a radioButton a global variable takes the value of true and returns true in that class. But when I try to send the value to another class it is assigned the value false

    part of the code for the boolean and radiobutton
    Java Code:
    public class GUI extends javax.swing.JFrame {  
       informationRequest info;  
       private static boolean RMI = false;
    Java Code:
    private void jRadioButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                                
      
         if(RMI==false)  
                RMI=true;  
            else  
                RMI=false;  
         test.setText("the value is"+RMI);  
    }
    in this moment returns true when i selected the radio button..

    Java Code:
    public synchronized void run(informationRequest info) {  
    this.info = info;  
      
              UDPRecebe udp = new UDPRecebe(info, RMI);  
              Thread t1 = new Thread(udp);  
              t1.start();

    the other class


    Java Code:
    boolean RMI;  
    String s1;  
    private String rsp;  
    private String challanger;  
    public UDPRecebe(informationRequest inf, boolean RMI){  
        this.inf = inf;  
        this.RMI = RMI;  
    
    ....
    
    System.out.println(RMI); 
    }
    in this point returns false?? why?? :S

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: problem with radiobutton

    It's hard for me to tell what's wrong based on the snippets of code posted. You might want to try to simplify your problem greatly by creating a GUI program that is small, compilable and runnable by us, and that reproduces your problem.

    If it were my program though, I wouldn't even use a boolean variable but instead would use myRadioButton.isSelected() for my boolean at the time that it is needed.

  3. #3
    _rapt0r_ is offline Member
    Join Date
    Nov 2011
    Posts
    24
    Rep Power
    0

    Default Re: problem with radiobutton

    you say like this??

    private void jRadioButton1ActionPerformed(java.awt.event.Action Event evt) {
    // TODO add your handling code here:
    if(!selected ){
    RMI = jRadioButton1.isSelected();


    selected = true;
    }

    namePlayer.setText("teste"+RMI);
    }

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: problem with radiobutton

    No. Wherever you're using your boolean variable RMI (which is mis-capitalized by the way), you would use the radiobutton's state itself:

    Java Code:
    UDPRecebe udp = new UDPRecebe(info, jRadioButton1.isSelected());
    I rarely give JRadioButton's ActionListeners since usually I don't want to know the state of the button when it has been pressed but rather when some other event takes place, such as if the user presses some "Accept" button.

  5. #5
    _rapt0r_ is offline Member
    Join Date
    Nov 2011
    Posts
    24
    Rep Power
    0

    Default Re: problem with radiobutton

    give'me false, but i resolve the problem with a check box..

    like this

    boolean checked = jCheckBox1.isSelected();
    if(checked){

    UDPRecebe udp = new UDPRecebe(info, true);
    Thread t1 = new Thread(udp);
    t1.start();

    }else {
    UDPRecebe udp = new UDPRecebe(info, false);
    Thread t1 = new Thread(udp);
    t1.start();
    }

Similar Threads

  1. about radiobutton
    By acat in forum New To Java
    Replies: 11
    Last Post: 04-13-2011, 03:27 AM
  2. Help with radiobutton!
    By goffy in forum New To Java
    Replies: 1
    Last Post: 05-09-2010, 04:14 PM
  3. RadioButton clearSelection Problem
    By Aniczka in forum New To Java
    Replies: 3
    Last Post: 10-31-2009, 02:26 PM
  4. uses of radiobutton...
    By mlibot in forum New To Java
    Replies: 22
    Last Post: 09-17-2009, 08:33 AM
  5. RadioButton
    By tiger100plus in forum New To Java
    Replies: 1
    Last Post: 01-05-2009, 08:04 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •