| | |
Radio button and JButton problem
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Jun 2009
Posts: 57
Reputation:
Solved Threads: 4
Hi
how can i execute a statement if only radio button is checked and Jbutton is click? i know how to use them Individually. i try to use like this
but it did not work. pls help thx
how can i execute a statement if only radio button is checked and Jbutton is click? i know how to use them Individually. i try to use like this
Java Syntax (Toggle Plain Text)
public void actionPerformed(ActionEvent event) { Object src = event.getSource(); if (src==radio1 && src == buttonclick) JOptionPane.showMessageDialog(null,"Raido1 is checked"); }
but it did not work. pls help thx
Last edited by emint; Aug 4th, 2009 at 6:34 am.
Don't associate an action event with the radio button, but, rather, just with the jbutton, then have the listener simply check the value of the radio button. You will probably have to build up a map with the button->radio associations (or make your own "extneds JButton" class where you can store a reference to the radio button directly), however.
Java Programmer and Sun Systems Administrator
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
Java Syntax (Toggle Plain Text)
actionPerformed if (source == button) // if a hashmap radio = map.get(button) // if a new object radio = button.radio if (radio.isSelected())
I assume you know how to create a map? I assume you know how to use the "extends" keyword.
Last edited by masijade; Aug 4th, 2009 at 6:55 am.
Java Programmer and Sun Systems Administrator
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
•
•
Join Date: May 2008
Posts: 38
Reputation:
Solved Threads: 2
yep ,
Java Syntax (Toggle Plain Text)
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) { if(jRadioButton1.isSelected()) { // do the operation } else { //do nothing } }
![]() |
Similar Threads
- How to make validation of Radio Button in C# (C#)
- radio button validation problem (JavaScript / DHTML / AJAX)
- display image next to radio button list problem (PHP)
- Radio Button - AJAX - Problem with Passing Value (JavaScript / DHTML / AJAX)
- Problem with Radio Button / AJAX (JavaScript / DHTML / AJAX)
- problem in checking focus of radio button (JavaScript / DHTML / AJAX)
- Problem passing value from radio button to second page. (PHP)
Other Threads in the Java Forum
- Previous Thread: Accessing the another class from Main (the whole class)
- Next Thread: j2me game development
| Thread Tools | Search this Thread |
Tag cloud for Java
3d android api apple applet application arguments array arrays automation binary birt block bluetooth byte c# chat class classes click client code color component database designadrawingapplicationusingjavajslider detection dice draw eclipse error event exception expand file fractal game givemetehcodez graphics gui guitesting helpwithhomework html ide image inheritance input integer j2me java javaprojects jlabel jmf jni jpanel julia keyword linux list loop map method methods mobile netbeans newbie nullpointerexception number object oracle physics pong print problem program programming project read recursion reflection replaydirector ria rsa scanner screen server set size sms socket sort sql string swing test threads time transforms tree windows






