?? frm.java
字號:
import java.awt.*;
import java.awt.event.*;
public class frm extends Frame implements ActionListener{
Label lab1,lab2,lab3,lab4;
TextField txt1;
Button btn1,btn2,btn3;
frm()
{
pack();
this.setTitle("四則運算");
this.setBounds(200,200, 380, 200);
//this.setResizable(false);
this.setVisible(true);
this.setLayout(null);
lab1=new Label(); //標簽,提示用戶輸入表達式
lab1.setBounds(15, 50, 80, 25);
lab1.setText("請輸入表達式:");
//lab1.setBackground(Color.blue);
lab2=new Label(); //標簽,提示運算結果
lab2.setBounds(15, 115, 80, 25);
lab2.setText("運算結果為:");
//lab2.setBackground(Color.pink);
lab3=new Label(); //標簽,顯示運算結果
lab3.setBounds(110, 115, 80, 25);
lab3.setBackground(Color.pink);
lab4=new Label("(請輸入正確的表達式并以#號結束,不包含括號)"); //標簽,注釋
lab4.setBounds(15, 80, 275, 25);
lab4.setBackground(Color.pink);
txt1=new TextField(); //輸入運算表達式
txt1.setBounds(110, 50, 180, 25);
btn1=new Button("確定"); //確定
btn1.setBounds(80,155, 60, 25);
btn2=new Button("清空"); //清空
btn2.setBounds(180, 155, 60, 25);
btn3=new Button("退出"); //退出
btn3.setBounds(280, 155, 60, 25);
add(lab1);
add(lab2);
add(lab3);
add(lab4);
add(btn1);
add(btn2);
add(btn3);
add(txt1);
btn1.addActionListener(this);
btn2.addActionListener(this);
btn3.addActionListener(this);
addWindowListener(new WindowAdapter(){
public void windowClosing (WindowEvent e){
dispose(); //釋放由此 Window、其子組件及其擁有的所有子組件所使用的所有本機屏幕資源
}});
}
public void actionPerformed(ActionEvent e) {
if(e.getActionCommand()=="退出") //退出
{
System.exit(0);
}
else if(e.getActionCommand()=="確定") //計算表達式
{
calculate cal=new calculate(txt1.getText());
int a=cal.AddSub();
lab3.setText(a+"");
}
else if(e.getActionCommand()=="清空") //清空表達式
{
txt1.setText(null);
lab3.setText(null);
}
}
public static void main(String[] args) {
frm f1=new frm();
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -