该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
import java.applet.*;import java.awt.*;import java.awt.event.*;
public class E7 extends Applet implements ActionListener
{
TextField t1,t2,t3;
Button b1,b2,b3,b4;
public void init()
{
t1=new TextField(10);
t2=new TextField(10);
t3=new TextField(10);
b1=new Button("加");
b2=new Button("差");
b3=new Button("积");
b4=new Button("除");
b1.setLocation(15, 20);
b2.setLocation(15, 25);
b3.setLocation(15, 30);
b4.setLocation(15, 35);
add(t1);add(t2);add(t3);add(b1);add(b2);add(b3);add(b4);
b1.addActionListener(this);b2.addActionListener(this);
b3.addActionListener(this);b4.addActionListener(this);
}
public void actionPerformed(ActionEvent e)
{if(e.getSource()==b1)
{double n1=0,n2=0;
try
{
n1=Double.valueOf(t1.getText()).doubleValue();
n2=Double.valueOf(t2.getText()).doubleValue();
t3.setText("");
}
catch(NumberFormatException event)
{
t3.setText("请输入数字字符");
}
}
if(e.getSource()==b2)
{double n1=0,n2=0;
try
{
n1=Double.valueOf(t1.getText()).doubleValue();
n2=Double.valueOf(t2.getText()).doubleValue();
t3.setText("");
}
catch(NumberFormatException event)
{
t3.setText("请输入数字字符");
}
}
if(e.getSource()==b3)
{double n1=0,n2=0;
try
{
n1=Double.valueOf(t1.getText()).doubleValue();
n2=Double.valueOf(t2.getText()).doubleValue();
t3.setText("");
}
catch(NumberFormatException event)
{
t3.setText("请输入数字字符");
}
}
if(e.getSource()==b4)
{double n1=0,n2=0;
try
{
n1=Double.valueOf(t1.getText()).doubleValue();
n2=Double.valueOf(t2.getText()).doubleValue();
t3.setText("");
}
catch(NumberFormatException event)
{
t3.setText("请输入数字字符");
}
}
}
}