passing value of radio button

passing value of radio button

hi,i have 3 jframe built using the GUi editor in net beans 6.9. i have two radio button in the first jframe.i have to get the selected item appear on the 3rd frame after passing through the second frame.plz help me how can i do so? PLEASE note that all the codes for the jframes and radiobutton are already generated when using the Editor. my pseudo code is something like this ( if fisrtframe.radiobutton1 is selected then print frist

else print second.

please help me

I try this code in my 3rd jFrame : FirstFrame fm=new FirstFrame(); if (fm.radiobutton1.isSelected()== true){ System.out.println("First"); }

but it is not working as it is returning me radiobutton1.isSelected false ven though it is selected in the first jframe.

View Answers

February 19, 2011 at 12:44 PM

Java Swing Passing Radio button value

1)Frame1.java:

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class Frame1{
  public static void main(String[] args){
    Frame1 sr = new Frame1();
  }

  public Frame1(){
    JFrame frame = new JFrame("Radio button selection");
    JRadioButton first = new JRadioButton("First");
    JRadioButton second = new JRadioButton("Second");

    JPanel panel = new JPanel();
    panel.add(first);
    panel.add(second);

    ButtonGroup bg = new ButtonGroup();
    bg.add(first);
    bg.add(second);

    first.addActionListener(new MyAction());
    second.addActionListener(new MyAction());

    frame.add(panel, BorderLayout.NORTH);
    frame.pack();
    frame.setVisible(true);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  }

  public class MyAction implements ActionListener{
    public void actionPerformed(ActionEvent e){
      Frame2 f=new Frame2(e.getActionCommand());
      f.setVisible(true);

      }
  }
}

2)Frame2.java:

import javax.swing.*;
import java.awt.event.*;
class Frame2 extends JFrame
{
    Frame2(final String value)
    {
    setTitle("Frame2");
    JButton b=new JButton("Get selected button on third frame");
    add(b);
    setVisible(true);
    pack();
    b.addActionListener(new ActionListener(){
        public void actionPerformed(ActionEvent e){
        new Frame3(value);
        }
    });
    }
}

3)Frame3.java:

import javax.swing.*;
class Frame3 extends JFrame
{
    public Frame3(String value){
    setTitle("Frame3");
    add(new JLabel("You have selected: "+value+" radio button"));
    setVisible(true);
    pack();
    }
}

Ads









Related Tutorials/Questions & Answers:
passing value of radio button
passing value of radio button  hi,i have 3 jframe built using the GUi editor in net beans 6.9. i have two radio button in the first jframe.i have to get the selected item appear on the 3rd frame after passing through the second
radio button value on edit action
radio button value on edit action  This is my edit.jsp code...In my......Problem 'm facing is on edit action 'm not retrieving radio button value..i have used if else logic..Bt its not working...My edit.jsp code is:-Radio button name
Advertisements
Retrieve value of radio button from database to form
Retrieve value of radio button from database to form  var gn=document.getElementsByName("empg"); //empg is name of radio input type. for(var i=0;i
Struts 2 radio button value problem
Struts 2 radio button value problem  When I use s:radio tag in struts 2, I'm not able to get the selected value using document.getElementById... gives first radio option's value as the value for any option selected. Ex
check radio button on retrieving the value from database.
check radio button on retrieving the value from database.  HI i am... database and according to that i want to check the cash cheque radio button... information from database the i want to show cash radio button checked.How can i do
Drop down and radio button value on edit action
Drop down and radio button value on edit action  HI, I have... the value from dropdown and radio button.. But the problem goes with edit action... for text boxes..bt select default value for dropdown and radio button...How do
Get radio button value after submiting page
Get radio button value after submiting page  Radio buttons are dynamically generated.After selecting radio button & submitting the page , the value of the selected radio button get displayed in that jsp page. <
Selecting a radio button in jquery autocomplete from database value
Selecting a radio button in jquery autocomplete from database value  ... radio button? Here is the pertinent code: $("#name").autocomplete... to do is to select the appropriate radio button. Any pointers please
radio button
radio button  On selecting a radio button, it should open a aspx page
passing values on button click
passing values on button click  Please help me to solve this issue.I want to pass a value assigned to button to another view upon button click in xcode
How to add radio button value in a table for particular field?
How to add radio button value in a table for particular field?  Hi,I... one radio button for text field then it insert only one value absent OR present... dynamically from other table and two radio button one for present and the second
Query on radio button
Query on radio button  I am having a multiple row in jsp page.They are dynamically coming. For each row there is one radio button. I want to select one row only, i.e I want to fetch the value of row and on submitting the page
Radio button Validation
Radio button Validation  Hi.. How to validate radio button in java?if the radio button is not selected an error message should be given... Please...()==false)){ JOptionPane.showMessageDialog(null,"Please select radio button
validation of radio button
validation of radio button  There are 3 radio button as A,B,W. there are another radio as 1,2,3.if we select W in first radio button then should select 2nd one(1,2,3).if we select A or B not need select any one from 1,2,3
passing value from javascript popup
passing value from javascript popup  How to take user input and pass that input value using popup in Javascript
Struts 2 Radio Button
radio buttons and I am using Struts2 tag.I want first rado button to be selected by default.But when i select the second radio button and hit on search button i want to retain the selection of that second radio button on search list
how to check the radio button automatically depending up on the value of database when editing the form...
how to check the radio button automatically depending up on the value... to highlight the radio button from the database.......nd even list box also can any... button. When the user clicks the particular radio button, that data will get shown
how to get radio value
how to get radio value    how to retrive the option value and insert the next table pls give example
Radio Button in HTML
by the text next to the radio button. It is not the value attribute. Use of a Radio..." name="Button" value="Water"> Water<br> <input type="radio" name="Button" value="Beer"> Beer<br> <input type="radio" name="Button
validate radio button using javascript
validate radio button using javascript  validate radio button using javascript
Radio Button Problem in jsp.
Radio Button Problem in jsp.  I have a small doubt in my application, my requirement is to get a "single selectible row", I generated a radio button...="radio" value="<%=rs.getString("op1")%>" name="radio<%=i%>"/><
java radio button and exception
java radio button and exception  Dear Sir/Madam, I have problem with my addBagelRadioButton and addCheeseRadioButton. There should be only 1 radio button can be selected, but somehow 2 can be selected the same time. Also, I
iPhone Radio Button Example
iPhone Radio Button Example  Can you please suggest me how to create Radio button in my iPhone application. Actually, in my application i have two... click on that button it get selected and by default it should display unselected
Dojo Radio Button
Dojo Radio Button         .... For creating radio button you need "dijit.form.CheckBox". The radio button do some action on press.  Try Online: Radio Button The RadioButton class
dependent radio button
of the Radio Button is to select only one option at a time. So you don't need...dependent radio button  Hi. I have 4 radio buttons say all,chocolate,cookie,icecream. If I select all the other 3 should not able to be selected
access into radio button
access into radio button  access the four fields of database called access,access file and stored in radio button.please help
display contents on the same page by selecting a radio button
;input type="radio" name="bill_status " value="due" /> Received<input type="radio" name="bill_status" value="received" /> <% String... on the same page under the radio button
Radio Button in Java
Radio Button in Java       Radio Button is a circular button on web page that can be selected by the user. The AWT  Widget used to create a radio button is Checkbox
On selecting a radio button, it should open a jsp page.
On selecting a radio button, it should open a jsp page.  Hi, COuld you please tell me how to link a radio button selection to a jsp. My requirement is if I select a radio button then it should open a jsp page. thank you
pass radio button values to next page
pass radio button values to next page  how to pass selected radio button values which coming from mysql database to next page using php. Please show me with examples
Radio button with values from a String ArrayList in JSP?
Radio button with values from a String ArrayList in JSP?  Radio... input. I want to display a radio button near each course, then user selects one...;input type= "radio" name= "courses" value="<%= i.next() %>"/></td>
Radio Button in J2ME
Radio Button in J2ME      ... to demonstrate, how to create the radio button in J2ME using MIDlet. The radio button is use to choose only one option at a time. To create the radio button we
when radio button is selected corresponding jsp page should open
when radio button is selected corresponding jsp page should open  how...="form"> View Profile<input type="radio" value="view" name="radios" onclick="openPage();"><br> Edit Profile<input type="radio" value="edit" name
Java radio buttons and button groups two values
Java radio buttons and button groups two values  hi i have a problem... is clicked depending on which button was clicked male or female be sent...) .addGap(0, 0, Short.MAX_VALUE
Java radio buttons and button groups two values
Java radio buttons and button groups two values  hi i have a problem... is clicked depending on which button was clicked male or female be sent...) .addGap(0, 0, Short.MAX_VALUE
passing text value from pop up to parent page
passing text value from pop up to parent page  i want to pass value of a textbox of one pop up window to its parent page(html). that parent page contain a table. And i want to pass that text value to one cell in table of parent
Radio Button In Java
Radio Button In Java       Introduction In this section, you will learn how to create Radio Button... a radio button is created that is an item that can be selected or deselected
Write a program to design a page.use radio button?
Write a program to design a page.use radio button?  i would lik..."); radioGroup.add(Female); JButton button=new JButton("Submit"); lbl1.setBounds(50,50,70,20...); f.add(button); f.setSize(500,500); f.setVisible(true); f.setDefaultCloseOperation
Problem passing a value from one jsp to another using href
Problem passing a value from one jsp to another using href  first page.jsp <a href="common.jsp?param=<%l.get(k).parentname%>">...);%> since url print a common.jsp?param=Arts but attr return a null value
Problem passing a value from one jsp to another using href
Problem passing a value from one jsp to another using href  first page.jsp <a href="common.jsp?param=<%l.get(k).parentname%>">...);%> since url print a common.jsp?param=Arts but attr return a null value
I'm using struts2,i'm asking about the radio button validation <s:radio>
I'm using struts2,i'm asking about the radio button validation    i used this javascript code but it didnt work function valider(){ frm=document.forms['frmSaisie']; if(frm.elements['Gender'].value
How to hide and show some field on a radio button click
How to hide and show some field on a radio button click  This is my... TYPE=radio NAME="payment_method" VALUE="cash" CHECKED><b class="label">... and cheque number label and textbox to be invisible when by cash radio button
How to use radio button in jsp page
How to use radio button in jsp page       This is detailed java code how to use radio button in jsp code and display a message in another jsp page according
I'm using struts2,i'm asking about the radio button validation <s:radio>
I'm using struts2,i'm asking about the radio button validation   my...()" id="frmSaisie"> < s:radio name="cv.gender" label="Gender" list="{'Male...']; if (frm.elements['Gender'].value != "") { return true
How to identify the radio button id and row id in a table in jsp?
How to identify the radio button id and row id in a table in jsp?  ...": newcell.childNodes[0].value = ""; break...; case "date":newcell.childNodes[0].value
passing textbox value from one page to another page using html n javascript
passing textbox value from one page to another page using html n javascript  on button onclick event pass text box value and i want to pass value of variable at onclick event of button and also want to print it in textbox
Radio buttons in html
Radio buttons in html Here is an example of radio button in html.In this example we have display two radio button Male and Female. The user select only one.... Example radioButton.html <html> <head><title>Radio button
Struts2.2.1 radio Tag Example
Struts2.2.1 radio Tag Example The radio tag is a UI tag that render a radio button input field. The following Example will shows how to implement the radio...;title>Example radio Tag</title> </head> <
Radio Buttons in HTML
;  The Radio Button in HTML are type of input form, which allows... must specify the name of radio button properly.  Understand with Example... radio button at a time among alternative buttons. <input type> :The <
Maven dependency for com.vaadin - vaadin-radio-button-flow version 14.5.0 is released. Learn to use vaadin-radio-button-flow version 14.5.0 in Maven based Java projects
-button-flow released The developers of   com.vaadin - vaadin-radio... 2021, the released version of  com.vaadin - vaadin-radio-button-flow library is 14.5.0. Developer can use this version ( com.vaadin - vaadin-radio-button

Ads