
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.

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();
}
}
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.