Java this
这句:b1.addActionListener(new MyeventAdd(this));//这里为什么传this,this代表上面,为什么传mtf就错
Java code:
package javagui;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class TestMath {
public static void main(String[] args) {
new MyFrameMath().MYMath();
}
}
class MyFrameMath extends Frame{
TextField tf1,tf2,tf3;
public void MYMath(){
tf1 = new TextField(10);
tf2 = new TextField(10);
tf3 = new TextField(15);
Label l = new Label("+");
Button b1 = new Button("=");
setLayout(new FlowLayout());
add(tf1);
add(l);
add(tf2);
add(b1);
add(tf3);
setResizable(false);
pack();
MyFrameMath mtf = new MyFrameMath();
b1.addActionListener(new MyeventAdd(this));//这里为什么传this,this代表上面,为什么传mtf就错呢?
setVisible(true);
}
}
class MyeventAdd implements ActionListener{
MyFrameMath mtf =null;
public MyeventAdd(MyFrameMath mtf){
this.mtf = mtf;
}
public void actionPerformed(ActionEvent e) {
int n1 = Integer.parseInt(mtf.tf1.getText());
int n2 = Integer.parseInt(mtf.tf2.getText());
mtf.tf3.setText(String.valueOf(n1+n2));
}
}
{
相关问答:
我已经按照教程上配置tomcat的server.xml
<Context path = "/POS" docBase = "POS" debug = "5" reloadable = "true" crossContext = "true" workDir = &quo ......
<?xml version="1.0" encoding="utf-8" ?>
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical&q ......
rt,我试了网上直连Acces数据库的方法,windows下没有问题,但是在linux下不行,谁能给点提示?谢谢
你怎么连的?
Acces数据库..
你怎么练的呢?
Java code:
static String DBDRIVER = "sun.jd ......
题目:
有1,2,3,4,5,6六个数字排序,用java程序计算出排序的种类。
要求:一,以4开头
二,2,3不能相邻
三,不能以5开头
希望大家能即 ......
要求:
1、具有2年以上的java开发工作经验,精通java;
2、熟悉Eclipse开发工具,熟悉WEB开发,具有两年以上Java开发经验,掌握面向对象的软件设计方法,
有Spring、Hibernate以及 ......