📄 ji.java
字号:
import java.awt.*;
import java.awt.event.*;
public class Ji{
static Frame vedio=new Frame("TextVedio");
static Frame btn=new Frame("Button");
static Button i1=new Button("1");
static Button i2=new Button("2");
static Button i3=new Button("3");
static Button i4=new Button("4");
static Button i5=new Button("5");
static Button i6=new Button("6");
static Button i7=new Button("7");
static Button i8=new Button("8");
static Button i9=new Button("9");
static Button i0=new Button("0");
static Button plus=new Button("+");
static Button minus=new Button("-");
static Button chen=new Button("X");
static Button chu=new Button("/");
static Button equal=new Button("=");
static Button ac=new Button("AC");
static TextField tf=new TextField("0");
static String tmp;
static int to;
public static void main(String args[]){
btn.add(i1);
btn.add(i2);
btn.add(i3);
btn.add(plus);
btn.add(i4);
btn.add(i5);
btn.add(i6);
btn.add(minus);
btn.add(i7);
btn.add(i8);
btn.add(i9);
btn.add(chen);
btn.add(ac);
btn.add(i0);
btn.add(equal);
btn.add(chu);
btn.setSize(400,400);
btn.setLayout(new GridLayout(4,4));
btn.show();
vedio.add(tf);
vedio.setSize(500,70);
vedio.show();
btn.addWindowListener(new java.awt.event.WindowListener(){
public void windowClosing(WindowEvent e){System.exit(0);}
public void windowClosed(WindowEvent e){ }
public void windowOpened(WindowEvent e){ }
public void windowIconified(WindowEvent e){ }
public void windowDeiconified(WindowEvent e){ }
public void windowActivated(WindowEvent e){ }
public void windowDeactivated(WindowEvent e){ }
});
vedio.addWindowListener(new java.awt.event.WindowListener(){
public void windowClosing(WindowEvent e){System.exit(0);}
public void windowClosed(WindowEvent e){ }
public void windowOpened(WindowEvent e){ }
public void windowIconified(WindowEvent e){ }
public void windowDeiconified(WindowEvent e){ }
public void windowActivated(WindowEvent e){ }
public void windowDeactivated(WindowEvent e){ }
});
i1.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
addString("1");
}
});
i2.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
addString("2");
}
});
i3.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
addString("3");
}
});
i4.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
addString("4");
}
});
i5.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
addString("5");
}
});
i6.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
addString("6");
}
});
i7.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
addString("7");
}
});
i8.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
addString("8");
}
});
i9.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
addString("9");
}
});
i0.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
addString("0");
}
});
plus.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
addo("+");
}
});
minus.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
addo("-");
}
});
chen.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
addo("X");
}
});
chu.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
addo("/");
}
});
equal.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
doequals();
}
});
ac.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
tf.setText("0");
}
});
}
public static void addString(String s){
String temp=tf.getText();
if(temp.equals("0")){
tf.setText(s);
}else{
tf.setText(tf.getText()+s);
}
}
public static void addo(String o){
tmp=tf.getText();
if(o.equals("+")){
to=1;
}else if(o.equals("-")){
to=2;
}else if(o.equals("X")){
to=3;
}else if(o.equals("/")){
to=4;
}
tf.setText("");
}
public static void doequals(){
try{
String temp=tf.getText();
double d1=Double.parseDouble(tmp);
double d2=Double.parseDouble(temp);
double sum=0;
if(to==1){
sum=d1+d2;
}else if(to==2){
sum=d1-d2;
}else if(to==3){
sum=d1*d2;
}else if(to==4){
sum=d1/d2;
}
tf.setText(Double.toString(sum));
}catch(Exception e){
tf.setText("It is not a Number!");
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -