import java.awt.*;
import java.awt.event.*;public class TestMath {
public static void main(String[] args) {
new TFFrame().launchFrame();
}
}class TFFrame extends Frame {
TextField num1, num2, num3;
public void launchFrame() {
num1 = new TextField(10);
num2 = new TextField(10);
num3 = new TextField(15);
Label lblPlus = new Label("+");
Button btnEqual = new Button("=");
btnEqual.addActionListener(new MyMonitor(this));
setLayout(new FlowLayout());
add(num1);
add(lblPlus);
add(num2);
add(btnEqual);
add(num3);
pack();
setVisible(true);
}
}class MyMonitor implements ActionListener {
TFFrame tf = null;
public MyMonitor(TFFrame tf) {
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));
}
}
这两句什么意思,有什么用?
TFFrame tf = null;
public MyMonitor(TFFrame tf) {
this.tf = tf;
}
import java.awt.event.*;public class TestMath {
public static void main(String[] args) {
new TFFrame().launchFrame();
}
}class TFFrame extends Frame {
TextField num1, num2, num3;
public void launchFrame() {
num1 = new TextField(10);
num2 = new TextField(10);
num3 = new TextField(15);
Label lblPlus = new Label("+");
Button btnEqual = new Button("=");
btnEqual.addActionListener(new MyMonitor(this));
setLayout(new FlowLayout());
add(num1);
add(lblPlus);
add(num2);
add(btnEqual);
add(num3);
pack();
setVisible(true);
}
}class MyMonitor implements ActionListener {
TFFrame tf = null;
public MyMonitor(TFFrame tf) {
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));
}
}
这两句什么意思,有什么用?
TFFrame tf = null;
public MyMonitor(TFFrame tf) {
this.tf = tf;
}
解决方案 »
- 现在JSP好还是PHP好
- 求助:java3D配置问题
- '数组\for循环'问题
- 请教一个基础问题,关于堆和栈,以及内存回收的相关知识,请高手进来帮忙,谢谢!平时不关心内存的人也进来学习一下吧。
- 要连到MYSQL数据库,请问要那几个包
- 得到链接的内容
- 请问有没有将.class文件反编译成.java的软件???
- 按首字符拼音方式对数据库中某表中字段进行搜索?(up有分)
- URLConnection.getOutputStream()相关问题
- 各位高手大家好,现在开发动态网页的时候配置环境的时候,你们选择是jrun还是tomcat 4.0,还有一些问题?
- 下载了Java类库,怎么用啊(求高手速来!)
- prepareStatement使用问号就异常
public MyMonitor(TFFrame tf) {
this.tf = tf;//注意我的着色,红的对应红的,蓝的对应蓝的
}
this.tf = tf; //让成员指向实际的TFFrame对象
}
actionListener是一个监听器TFFrame tf = null; //定义一个TFFrame类型的对象,设为null//带参数的构造方法,给成员变量tf赋值引用
public MyMonitor(TFFrame tf) {
this.tf = tf;
this.tf = tf; //让成员指向实际的TFFrame对象
}
this 表示当前的对象,就是你这个类所在的对象