能看出这程序错哪了的进~
import javax.swing.*;import java.awt.*;
import java.awt.event.*;
class Computer extends JFrame implements ActionListener //ItemListener
{
private JLabel xLabel;
private JLabel yLabel;
private JLabel hLabel;
private JLabel rLabel;
private JTextField xText;
private JTextField yText;
private JTextField hText;
private JTextField rText;
private JRadioButton yuanButton;
private JRadioButton yuanzhuButton;
private JLabel resultLabel;
private JTextField resultText;
private JButton jisuanButton;
private JButton clearButton;
private JButton quxiaoButton;
private JPanel zuobiaoPanel;
private JPanel hrPanel;
private JPanel resultPanel;
private JPanel radioButtonPanel;
private JPanel buttonPanel;
private JPanel resultPanel2;
private ButtonGroup group;
private JTextField resultText2;
Computer(String s)
{
super(s);
xLabel=new JLabel("x");
yLabel=new JLabel("y");
rLabel=new JLabel("r");
hLabel=new JLabel("h");
xText=new JTextField();
yText=new JTextField();
rText=new JTextField();
hText=new JTextField();
yuanButton=new JRadioButton("圆");
yuanzhuButton=new JRadioButton("圆柱");
resultLabel=new JLabel();
resultText=new JTextField();
jisuanButton=new JButton("计算");
clearButton=new JButton("清除");
quxiaoButton=new JButton("取消");
zuobiaoPanel=new JPanel();
hrPanel=new JPanel();
resultPanel=new JPanel();
radioButtonPanel=new JPanel();
buttonPanel=new JPanel();
resultPanel2=new JPanel();
Container con=getContentPane();
con.setLayout(new GridLayout(6,1));
con.add(zuobiaoPanel);
con.add(hrPanel);
con.add(resultPanel);
con.add(resultPanel2);
con.add(radioButtonPanel);
con.add(buttonPanel);
zuobiaoPanel.setLayout(new GridLayout(1,4));
hrPanel.setLayout(new GridLayout(1,4));
resultPanel.setLayout(new GridLayout(1,2));
resultPanel2.setLayout(new GridLayout(1,2));
zuobiaoPanel.add(xLabel);
zuobiaoPanel.add(xText);
zuobiaoPanel.add(yLabel);
zuobiaoPanel.add(yText);
hrPanel.add(hLabel);
hrPanel.add(hText);
hrPanel.add(rLabel);
hrPanel.add(rText);
resultPanel.add(resultLabel);
resultPanel.add(resultText);
buttonPanel.add(jisuanButton);
buttonPanel.add(clearButton);
buttonPanel.add(quxiaoButton);
resultText.setEditable(false);
xText.setEditable(false);
yText.setEditable(false);
hText.setEditable(false);
rText.setEditable(false);
jisuanButton.addActionListener(this);
clearButton.addActionListener(this);
quxiaoButton.addActionListener(this);
group=new ButtonGroup();
group.add(yuanButton);
group.add(yuanzhuButton);
yuanButton.addItemListener(this);
yuanzhuButton.addItemListener(this);
pack();
setVisible(true);
}
public void itemStateChange(ItemEvent e)
{
JRadioButton b=(JRadioButton)e.getItemSelectable();
if(b.isSelected()==yuanzhuButton)
{
xText.setEditable(true);
yText.setEditable(true);
hText.setEditable(true);
rText.setEditable(true);
resultLabel.setText("圆柱的表表面积是");
JLabel resultLabel2=new JLabel("圆柱的体积是");
resultText2=new JTextField();
resultPanel2.add(resultLabel2);
resultText2.setEditable(false);
resultPanel2.add(resultText2);
}
if(b.isSelected()==yuanButton)
{
xText.setEditable(true);
yText.setEditable(true);
rText.setEditable(true);
resultLabel.setText("圆的面积是");
hText.setText("0");
}
}
public void actionPerformed(ActionEvent ee)
{
double operateX,operateY,operateH,operateR;
try
{
operateX=Double.parseDouble(operateX.getText());
operateY=Double.parseDouble(operateY.getText());
operateH=Double.parseDouble(operateH.getText());
operateR=Double.parseDouble(operateR.getText());
}
catch(NumberFormatException numberFormat)
{
JOptionPane.showMessageDialog(this,"输入格式不正确","错误",JOptionPane.ERROR_MESSAGE);
return;
}
if(ee.getSource()==jisuanButton)
{
if(b.isSelected()==yuanButton)
resultText.setText(String.valueOf(Math.PI*operateR*operateR));
if(b.isSelected()==yuanzhuButton)
{
resultText.setText(String.valueOf(2*Math.PI*operateR*operateH));
resultText2.setText(String.valueOf(Math.PI*operateR*operateR*operateH));
}
}
if(ee.getSource()==clearButton)
{
xText.setText("");
yText.setText("");
hText.setText("");
rText.setText("");
resultText.setText("");
resultText2.setText("");
}
if(ee.getSource()==quxiaoButton)
{
System.exit(0);
}
}
}
public class Bh
{
public static void main(String args[])
{
Computer com=new Computer("计算");
com.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}