| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 518 人关注过本帖
标题:能看出这程序错哪了的进~
只看楼主 加入收藏
大嘴先生2
Rank: 1
等 级:新手上路
威 望:2
帖 子:815
专家分:0
注 册:2006-4-17
收藏
 问题点数:0 回复次数:6 
能看出这程序错哪了的进~
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);
}
}













搜索更多相关主题的帖子: import private 
2006-06-27 11:52
千里冰封
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:灌水之王
等 级:版主
威 望:155
帖 子:28477
专家分:59
注 册:2006-2-26
收藏
得分:0 
你这个程序到处都有错误
编译都通过不了
自己找找吧,

可惜不是你,陪我到最后
2006-06-27 11:55
大嘴先生2
Rank: 1
等 级:新手上路
威 望:2
帖 子:815
专家分:0
注 册:2006-4-17
收藏
得分:0 
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);
}
}

骑白马的未必是王子,也可能是唐僧;有翅膀的未必是天使,也可能是鸟人。
2006-06-27 12:19
千里冰封
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:灌水之王
等 级:版主
威 望:155
帖 子:28477
专家分:59
注 册:2006-2-26
收藏
得分:0 
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
class Computer extends JFrame implements ActionListener,ItemListener
{//你既然选择了实现ItemListener,但 是为什么不实现里面的方法itemStateChanged(ItemEvent ie);
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)//你这里就是少了一个d
{
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());//double值有这个方法吗?
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)//你的b是哪里定义的
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);
}
}

其实上面的错误,你编译的时候,编译器就会告诉你的
为什么不自己把它排除出来呢

可惜不是你,陪我到最后
2006-06-27 12:28
大嘴先生2
Rank: 1
等 级:新手上路
威 望:2
帖 子:815
专家分:0
注 册:2006-4-17
收藏
得分:0 
哦?
谢谢你啊,我再看看
operateX=Double.parseDouble(operateX.getText());//double值有这个方法吗?
//这里不能转换吗??
public void itemStateChange(ItemEvent e)//你这里就是少了一个d
//加了不就实现了方法了麻~
JRadioButton b=(JRadioButton)e.getItemSelectable();
if(
b.isSelected()==yuanzhuButton)//布尔量和按钮会相等吗?
//那这又该怎么用呢???
麻烦你了,再教教偶吧!~

骑白马的未必是王子,也可能是唐僧;有翅膀的未必是天使,也可能是鸟人。
2006-06-27 12:43
千里冰封
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:灌水之王
等 级:版主
威 望:155
帖 子:28477
专家分:59
注 册:2006-2-26
收藏
得分:0 
operateX=Double.parseDouble(operateX.getText());//
这样也能转换吗?
你前面和后面的是一样的,都是double啊
getText()是文本组件才有的方法啊
double怎么会有这个方法,并且double也不是对象

可惜不是你,陪我到最后
2006-06-27 13:29
大嘴先生2
Rank: 1
等 级:新手上路
威 望:2
帖 子:815
专家分:0
注 册:2006-4-17
收藏
得分:0 

谢谢拉


骑白马的未必是王子,也可能是唐僧;有翅膀的未必是天使,也可能是鸟人。
2006-06-28 09:46
快速回复:能看出这程序错哪了的进~
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.021052 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved