| | |
Radio button and JButton problem
![]() |
•
•
Join Date: Jun 2009
Posts: 56
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 |
2dgraphics 3d @param affinetransform android api apple applet application arc arguments array arrays automation binary binarytree bluetooth byte chat chatprogramusingobjects class client code color compare component count database derby design detection eclipse eclipsedevelopment encryption error fractal game givemetehcodez graphics gridlayout gui guitesting helpwithhomework html ide if_statement image input integer interface j2me java java.xls javadesktopapplications javaprojects jni jpanel julia keytool keyword linux list loop macintosh map method methods mobile netbeans newbie object os pong problem producer program programming project projectideas read recursion replaysolutions rim scanner server set size sms sort sql string swing terminal threads transforms tree ui unicode web windows






