| | |
problem with controlling JRadio button
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Mar 2009
Posts: 20
Reputation:
Solved Threads: 0
i am havin a problem using a RadioButton to control labels on a panel.Anytime i click on one of the JRadio button it controls all the other panels at the same time instead of only controlling its label on its panel.
Please all hw do i go about setting my radio button to only control the label on its own panel and not all the labels on the other panels?
Please all hw do i go about setting my radio button to only control the label on its own panel and not all the labels on the other panels?
•
•
Join Date: Jul 2009
Posts: 19
Reputation:
Solved Threads: 0
[code = Java]
import java.awt.Font;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.ButtonGroup;
import javax.swing.JInternalFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.event.InternalFrameEvent;
import javax.swing.event.InternalFrameListener;
public class radioButon extends JInternalFrame{
//JPanel
private JPanel jContentPane = null;
//JRadioButton
private JRadioButton Radio_1 = null;
private JRadioButton Radio_2 = null;
private JRadioButton Radio_3 = null;
private ButtonGroup BttnGroupUpdType = new ButtonGroup();
//JLabel
private JLabel jlblFile = null;
public radioButon(){
super("Radio Button", false,
true, //closable
false, //icon
true); //minimizeable
this.setName("Radio Button");
initialize();
}
private void initialize(){
this.setSize(310, 230);
this.setTitle("Radio Button");
this.setResizable(false);
this.setVisible(true);
this.setContentPane(getJContentPane());
this.addInternalFrameListener(new InternalFrameListener(){
public void internalFrameActivated(InternalFrameEvent arg0) {
}
public void internalFrameClosed(InternalFrameEvent arg0) {}
public void internalFrameClosing(InternalFrameEvent arg0) {
}
public void internalFrameDeactivated(InternalFrameEvent arg0) {
}
public void internalFrameDeiconified(InternalFrameEvent arg0) {}
public void internalFrameIconified(InternalFrameEvent arg0) {}
public void internalFrameOpened(InternalFrameEvent arg0) {}
});
}
private JPanel getJContentPane() {
if (jContentPane == null) {
jlblFile = new JLabel();
jlblFile.setBounds(7, 100, 300, 16);
jlblFile.setText("Click any Radio Button! ^_^");
jlblFile.setFont(new Font("Tahoma", Font.BOLD, 12));
jlblFile.grabFocus();
jlblFile.setVisible(true);
}
jContentPane = new JPanel();
jContentPane.setLayout(null);
jContentPane.add(jlblFile,null);
jContentPane.add(getRadio_1(), null);
jContentPane.add(getRadio_2(), null);
jContentPane.add(getRadio_3(), null);
BttnGroupUpdType.add(getRadio_1());
BttnGroupUpdType.add(getRadio_2());
BttnGroupUpdType.add(getRadio_3());
getButtonUpdType();
return jContentPane;
}
private ButtonGroup getButtonUpdType(){
BttnGroupUpdType = new ButtonGroup();
BttnGroupUpdType.add(Radio_1);
BttnGroupUpdType.add(Radio_2);
BttnGroupUpdType.add(Radio_3);
return BttnGroupUpdType;
}
private JRadioButton getRadio_1() {
if (Radio_1 == null) {
Radio_1 = new JRadioButton();
Radio_1.setBounds(new Rectangle(7, 10, 200, 16));
Radio_1.setFont(new Font("Tahoma", Font.BOLD, 12));
Radio_1.setText("Radio_1");
Radio_1.setSelected(false);
Radio_1.setEnabled(true);
Radio_1.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent ae){
try {
jlblFile.setText("YOU CLICK RADIO _ 1");
}catch (Exception e) {
e.printStackTrace();
}
}
});
}
return Radio_1;
}
private JRadioButton getRadio_2() {
if (Radio_2 == null) {
Radio_2 = new JRadioButton();
Radio_2.setBounds(new Rectangle(7, 30, 200, 16));
Radio_2.setFont(new Font("Tahoma", Font.BOLD, 12));
Radio_2.setText("Radio_2");
Radio_2.setSelected(false);
Radio_2.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent ae){
try{
jlblFile.setText("What will happen!! ^_^\n"+" YOU CLICK RADIO _ 2");
}catch (Exception e) {
// TODO: handle exception
}
}
});
}
return Radio_2;
}
private JRadioButton getRadio_3() {
if (Radio_3 == null) {
Radio_3 = new JRadioButton();
Radio_3.setBounds(new Rectangle(7, 50, 200, 16));
Radio_3.setFont(new Font("Tahoma", Font.BOLD, 12));
Radio_3.setText("Radio_3");
Radio_3.setSelected(false);
Radio_3.setEnabled(true);
Radio_3.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent ae){
try {
jlblFile.setText("see!! ^_^\n"+" YOU CLICK RADIO _ 3");
}catch (Exception e) {
e.printStackTrace();
}
}
});
}
return Radio_3;
}
}
[/code]
import java.awt.Font;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.ButtonGroup;
import javax.swing.JInternalFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.event.InternalFrameEvent;
import javax.swing.event.InternalFrameListener;
public class radioButon extends JInternalFrame{
//JPanel
private JPanel jContentPane = null;
//JRadioButton
private JRadioButton Radio_1 = null;
private JRadioButton Radio_2 = null;
private JRadioButton Radio_3 = null;
private ButtonGroup BttnGroupUpdType = new ButtonGroup();
//JLabel
private JLabel jlblFile = null;
public radioButon(){
super("Radio Button", false,
true, //closable
false, //icon
true); //minimizeable
this.setName("Radio Button");
initialize();
}
private void initialize(){
this.setSize(310, 230);
this.setTitle("Radio Button");
this.setResizable(false);
this.setVisible(true);
this.setContentPane(getJContentPane());
this.addInternalFrameListener(new InternalFrameListener(){
public void internalFrameActivated(InternalFrameEvent arg0) {
}
public void internalFrameClosed(InternalFrameEvent arg0) {}
public void internalFrameClosing(InternalFrameEvent arg0) {
}
public void internalFrameDeactivated(InternalFrameEvent arg0) {
}
public void internalFrameDeiconified(InternalFrameEvent arg0) {}
public void internalFrameIconified(InternalFrameEvent arg0) {}
public void internalFrameOpened(InternalFrameEvent arg0) {}
});
}
private JPanel getJContentPane() {
if (jContentPane == null) {
jlblFile = new JLabel();
jlblFile.setBounds(7, 100, 300, 16);
jlblFile.setText("Click any Radio Button! ^_^");
jlblFile.setFont(new Font("Tahoma", Font.BOLD, 12));
jlblFile.grabFocus();
jlblFile.setVisible(true);
}
jContentPane = new JPanel();
jContentPane.setLayout(null);
jContentPane.add(jlblFile,null);
jContentPane.add(getRadio_1(), null);
jContentPane.add(getRadio_2(), null);
jContentPane.add(getRadio_3(), null);
BttnGroupUpdType.add(getRadio_1());
BttnGroupUpdType.add(getRadio_2());
BttnGroupUpdType.add(getRadio_3());
getButtonUpdType();
return jContentPane;
}
private ButtonGroup getButtonUpdType(){
BttnGroupUpdType = new ButtonGroup();
BttnGroupUpdType.add(Radio_1);
BttnGroupUpdType.add(Radio_2);
BttnGroupUpdType.add(Radio_3);
return BttnGroupUpdType;
}
private JRadioButton getRadio_1() {
if (Radio_1 == null) {
Radio_1 = new JRadioButton();
Radio_1.setBounds(new Rectangle(7, 10, 200, 16));
Radio_1.setFont(new Font("Tahoma", Font.BOLD, 12));
Radio_1.setText("Radio_1");
Radio_1.setSelected(false);
Radio_1.setEnabled(true);
Radio_1.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent ae){
try {
jlblFile.setText("YOU CLICK RADIO _ 1");
}catch (Exception e) {
e.printStackTrace();
}
}
});
}
return Radio_1;
}
private JRadioButton getRadio_2() {
if (Radio_2 == null) {
Radio_2 = new JRadioButton();
Radio_2.setBounds(new Rectangle(7, 30, 200, 16));
Radio_2.setFont(new Font("Tahoma", Font.BOLD, 12));
Radio_2.setText("Radio_2");
Radio_2.setSelected(false);
Radio_2.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent ae){
try{
jlblFile.setText("What will happen!! ^_^\n"+" YOU CLICK RADIO _ 2");
}catch (Exception e) {
// TODO: handle exception
}
}
});
}
return Radio_2;
}
private JRadioButton getRadio_3() {
if (Radio_3 == null) {
Radio_3 = new JRadioButton();
Radio_3.setBounds(new Rectangle(7, 50, 200, 16));
Radio_3.setFont(new Font("Tahoma", Font.BOLD, 12));
Radio_3.setText("Radio_3");
Radio_3.setSelected(false);
Radio_3.setEnabled(true);
Radio_3.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent ae){
try {
jlblFile.setText("see!! ^_^\n"+" YOU CLICK RADIO _ 3");
}catch (Exception e) {
e.printStackTrace();
}
}
});
}
return Radio_3;
}
}
[/code]
•
•
Join Date: Jul 2009
Posts: 19
Reputation:
Solved Threads: 0
USE [code = Java]
import java.awt.Font;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.ButtonGroup;
import javax.swing.JInternalFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.event.InternalFrameEvent;
import javax.swing.event.InternalFrameListener;
public class radioButon extends JInternalFrame{
//JPanel
private JPanel jContentPane = null;
//JRadioButton
private JRadioButton Radio_1 = null;
private JRadioButton Radio_2 = null;
private JRadioButton Radio_3 = null;
private ButtonGroup BttnGroupUpdType = new ButtonGroup();
//JLabel
private JLabel jlblFile = null;
public radioButon(){
super("Radio Button", false,
true, //closable
false, //icon
true); //minimizeable
this.setName("Radio Button");
initialize();
}
private void initialize(){
this.setSize(310, 230);
this.setTitle("Radio Button");
this.setResizable(false);
this.setVisible(true);
this.setContentPane(getJContentPane());
this.addInternalFrameListener(new InternalFrameListener(){
public void internalFrameActivated(InternalFrameEvent arg0) {
}
public void internalFrameClosed(InternalFrameEvent arg0) {}
public void internalFrameClosing(InternalFrameEvent arg0) {
}
public void internalFrameDeactivated(InternalFrameEvent arg0) {
}
public void internalFrameDeiconified(InternalFrameEvent arg0) {}
public void internalFrameIconified(InternalFrameEvent arg0) {}
public void internalFrameOpened(InternalFrameEvent arg0) {}
});
}
private JPanel getJContentPane() {
if (jContentPane == null) {
jlblFile = new JLabel();
jlblFile.setBounds(7, 100, 300, 16);
jlblFile.setText("Click any Radio Button! ^_^");
jlblFile.setFont(new Font("Tahoma", Font.BOLD, 12));
jlblFile.grabFocus();
jlblFile.setVisible(true);
}
jContentPane = new JPanel();
jContentPane.setLayout(null);
jContentPane.add(jlblFile,null);
jContentPane.add(getRadio_1(), null);
jContentPane.add(getRadio_2(), null);
jContentPane.add(getRadio_3(), null);
BttnGroupUpdType.add(getRadio_1());
BttnGroupUpdType.add(getRadio_2());
BttnGroupUpdType.add(getRadio_3());
getButtonUpdType();
return jContentPane;
}
private ButtonGroup getButtonUpdType(){
BttnGroupUpdType = new ButtonGroup();
BttnGroupUpdType.add(Radio_1);
BttnGroupUpdType.add(Radio_2);
BttnGroupUpdType.add(Radio_3);
return BttnGroupUpdType;
}
private JRadioButton getRadio_1() {
if (Radio_1 == null) {
Radio_1 = new JRadioButton();
Radio_1.setBounds(new Rectangle(7, 10, 200, 16));
Radio_1.setFont(new Font("Tahoma", Font.BOLD, 12));
Radio_1.setText("Radio_1");
Radio_1.setSelected(false);
Radio_1.setEnabled(true);
Radio_1.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent ae){
try {
jlblFile.setText("YOU CLICK RADIO _ 1");
}catch (Exception e) {
e.printStackTrace();
}
}
});
}
return Radio_1;
}
private JRadioButton getRadio_2() {
if (Radio_2 == null) {
Radio_2 = new JRadioButton();
Radio_2.setBounds(new Rectangle(7, 30, 200, 16));
Radio_2.setFont(new Font("Tahoma", Font.BOLD, 12));
Radio_2.setText("Radio_2");
Radio_2.setSelected(false);
Radio_2.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent ae){
try{
jlblFile.setText("What will happen!! ^_^\n"+" YOU CLICK RADIO _ 2");
}catch (Exception e) {
// TODO: handle exception
}
}
});
}
return Radio_2;
}
private JRadioButton getRadio_3() {
if (Radio_3 == null) {
Radio_3 = new JRadioButton();
Radio_3.setBounds(new Rectangle(7, 50, 200, 16));
Radio_3.setFont(new Font("Tahoma", Font.BOLD, 12));
Radio_3.setText("Radio_3");
Radio_3.setSelected(false);
Radio_3.setEnabled(true);
Radio_3.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent ae){
try {
jlblFile.setText("see!! ^_^\n"+" YOU CLICK RADIO _ 3");
}catch (Exception e) {
e.printStackTrace();
}
}
});
}
return Radio_3;
}
}
[\code]
import java.awt.Font;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.ButtonGroup;
import javax.swing.JInternalFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.event.InternalFrameEvent;
import javax.swing.event.InternalFrameListener;
public class radioButon extends JInternalFrame{
//JPanel
private JPanel jContentPane = null;
//JRadioButton
private JRadioButton Radio_1 = null;
private JRadioButton Radio_2 = null;
private JRadioButton Radio_3 = null;
private ButtonGroup BttnGroupUpdType = new ButtonGroup();
//JLabel
private JLabel jlblFile = null;
public radioButon(){
super("Radio Button", false,
true, //closable
false, //icon
true); //minimizeable
this.setName("Radio Button");
initialize();
}
private void initialize(){
this.setSize(310, 230);
this.setTitle("Radio Button");
this.setResizable(false);
this.setVisible(true);
this.setContentPane(getJContentPane());
this.addInternalFrameListener(new InternalFrameListener(){
public void internalFrameActivated(InternalFrameEvent arg0) {
}
public void internalFrameClosed(InternalFrameEvent arg0) {}
public void internalFrameClosing(InternalFrameEvent arg0) {
}
public void internalFrameDeactivated(InternalFrameEvent arg0) {
}
public void internalFrameDeiconified(InternalFrameEvent arg0) {}
public void internalFrameIconified(InternalFrameEvent arg0) {}
public void internalFrameOpened(InternalFrameEvent arg0) {}
});
}
private JPanel getJContentPane() {
if (jContentPane == null) {
jlblFile = new JLabel();
jlblFile.setBounds(7, 100, 300, 16);
jlblFile.setText("Click any Radio Button! ^_^");
jlblFile.setFont(new Font("Tahoma", Font.BOLD, 12));
jlblFile.grabFocus();
jlblFile.setVisible(true);
}
jContentPane = new JPanel();
jContentPane.setLayout(null);
jContentPane.add(jlblFile,null);
jContentPane.add(getRadio_1(), null);
jContentPane.add(getRadio_2(), null);
jContentPane.add(getRadio_3(), null);
BttnGroupUpdType.add(getRadio_1());
BttnGroupUpdType.add(getRadio_2());
BttnGroupUpdType.add(getRadio_3());
getButtonUpdType();
return jContentPane;
}
private ButtonGroup getButtonUpdType(){
BttnGroupUpdType = new ButtonGroup();
BttnGroupUpdType.add(Radio_1);
BttnGroupUpdType.add(Radio_2);
BttnGroupUpdType.add(Radio_3);
return BttnGroupUpdType;
}
private JRadioButton getRadio_1() {
if (Radio_1 == null) {
Radio_1 = new JRadioButton();
Radio_1.setBounds(new Rectangle(7, 10, 200, 16));
Radio_1.setFont(new Font("Tahoma", Font.BOLD, 12));
Radio_1.setText("Radio_1");
Radio_1.setSelected(false);
Radio_1.setEnabled(true);
Radio_1.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent ae){
try {
jlblFile.setText("YOU CLICK RADIO _ 1");
}catch (Exception e) {
e.printStackTrace();
}
}
});
}
return Radio_1;
}
private JRadioButton getRadio_2() {
if (Radio_2 == null) {
Radio_2 = new JRadioButton();
Radio_2.setBounds(new Rectangle(7, 30, 200, 16));
Radio_2.setFont(new Font("Tahoma", Font.BOLD, 12));
Radio_2.setText("Radio_2");
Radio_2.setSelected(false);
Radio_2.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent ae){
try{
jlblFile.setText("What will happen!! ^_^\n"+" YOU CLICK RADIO _ 2");
}catch (Exception e) {
// TODO: handle exception
}
}
});
}
return Radio_2;
}
private JRadioButton getRadio_3() {
if (Radio_3 == null) {
Radio_3 = new JRadioButton();
Radio_3.setBounds(new Rectangle(7, 50, 200, 16));
Radio_3.setFont(new Font("Tahoma", Font.BOLD, 12));
Radio_3.setText("Radio_3");
Radio_3.setSelected(false);
Radio_3.setEnabled(true);
Radio_3.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent ae){
try {
jlblFile.setText("see!! ^_^\n"+" YOU CLICK RADIO _ 3");
}catch (Exception e) {
e.printStackTrace();
}
}
});
}
return Radio_3;
}
}
[\code]
![]() |
Similar Threads
- Back button problem with $Sessions and GET (PHP)
- Php submit button problem.. (PHP)
- Back Button problem (PHP)
- [B]PROBLEM creating next and previous button?[/B] (VB.NET)
- Problem in compiler and Run button , missing file (C++)
- Swing: default button problem (Java)
- Delete button not working on my Java GUI Inventory (Java)
- problem clicking on button (Perl)
- msn border problem. (Windows Software)
- Problem passing value from radio button to second page. (PHP)
Other Threads in the Java Forum
- Previous Thread: Homework Help: arrays
- Next Thread: Filling a ComboBox....
| Thread Tools | Search this Thread |
Tag cloud for Java
-xlint 2dgraphics android api apple applet application applications arguments array arrays automation bank binary bluetooth chat class classes client code collision component database db development draw eclipse eclipsedevelopment error event exception file fractal game givemetehcodez graphics gui helpwithhomework homework html ide image input integer integration j2me jarfile java javadesktopapplications javafx javaprojects jmf jni jpanel julia learningresources linux list loop map method methods mobile netbeans newbie number object oracle print problem program programming project projectideas recursion researchinmotion scanner screen server service set size sms socket sort sorting sql sqlserver state string swing swt tcp test text-file threads time tree web windows





