Topic: 请高手们帮我看看!(这个GUI为什么不能运行)

  Print this page

1.请高手们帮我看看!(这个GUI为什么不能运行) Copy to clipboard
Posted by: 别野
Posted on: 2006-05-18 10:41


import java.awt.*;
import java.awt.event.*;
public class calculator implements ActionListener
{
Frame f;
Panel p1,p2;
TextField op1,op2,result;
Button calc,clearb;
public void show()
{
f=new Frame("一个简单的计算器");
f.setSize(240,180);
f.setLocation(300,200);
f.setBackground(Color.lightGray);
f.setLayout(new FlowLayout());
result = new TextField(20);
result.setEditable(false);
op1=new TextField("0",4);
op2=new TextField("0",4);
p1=new Panel();
p1.add(op1);
p1.add(new Label("+"));
p1.add(op2);
f.add(result);
f.add(p1);
calc = new Button("=");
clearb=new Button("Clear");
p2=new Panel();
p2.add(calc);
p2.add(clearb);
f.add(p2);
calc.addActionListener(this);
clearb.addActionListener(this);
f.addWindowListener(new WinClose());
f.setVisible(true);
}
public void actionperformed(ActionEvent e)
{
if(e.getSource()==clearb)
{
result.setText(" ");
op1.setText("0");
op2.setText("0");
}else
if(e.getSource()==calc)
{
int sum,x,y;
String s1=op1.getText().trim();
String s2=op2.getText().trim();
String temps;
x=Integer.parseInt(s1);
y=Integer.parseInt(s2);
sum=x+y;
result.setText(String.valueOf(x)+"+"+String.valueOf(y)+"="+String.valueOf(sum));
}
}
public static void main(String arg[])
{
(new calculator()).show();
}
}
class WinClose implements WindowListener
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
public void windowOpened(WindowEvent e){};
public void windowIconified(WindowEvent e){};
public void windowDeiconifide(WindowEvent e){};
public void windowClosed(WindowEvent e){};
public void windowActivated(WindowEvent e){};
public void windowDeactivated(WindowEvent e){};
};

这个GUI为什么不能运行! ̄!

2.Re:请高手们帮我看看!(这个GUI为什么不能运行) [Re: 别野] Copy to clipboard
Posted by: Skybus
Posted on: 2006-05-18 22:09

import java.awt.Button;
import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.Frame;
import java.awt.Label;
import java.awt.Panel;
import java.awt.TextField;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;

public class Calculator implements ActionListener {//这个地方应该使用大写,这是基本的常识.
Frame f;

Panel p1, p2;

TextField op1, op2, result;

Button calc, clearb;

public void show() {
f = new Frame("一个简单的计算器");
f.setSize(240, 180);
f.setLocation(300, 200);
f.setBackground(Color.lightGray);
f.setLayout(new FlowLayout());
result = new TextField(20);
result.setEditable(false);
op1 = new TextField("0", 4);
op2 = new TextField("0", 4);
p1 = new Panel();
p1.add(op1);
p1.add(new Label("+"));
p1.add(op2);
f.add(result);
f.add(p1);
calc = new Button("=");
clearb = new Button("Clear");
p2 = new Panel();
p2.add(calc);
p2.add(clearb);
f.add(p2);
calc.addActionListener(this);
clearb.addActionListener(this);
f.addWindowListener(new WinClose());
f.setVisible(true);
}

public void actionPerformed(ActionEvent e) {//这个地方应该是大写
if (e.getSource() == clearb) {
result.setText(" ");
op1.setText("0");
op2.setText("0");
} else if (e.getSource() == calc) {
int sum, x, y;
String s1 = op1.getText().trim();
String s2 = op2.getText().trim();
String temps;
x = Integer.parseInt(s1);
y = Integer.parseInt(s2);
sum = x + y;
result.setText(String.valueOf(x) + "+" + String.valueOf(y) + "="
+ String.valueOf(sum));
}
}

public static void main(String arg[]) {
(new Calculator()).show();
}
}

class WinClose implements WindowListener {
public void windowClosing(WindowEvent e) {
System.exit(0);
}

public void windowOpened(WindowEvent e) {
};

public void windowIconified(WindowEvent e) {
};

public void windowDeiconified(WindowEvent e) {//这个地方写颠倒了.
};

public void windowClosed(WindowEvent e) {
};

public void windowActivated(WindowEvent e) {
};

public void windowDeactivated(WindowEvent e) {
};
};


总的来说,java的基本功还是要扎实!

3.Re:请高手们帮我看看!(这个GUI为什么不能运行) [Re: 别野] Copy to clipboard
Posted by: 别野
Posted on: 2006-05-19 10:06

谢谢哦,太谢谢了
我是新手,我扎实起来的! ̄!Kiss

4.Re:请高手们帮我看看!(这个GUI为什么不能运行) [Re: 别野] Copy to clipboard
Posted by: xuyan268
Posted on: 2006-05-21 22:11

那个类名不大写是不是不行哦!!
windows系统下怎么可以!

5.Re:请高手们帮我看看!(这个GUI为什么不能运行) [Re: 别野] Copy to clipboard
Posted by: lisliefor
Posted on: 2006-05-24 21:54

建议使用好一点的工具 !

6.Re:请高手们帮我看看!(这个GUI为什么不能运行) [Re: 别野] Copy to clipboard
Posted by: 别野
Posted on: 2006-05-31 10:16

lisliefor
用什么工具好呢
能不能见意一个!~!

7.Re:请高手们帮我看看!(这个GUI为什么不能运行) [Re: 别野] Copy to clipboard
Posted by: lisliefor
Posted on: 2006-05-31 12:21

Eclipse
JBuilder
JCreate
先去搜索一下,找不到,联系我QQ:258280899

8.Re:请高手们帮我看看!(这个GUI为什么不能运行) [Re: 别野] Copy to clipboard
Posted by: 别野
Posted on: 2006-06-12 18:00

好久没有来了
谢谢
我以经找到了
呵呵


   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923