一个JAVA的程序

来源:百度知道 编辑:UC知道 时间:2024/05/19 04:15:44
这是我写的程序的一个例子

import java.applet.*;
import java.awt.*;
import java.awt.event.*;

public class JSQ5 extends Applet implements ActionListener
{
TextField text1;

Button b1,b2,b3,b4;
double n,n1,n2,t;
int s,s1;
StringBuffer c = new StringBuffer() ;

public void init()
{

text1 = new TextField(16);

b1 = new Button("1");
b2 = new Button("2");
b3 = new Button("+");
b4 = new Button("=");

add(text1);

add(b1);
add(b2);
add(b3);
add(b4);

b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
b4.addActionListener(this);

}

我调试了下,可以实现。。。。

import java.applet.*;
import java.awt.*;
import java.awt.event.*;

public class JSQ5 extends Applet implements ActionListener
{
TextField text1;

Button b1,b2,b3,b4,b5;//****
double n,n1,n2,t;
int s,s1;
StringBuffer c = new StringBuffer() ;

public void init()
{

text1 = new TextField(16);

b1 = new Button("1");
b2 = new Button("2");
b3 = new Button("+");
b4 = new Button("=");
b5=new Button("清空");//***

add(text1);

add(b1);
add(b2);
add(b3);
add(b4);
add(b5);//****

b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
b4.addActionListener(this);
b5.addActionListener(this);//******

}

public void actionPerformed(ActionEvent e)
{
if(e.getSource()==b1)
{
n2=Doubl