?? tfmath.java
字號:
package com.zhoutenghn;
import java.awt.*;
import java.awt.event.*;
public class TFmath {
public static void main(String[] args) {
new TFrame().launch();
}
}
class TFrame extends Frame {
TextField num1, num2, num3;
public void launch() {
num1 = new TextField(10);
num2 = new TextField(10);
num3 = new TextField(15);
Label add = new Label("+");
Button equel = new Button("=");
equel.addActionListener(new Moniter());
setLayout(new FlowLayout());
add(num1);
add(add);
add(num2);
add(equel);
add(num3);
pack();
setVisible(true);
}
private class Moniter implements ActionListener {// 內部類!!!
// 可以直接調用外面包裝類的成員變量,如果時私有的話,
// 別人不能訪問此內部類
public void actionPerformed(ActionEvent e) {
int n1 = Integer.parseInt(num1.getText());
int n2 = Integer.parseInt(num2.getText());
num3.setText("" + (n1 + n2));
// System.out.println("ok");
}
}
}
/*
* class Moniter implements ActionListener { TFrame tf = null;
*
* public Moniter(TFrame tf) {//此為持有對象的引用,把TFrame對象的引用調過來,以便使用其成員變量 this.tf =
* tf; }
*
* public void actionPerformed(ActionEvent e) { int n1 =
* Integer.parseInt(tf.num1.getText()); int n2 =
* Integer.parseInt(tf.num2.getText()); tf.num3.setText("" + (n1 + n2)); //
* System.out.println("ok"); }
* }
*/
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -