Results 1 to 5 of 5
Thread: problem with radiobutton
- 12-28-2011, 08:26 PM #1
Member
- Join Date
- Nov 2011
- Posts
- 24
- Rep Power
- 0
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;in this moment returns true when i selected the radio button..Java Code:private void jRadioButton1ActionPerformed(java.awt.event.ActionEvent evt) { if(RMI==false) RMI=true; else RMI=false; test.setText("the value is"+RMI); }
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
in this point returns false?? why?? :SJava 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); }
-
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.
- 12-28-2011, 09:45 PM #3
Member
- Join Date
- Nov 2011
- Posts
- 24
- Rep Power
- 0
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);
}
-
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:
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.Java Code:UDPRecebe udp = new UDPRecebe(info, jRadioButton1.isSelected());
- 12-28-2011, 10:57 PM #5
Member
- Join Date
- Nov 2011
- Posts
- 24
- Rep Power
- 0
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
-
about radiobutton
By acat in forum New To JavaReplies: 11Last Post: 04-13-2011, 03:27 AM -
Help with radiobutton!
By goffy in forum New To JavaReplies: 1Last Post: 05-09-2010, 04:14 PM -
RadioButton clearSelection Problem
By Aniczka in forum New To JavaReplies: 3Last Post: 10-31-2009, 02:26 PM -
uses of radiobutton...
By mlibot in forum New To JavaReplies: 22Last Post: 09-17-2009, 08:33 AM -
RadioButton
By tiger100plus in forum New To JavaReplies: 1Last Post: 01-05-2009, 08:04 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks