this program is already running, but i don't know how to control
2 radio buttons at the same time.. coz the condition here is that you have to chose if male and female, and then chose your height, then the output will be displayed in the resultText. help me please.. thank you!
java
import java.awt.* ;
import java.awt.event.*;
import javax.swing.*;
public class IdealWeight extends JFrame implements ActionListener {
JRadioButton genderM, genderF;
ButtonGroup genderGroup;
JPanel genderPanel;
JRadioButton heightA, heightB, heightC, heightD, heightE;
ButtonGroup heightGroup;
JPanel heightPanel;
JTextField resultText;
JLabel resultLabl;
JPanel resultPanel;
String height1 = "60 to 64 inches";
String height2 = "64 to 68 inches";
String height3 = "68 to 72 inches";
String height4 = "72 to 76 inches";
String height5 = "76 to 80 inches";
// String height6 = "height6";
String fem = "female";
String mal = "male";
public IdealWeight() {
setTitle( "Your Ideal Weight" );
setDefaultCloseOperation( EXIT_ON_CLOSE );
// gender group
genderM = new JRadioButton(mal, true );
genderM.setActionCommand(mal);
genderM.addActionListener(this);
genderF = new JRadioButton(fem, false );
genderF.setActionCommand(fem);
genderF.addActionListener(this);
genderGroup = new ButtonGroup();
genderGroup.add( genderM ); genderGroup.add( genderF );
genderPanel = new JPanel();
genderPanel.setLayout(
new BoxLayout( genderPanel, BoxLayout.Y_AXIS ) );
genderPanel.add( new JLabel("Your Gender") );
genderPanel.add( genderM ); genderPanel.add( genderF );
// height group
heightA = new JRadioButton(height1, true );
heightA .setActionCommand(height1 );
heightA .addActionListener(this);
heightB = new JRadioButton(height2 , false );
heightB .setActionCommand( height2 );
heightB .addActionListener(this);
heightC = new JRadioButton(height3, false );
heightC.setActionCommand(height3);
heightC.addActionListener(this);
heightD = new JRadioButton(height4, false );
heightD.setActionCommand(height4);
heightD.addActionListener(this);
heightE = new JRadioButton(height5 , false );
heightE .setActionCommand(height5 );
heightE .addActionListener(this);
heightGroup = new ButtonGroup();
heightGroup.add( heightA ); heightGroup.add( heightB );
heightGroup.add( heightC ); heightGroup.add( heightD );
heightGroup.add( heightE );
heightPanel = new JPanel();
heightPanel.setLayout(
new BoxLayout( heightPanel, BoxLayout.Y_AXIS ) );
heightPanel.add( new JLabel("Your Height") );
heightPanel.add( heightA ); heightPanel.add( heightB );
heightPanel.add( heightC ); heightPanel.add( heightD );
heightPanel.add( heightE );
// result panel
resultText = new JTextField(7);
resultText.setEditable( false );
resultLabl = new JLabel("Ideal Weight");
resultPanel = new JPanel();
resultPanel.add( resultLabl );
resultPanel.add( resultText );
// content pane
getContentPane().setLayout( new BorderLayout() );
getContentPane().add( genderPanel, BorderLayout.WEST );
getContentPane().add( heightPanel, BorderLayout.EAST );
getContentPane().add( resultPanel, BorderLayout.SOUTH ); }
public void actionPerformed(ActionEvent evt) {
String get = evt.getActionCommand();
if (get.equals ("female")) { //&& (get.equals("60 to 64 inches"))
if(heightA.isSelected("60 to 64 inches"))
//{
resultText.setText("Hello");
//}
}
if (get.equals ("male"))
resultText.setText("World");
}
public static void main ( String[] args ) {
IdealWeight weightApp = new IdealWeight() ;
weightApp.setSize( 250, 225 );
weightApp.setVisible( true ); } }
aimport java.awt.* ;
import java.awt.event.*;
import javax.swing.*;
public class IdealWeight extends JFrame implements ActionListener {
JRadioButton genderM, genderF;
ButtonGroup genderGroup;
JPanel genderPanel;
JRadioButton heightA, heightB, heightC, heightD, heightE;
ButtonGroup heightGroup;
JPanel heightPanel;
JTextField resultText;
JLabel resultLabl;
JPanel resultPanel;
String height1 = "60 to 64 inches";
String height2 = "64 to 68 inches";
String height3 = "68 to 72 inches";
String height4 = "72 to 76 inches";
String height5 = "76 to 80 inches";
// String height6 = "height6";
String fem = "female";
String mal = "male";
public IdealWeight() {
setTitle( "Your Ideal Weight" );
setDefaultCloseOperation( EXIT_ON_CLOSE );
// gender group
genderM = new JRadioButton(mal, true );
genderM.setActionCommand(mal);
genderM.addActionListener(this);
genderF = new JRadioButton(fem, false );
genderF.setActionCommand(fem);
genderF.addActionListener(this);
genderGroup = new ButtonGroup();
genderGroup.add( genderM ); genderGroup.add( genderF );
genderPanel = new JPanel();
genderPanel.setLayout(
new BoxLayout( genderPanel, BoxLayout.Y_AXIS ) );
genderPanel.add( new JLabel("Your Gender") );
genderPanel.add( genderM ); genderPanel.add( genderF );
// height group
heightA = new JRadioButton(height1, true );
heightA .setActionCommand(height1 );
heightA .addActionListener(this);
heightB = new JRadioButton(height2 , false );
heightB .setActionCommand( height2 );
heightB .addActionListener(this);
heightC = new JRadioButton(height3, false );
heightC.setActionCommand(height3);
heightC.addActionListener(this);
heightD = new JRadioButton(height4, false );
heightD.setActionCommand(height4);
heightD.addActionListener(this);
heightE = new JRadioButton(height5 , false );
heightE .setActionCommand(height5 );
heightE .addActionListener(this);
heightGroup = new ButtonGroup();
heightGroup.add( heightA ); heightGroup.add( heightB );
heightGroup.add( heightC ); heightGroup.add( heightD );
heightGroup.add( heightE );
heightPanel = new JPanel();
heightPanel.setLayout(
new BoxLayout( heightPanel, BoxLayout.Y_AXIS ) );
heightPanel.add( new JLabel("Your Height") );
heightPanel.add( heightA ); heightPanel.add( heightB );
heightPanel.add( heightC ); heightPanel.add( heightD );
heightPanel.add( heightE );
// result panel
resultText = new JTextField(7);
resultText.setEditable( false );
resultLabl = new JLabel("Ideal Weight");
resultPanel = new JPanel();
resultPanel.add( resultLabl );
resultPanel.add( resultText );
// content pane
getContentPane().setLayout( new BorderLayout() );
getContentPane().add( genderPanel, BorderLayout.WEST );
getContentPane().add( heightPanel, BorderLayout.EAST );
getContentPane().add( resultPanel, BorderLayout.SOUTH ); }
public void actionPerformed(ActionEvent evt) {
String get = evt.getActionCommand();
if (get.equals ("female")) { //&& (get.equals("60 to 64 inches"))
if(heightA.isSelected("60 to 64 inches"))
//{
resultText.setText("Hello"); // this is just for testing
//}
}
if (get.equals ("male"))
resultText.setText("World");// this is just for testing
}
public static void main ( String[] args ) {
IdealWeight weightApp = new IdealWeight() ;
weightApp.setSize( 250, 225 );
weightApp.setVisible( true ); } }