Java中加减乘除怎样写代码,【求助】怎样实现加减乘除 代码如下
該樓層疑似違規(guī)已被系統(tǒng)折疊?隱藏此樓查看此樓
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("請(qǐng)輸入數(shù)字字符");
}
}
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("請(qǐng)輸入數(shù)字字符");
}
}
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("請(qǐng)輸入數(shù)字字符");
}
}
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("請(qǐng)輸入數(shù)字字符");
}
}
}
}
總結(jié)
以上是生活随笔為你收集整理的Java中加减乘除怎样写代码,【求助】怎样实现加减乘除 代码如下的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: Redis入门到精通-Redis数据类型
- 下一篇: java美元兑换,(Java实现) 美元