Java....请问这个有错吗??
importjava.awt.*;importjava.awt.event.*;classJiSuanQiimplementsActionListener{Framef=...
import java.awt.*;
import java.awt.event.*;
class JiSuanQi implements ActionListener{
Frame f=new Frame("计算器");
Panel p=new Panel();
Panel p1=new Panel();
Panel p2=new Panel();
Button b=new Button("x+y");
Button b1=new Button("x-y");
Button b2=new Button("清除");
Lable Lbx=new lable("x");
Lable lby=new Lable("y");
TextField tfx=new TextField(4);
TextField tfy=new TextField(4);
TextArea ta=new TextArea();
Font ft=new Font("宋体",Font.BOLD,18);
GridLayout g1=new GridLayout(4,1);
GridLayout g2=new GridLayout(4,1);
double x,y,sum;
public static void main(String[] args){
JiSuanQi ji=new JiSuanQi();
ji.go();
}
public void go(){
b.setFont(ft);
b1.setFont(ft);
b2.setFont(ft);
lbx.setAlignment(Label.CENTER);
lby.setAlignment(Label.CENTER);
lbx.setFont(ft);
lby.setFont(ft);
tfx.setFont(ft);
tfy.setFont(ft);
ta.setFont(ft);
p.setLayout(g1);
p.add(lbx);
p.add(tfx);
p.add(lby);
p.add(tfy);
f.add(p,"West");
p1.set.Layout(g2);
p1.add(b);
p1.add(b1);
b.addActionListener(this);
b1.addActionListener(this);
f.add(p1,"East");
p2.add(b2);
b2.addActionListener(this);
f.add(p2,"South");
f.add(ta,"Center");
f.setSize(250,150);
f.setVisible(ture);
}
public void actionPerformed(ActionEvent ae){
String s=ae.get.getActionCommand();
x=Double.parseDouble(tfx.getText());
y=Double.parseDouble(tfy.getText());
if(s.equals("x+y")==true){
ta.append("x+y"+(x+y)+"\n");
}
if(s.equals("x-y")==true){
ta.append("x-y"+(x-y)+"\n");
}
if(s.equals("清除")==true){
ta.setText("");
}
}
} 展开
import java.awt.event.*;
class JiSuanQi implements ActionListener{
Frame f=new Frame("计算器");
Panel p=new Panel();
Panel p1=new Panel();
Panel p2=new Panel();
Button b=new Button("x+y");
Button b1=new Button("x-y");
Button b2=new Button("清除");
Lable Lbx=new lable("x");
Lable lby=new Lable("y");
TextField tfx=new TextField(4);
TextField tfy=new TextField(4);
TextArea ta=new TextArea();
Font ft=new Font("宋体",Font.BOLD,18);
GridLayout g1=new GridLayout(4,1);
GridLayout g2=new GridLayout(4,1);
double x,y,sum;
public static void main(String[] args){
JiSuanQi ji=new JiSuanQi();
ji.go();
}
public void go(){
b.setFont(ft);
b1.setFont(ft);
b2.setFont(ft);
lbx.setAlignment(Label.CENTER);
lby.setAlignment(Label.CENTER);
lbx.setFont(ft);
lby.setFont(ft);
tfx.setFont(ft);
tfy.setFont(ft);
ta.setFont(ft);
p.setLayout(g1);
p.add(lbx);
p.add(tfx);
p.add(lby);
p.add(tfy);
f.add(p,"West");
p1.set.Layout(g2);
p1.add(b);
p1.add(b1);
b.addActionListener(this);
b1.addActionListener(this);
f.add(p1,"East");
p2.add(b2);
b2.addActionListener(this);
f.add(p2,"South");
f.add(ta,"Center");
f.setSize(250,150);
f.setVisible(ture);
}
public void actionPerformed(ActionEvent ae){
String s=ae.get.getActionCommand();
x=Double.parseDouble(tfx.getText());
y=Double.parseDouble(tfy.getText());
if(s.equals("x+y")==true){
ta.append("x+y"+(x+y)+"\n");
}
if(s.equals("x-y")==true){
ta.append("x-y"+(x-y)+"\n");
}
if(s.equals("清除")==true){
ta.setText("");
}
}
} 展开
4个回答
展开全部
错误的地方,都在代码后面有注释,这个我已经运行过了,可以正常运行的。
import java.awt.*;
import java.awt.event.*;
class JiSuanQi implements ActionListener{
Frame f=new Frame("计算器");
Panel p=new Panel();
Panel p1=new Panel();
Panel p2=new Panel();
Button b=new Button("x+y");
Button b1=new Button("x-y");
Button b2=new Button("清除");
Label Lbx=new Label("x"); //Label
Label lby=new Label("y");
TextField tfx=new TextField(4);
TextField tfy=new TextField(4);
TextArea ta=new TextArea();
Font ft=new Font("宋体",Font.BOLD,18);
GridLayout g1=new GridLayout(4,1);
GridLayout g2=new GridLayout(4,1);
double x,y,sum;
public static void main(String[] args){
JiSuanQi ji=new JiSuanQi();
ji.go();
}
public void go(){
b.setFont(ft);
b1.setFont(ft);
b2.setFont(ft);
Lbx.setAlignment(Label.CENTER); //Lbx
lby.setAlignment(Label.CENTER);
Lbx.setFont(ft);
lby.setFont(ft);
tfx.setFont(ft);
tfy.setFont(ft);
ta.setFont(ft);
p.setLayout(g1);
p.add(Lbx);
p.add(tfx);
p.add(lby);
p.add(tfy);
f.add(p,"West");
p1.setLayout(g2); //去掉.
p1.add(b);
p1.add(b1);
b.addActionListener(this);
b1.addActionListener(this);
f.add(p1,"East");
p2.add(b2);
b2.addActionListener(this);
f.add(p2,"South");
f.add(ta,"Center");
f.setSize(250,150);
f.setVisible(true); //ture错,应该是true
}
public void actionPerformed(ActionEvent ae){
String s=ae.getActionCommand(); //方法写错了
x=Double.parseDouble(tfx.getText());
y=Double.parseDouble(tfy.getText());
if(s.equals("x+y")==true){
ta.append("x+y"+(x+y)+"\n");
}
if(s.equals("x-y")==true){
ta.append("x-y"+(x-y)+"\n");
}
if(s.equals("清除")==true){
ta.setText("");
}
}
}
import java.awt.*;
import java.awt.event.*;
class JiSuanQi implements ActionListener{
Frame f=new Frame("计算器");
Panel p=new Panel();
Panel p1=new Panel();
Panel p2=new Panel();
Button b=new Button("x+y");
Button b1=new Button("x-y");
Button b2=new Button("清除");
Label Lbx=new Label("x"); //Label
Label lby=new Label("y");
TextField tfx=new TextField(4);
TextField tfy=new TextField(4);
TextArea ta=new TextArea();
Font ft=new Font("宋体",Font.BOLD,18);
GridLayout g1=new GridLayout(4,1);
GridLayout g2=new GridLayout(4,1);
double x,y,sum;
public static void main(String[] args){
JiSuanQi ji=new JiSuanQi();
ji.go();
}
public void go(){
b.setFont(ft);
b1.setFont(ft);
b2.setFont(ft);
Lbx.setAlignment(Label.CENTER); //Lbx
lby.setAlignment(Label.CENTER);
Lbx.setFont(ft);
lby.setFont(ft);
tfx.setFont(ft);
tfy.setFont(ft);
ta.setFont(ft);
p.setLayout(g1);
p.add(Lbx);
p.add(tfx);
p.add(lby);
p.add(tfy);
f.add(p,"West");
p1.setLayout(g2); //去掉.
p1.add(b);
p1.add(b1);
b.addActionListener(this);
b1.addActionListener(this);
f.add(p1,"East");
p2.add(b2);
b2.addActionListener(this);
f.add(p2,"South");
f.add(ta,"Center");
f.setSize(250,150);
f.setVisible(true); //ture错,应该是true
}
public void actionPerformed(ActionEvent ae){
String s=ae.getActionCommand(); //方法写错了
x=Double.parseDouble(tfx.getText());
y=Double.parseDouble(tfy.getText());
if(s.equals("x+y")==true){
ta.append("x+y"+(x+y)+"\n");
}
if(s.equals("x-y")==true){
ta.append("x-y"+(x-y)+"\n");
}
if(s.equals("清除")==true){
ta.setText("");
}
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Lable 改为 Label
p1.set.Layout(g2); 改为 p1.setLayout(g2);
lbx.setAlignment(Label.CENTER); 改为 Lbx.setAlignment(Label.CENTER);
String s = ae.get.getActionCommand(); 改为 String s = ae.getActionCommand();
f.setVisible(ture); f.setVisible(true);
没有错误的代码
import java.awt.*;
import java.awt.event.*;
class JiSuanQi implements ActionListener {
Frame f = new Frame("计算器");
Panel p = new Panel();
Panel p1 = new Panel();
Panel p2 = new Panel();
Button b = new Button("x+y");
Button b1 = new Button("x-y");
Button b2 = new Button("清除");
Label Lbx = new Label("x");
Label lby = new Label("y");
TextField tfx = new TextField(4);
TextField tfy = new TextField(4);
TextArea ta = new TextArea();
Font ft = new Font("宋体", Font.BOLD, 18);
GridLayout g1 = new GridLayout(4, 1);
GridLayout g2 = new GridLayout(4, 1);
double x, y, sum;
public static void main(String[] args) {
JiSuanQi ji = new JiSuanQi();
ji.go();
}
public void go() {
b.setFont(ft);
b1.setFont(ft);
b2.setFont(ft);
Lbx.setAlignment(Label.CENTER); //Lbx
lby.setAlignment(Label.CENTER);
Lbx.setFont(ft);
lby.setFont(ft);
tfx.setFont(ft);
tfy.setFont(ft);
ta.setFont(ft);
p.setLayout(g1);
p.add(Lbx);
p.add(tfx);
p.add(lby);
p.add(tfy);
f.add(p, "West");
p1.setLayout(g2);
p1.add(b);
p1.add(b1);
b.addActionListener(this);
b1.addActionListener(this);
f.add(p1, "East");
p2.add(b2);
b2.addActionListener(this);
f.add(p2, "South");
f.add(ta, "Center");
f.setSize(250, 150);
f.setVisible(true);
}
public void actionPerformed(ActionEvent ae) {
String s = ae.getActionCommand();
x = Double.parseDouble(tfx.getText());
y = Double.parseDouble(tfy.getText());
if (s.equals("x+y") == true) {
ta.append("x+y" + (x + y) + "\n");
}
if (s.equals("x-y") == true) {
ta.append("x-y" + (x - y) + "\n");
}
if (s.equals("清除") == true) {
ta.setText("");
}
}
}
p1.set.Layout(g2); 改为 p1.setLayout(g2);
lbx.setAlignment(Label.CENTER); 改为 Lbx.setAlignment(Label.CENTER);
String s = ae.get.getActionCommand(); 改为 String s = ae.getActionCommand();
f.setVisible(ture); f.setVisible(true);
没有错误的代码
import java.awt.*;
import java.awt.event.*;
class JiSuanQi implements ActionListener {
Frame f = new Frame("计算器");
Panel p = new Panel();
Panel p1 = new Panel();
Panel p2 = new Panel();
Button b = new Button("x+y");
Button b1 = new Button("x-y");
Button b2 = new Button("清除");
Label Lbx = new Label("x");
Label lby = new Label("y");
TextField tfx = new TextField(4);
TextField tfy = new TextField(4);
TextArea ta = new TextArea();
Font ft = new Font("宋体", Font.BOLD, 18);
GridLayout g1 = new GridLayout(4, 1);
GridLayout g2 = new GridLayout(4, 1);
double x, y, sum;
public static void main(String[] args) {
JiSuanQi ji = new JiSuanQi();
ji.go();
}
public void go() {
b.setFont(ft);
b1.setFont(ft);
b2.setFont(ft);
Lbx.setAlignment(Label.CENTER); //Lbx
lby.setAlignment(Label.CENTER);
Lbx.setFont(ft);
lby.setFont(ft);
tfx.setFont(ft);
tfy.setFont(ft);
ta.setFont(ft);
p.setLayout(g1);
p.add(Lbx);
p.add(tfx);
p.add(lby);
p.add(tfy);
f.add(p, "West");
p1.setLayout(g2);
p1.add(b);
p1.add(b1);
b.addActionListener(this);
b1.addActionListener(this);
f.add(p1, "East");
p2.add(b2);
b2.addActionListener(this);
f.add(p2, "South");
f.add(ta, "Center");
f.setSize(250, 150);
f.setVisible(true);
}
public void actionPerformed(ActionEvent ae) {
String s = ae.getActionCommand();
x = Double.parseDouble(tfx.getText());
y = Double.parseDouble(tfy.getText());
if (s.equals("x+y") == true) {
ta.append("x+y" + (x + y) + "\n");
}
if (s.equals("x-y") == true) {
ta.append("x-y" + (x - y) + "\n");
}
if (s.equals("清除") == true) {
ta.setText("");
}
}
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
有错,而且不只一个地方啊....
运行不了,也看不出来你要编的是什么意思.
我学的可能跟你学的不一样.
不过.写类的方法里面是不是少个extends啊?
public class JiSuanQi extends JFrame implements ActionListener
还有动作监听里面怎么没有接受事件源?
if (ae.getSource()==b)
是我们学的不一样的问题吗?
运行不了,也看不出来你要编的是什么意思.
我学的可能跟你学的不一样.
不过.写类的方法里面是不是少个extends啊?
public class JiSuanQi extends JFrame implements ActionListener
还有动作监听里面怎么没有接受事件源?
if (ae.getSource()==b)
是我们学的不一样的问题吗?
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
请看注释:
import java.awt.*;
import java.awt.event.*;
class JiSuanQi implements ActionListener{
Frame f=new Frame("计算器");
Panel p=new Panel();
Panel p1=new Panel();
Panel p2=new Panel();
Button b=new Button("x+y");
Button b1=new Button("x-y");
Button b2=new Button("清除");
Lable Lbx=new lable("x");
//注意是Label,不是Lable,并注意大写
Lable lby=new Lable("y");
//注意是Label,不是Lable,并注意大写
TextField tfx=new TextField(4);
TextField tfy=new TextField(4);
TextArea ta=new TextArea();
Font ft=new Font("宋体",Font.BOLD,18);
GridLayout g1=new GridLayout(4,1);
GridLayout g2=new GridLayout(4,1);
double x,y,sum;
public static void main(String[] args){
JiSuanQi ji=new JiSuanQi();
ji.go();
}
public void go(){
b.setFont(ft);
b1.setFont(ft);
b2.setFont(ft);
lbx.setAlignment(Label.CENTER);
lby.setAlignment(Label.CENTER);
lbx.setFont(ft); //你上面写的是Lbx
lby.setFont(ft);
tfx.setFont(ft);
tfy.setFont(ft);
ta.setFont(ft);
p.setLayout(g1);
p.add(lbx);
p.add(tfx);
p.add(lby);
p.add(tfy);
f.add(p,"West");
p1.set.Layout(g2); //这里应该是p1.setLayout(g2);
p1.add(b);
p1.add(b1);
b.addActionListener(this);
b1.addActionListener(this);
f.add(p1,"East");
p2.add(b2);
b2.addActionListener(this);
f.add(p2,"South");
f.add(ta,"Center");
f.setSize(250,150);
f.setVisible(ture); //注意是ture还是ture
}
public void actionPerformed(ActionEvent ae){
String s=ae.get.getActionCommand();
//这是里String s=ae.getActionCommand;
x=Double.parseDouble(tfx.getText());
y=Double.parseDouble(tfy.getText());
if(s.equals("x+y")==true){
ta.append("x+y"+(x+y)+"\n");
}
if(s.equals("x-y")==true){
ta.append("x-y"+(x-y)+"\n");
}
if(s.equals("清除")==true){
ta.setText("");
}
}
}
import java.awt.*;
import java.awt.event.*;
class JiSuanQi implements ActionListener{
Frame f=new Frame("计算器");
Panel p=new Panel();
Panel p1=new Panel();
Panel p2=new Panel();
Button b=new Button("x+y");
Button b1=new Button("x-y");
Button b2=new Button("清除");
Lable Lbx=new lable("x");
//注意是Label,不是Lable,并注意大写
Lable lby=new Lable("y");
//注意是Label,不是Lable,并注意大写
TextField tfx=new TextField(4);
TextField tfy=new TextField(4);
TextArea ta=new TextArea();
Font ft=new Font("宋体",Font.BOLD,18);
GridLayout g1=new GridLayout(4,1);
GridLayout g2=new GridLayout(4,1);
double x,y,sum;
public static void main(String[] args){
JiSuanQi ji=new JiSuanQi();
ji.go();
}
public void go(){
b.setFont(ft);
b1.setFont(ft);
b2.setFont(ft);
lbx.setAlignment(Label.CENTER);
lby.setAlignment(Label.CENTER);
lbx.setFont(ft); //你上面写的是Lbx
lby.setFont(ft);
tfx.setFont(ft);
tfy.setFont(ft);
ta.setFont(ft);
p.setLayout(g1);
p.add(lbx);
p.add(tfx);
p.add(lby);
p.add(tfy);
f.add(p,"West");
p1.set.Layout(g2); //这里应该是p1.setLayout(g2);
p1.add(b);
p1.add(b1);
b.addActionListener(this);
b1.addActionListener(this);
f.add(p1,"East");
p2.add(b2);
b2.addActionListener(this);
f.add(p2,"South");
f.add(ta,"Center");
f.setSize(250,150);
f.setVisible(ture); //注意是ture还是ture
}
public void actionPerformed(ActionEvent ae){
String s=ae.get.getActionCommand();
//这是里String s=ae.getActionCommand;
x=Double.parseDouble(tfx.getText());
y=Double.parseDouble(tfy.getText());
if(s.equals("x+y")==true){
ta.append("x+y"+(x+y)+"\n");
}
if(s.equals("x-y")==true){
ta.append("x-y"+(x-y)+"\n");
}
if(s.equals("清除")==true){
ta.setText("");
}
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询