📄 caculatordemo.java
字号:
/**How to control the layout of the applet??
*A simple caculator program
*2004.11.27. xhcprince
*/
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
public class caculatorDemo extends Applet implements ActionListener
{
Label L1,L2,L3;
TextField t1,t2,t3;
Button add_,sub_,mul_,div_;
public void init()
{
L1 = new Label("First number");
add(L1);
L2 = new Label("Second number");
add(L2);
t1 = new TextField(10);
add(t1);
t2 = new TextField(10);
add(t2);
add_ = new Button("+");
add(add_);
add_.addActionListener(this);
sub_ = new Button("-");
add(sub_);
sub_.addActionListener(this);
mul_ = new Button("*");
add(mul_);
mul_.addActionListener(this);
div_ = new Button("/");
add(div_);
div_.addActionListener(this);
t3 = new TextField(10);
add(t3);
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource() == add_)
{
double sum = Integer.parseInt(t1.getText()) + Integer.parseInt(t2.getText());
t3.setText(String.valueOf(sum));
}
if(e.getSource() == sub_)
{
double sub = Integer.parseInt(t1.getText()) - Integer.parseInt(t2.getText());
t3.setText(String.valueOf(sub));
}
if(e.getSource() == mul_)
{
double mul = Integer.parseInt(t1.getText()) * Integer.parseInt(t2.getText());
t3.setText(String.valueOf(mul));
}
if(e.getSource() == div_)
{
double div = Integer.parseInt(t1.getText()) / Integer.parseInt(t2.getText());
t3.setText(String.valueOf(div));
}
}
}
/*
<applet code = "caculatorDemo.class" width = 300 height = 160>
</applet>
*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -