各位大神求帮助,尽快,谢谢
为什么第九行,按键设置背景色会错误,正确应该怎么样,谢谢各位大神
import java.awt.* ;
import java.awt.event.*;
import javax.swing.*;
import java.awt.Color;
public class IdealWeight extends JFrame implements ActionListener
{
JRadioButton genderM, genderF;
genderM.setBackground(Color.white);
ButtonGroup genderGroup;
JPanel genderPanel;
JRadioButton heightA, heightB, heightC, heightD, heightE;
ButtonGroup heightGroup;
JPanel heightPanel;
JTextField resultText;
JLabel resultLabl;
JPanel resultPanel;
int sex=28,h=62;
double out;
String str;
public IdealWeight()
{
setTitle( "Your Ideal Weight" );
setDefaultCloseOperation( EXIT_ON_CLOSE );
// gender group
genderM = new JRadioButton("Male", true );
genderF = new JRadioButton("Female", false );
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("60 to 64 inches", true );
heightB = new JRadioButton("64 to 68 inches", false );
heightC = new JRadioButton("68 to 72 inches", false );
heightD = new JRadioButton("72 to 76 inches", false );
heightE = new JRadioButton("76 to 80 inches", false );
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 );
//set action command
genderM.setActionCommand("male");
genderF.setActionCommand("female");
heightA.setActionCommand("first");
heightB.setActionCommand("second");
heightC.setActionCommand("third");
heightD.setActionCommand("forth");
heightE.setActionCommand("fifth");
//add action listener
genderM.addActionListener(this);
genderF.addActionListener(this);
heightA.addActionListener(this);
heightB.addActionListener(this);
heightC.addActionListener(this);
heightD.addActionListener(this);
heightE.addActionListener(this);
resultText.setText("137.3");
}
public void actionPerformed(ActionEvent evt){
if(evt.getActionCommand().equals("male"))
sex=28;
else if(evt.getActionCommand().equals("female"))
sex=30;
else if(evt.getActionCommand().equals("first"))
h=62;
else if(evt.getActionCommand().equals("second"))
h=66;
else if(evt.getActionCommand().equals("third"))
h=70;
else if(evt.getActionCommand().equals("forth"))
h=74;
else h=78;
out=(h*h)/sex;
str=String.valueOf(out);
resultText.setText(str);
}
public static void main ( String[] args )
{
IdealWeight weightApp = new IdealWeight() ;
weightApp.setSize( 250, 225 );
weightApp.setVisible( true );
}
}