java addlistener_java addActionListener(this)的问题,求支招!!!!

该楼层疑似违规已被系统折叠 隐藏此楼查看此楼

import java.awt.*;

import java.awt.event.*;

public class duihuakuang2

{

public static TextField tf1, tf2, tf3;

public static void main(String[] args){

TF tf = new TF();

tf.launch();

}

}

class TF

{

public TextField tf1, tf2, tf3;

public void launch(){

tf1 = new TextField(30);

tf2 = new TextField(30);

tf3 = new TextField(30);

Button bn = new Button("=");

Label Lb = new Label("+");

Frame f = new Frame("文本框相加示例");

f.setLayout(new FlowLayout());

f.add(tf1);

f.add(Lb);

f.add(tf2);

f.add(bn);

f.add(tf3);

bn.addActionListener(new MyMonitor(this));//this的用法是什么,实现什么功能呢?求支招

f.pack();

f.setVisible(true);

}

}

class MyMonitor implements ActionListener

{

private TF tf;

public MyMonitor(TF tf){

this.tf = tf;

}

@Override

public void actionPerformed(ActionEvent e){

String str1 = tf.tf1.getText();

String str2 = tf.tf2.getText();

int num1 = Integer.parseInt(str1);

int num2 = Integer.parseInt(str2);

int num3 = num1 + num2;

tf.tf3.setText(num3+"");

}

}

表情包
插入表情
评论将由博主筛选后显示,对所有人可见 | 还能输入1000个字符
相关推荐
<p> <b><span style="background-color:#FFE500;">【超实用课程内容】</span></b> </p> <p> <br /> </p> <p> <br /> </p> <p> 本课程内容包含讲解<span>解读Nginx基础知识</span><span>解读Nginx核心知识、带领学员进行</span>高并发环境下Nginx性能优化实战让学生能够快速将所学融合到企业应用中。 </p> <p> <br /> </p> <p style="font-family:Helvetica;color:#3A4151;font-size:14px;background-color:#FFFFFF;"> <b><br /> </b> </p> <p style="font-family:Helvetica;color:#3A4151;font-size:14px;background-color:#FFFFFF;"> <b><span style="background-color:#FFE500;">【课程如何观看?】</span></b> </p> <p style="font-family:Helvetica;color:#3A4151;font-size:14px;background-color:#FFFFFF;"> PC端:<a href="https://edu.csdn.net/course/detail/26277"><span id="__kindeditor_bookmark_start_21__"></span></a><a href="https://edu.csdn.net/course/detail/27216">https://edu.csdn.net/course/detail/27216</a> </p> <p style="font-family:Helvetica;color:#3A4151;font-size:14px;background-color:#FFFFFF;"> 移动端:CSDN 学院APP注意不是CSDN APP哦 </p> <p style="font-family:Helvetica;color:#3A4151;font-size:14px;background-color:#FFFFFF;"> 本课程为录播课课程永久有效观看时长大家可以抓紧时间学习后一起讨论哦~ </p> <p style="font-family:"color:#3A4151;font-size:14px;background-color:#FFFFFF;"> <br /> </p> <p class="ql-long-24357476" style="font-family:"color:#3A4151;font-size:14px;background-color:#FFFFFF;"> <strong><span style="background-color:#FFE500;">【学员专享增值服务】</span></strong> </p> <p class="ql-long-24357476" style="font-family:"color:#3A4151;font-size:14px;background-color:#FFFFFF;"> <b>源码开放</b> </p> <p class="ql-long-24357476" style="font-family:"color:#3A4151;font-size:14px;background-color:#FFFFFF;"> 课件、课程案例代码完全开放给你你可以根据所学知识自行修改、优化 </p> <p class="ql-long-24357476" style="font-family:"color:#3A4151;font-size:14px;background-color:#FFFFFF;"> 下载方式:电脑登录<a href="https://edu.csdn.net/course/detail/26277"></a><a href="https://edu.csdn.net/course/detail/27216">https://edu.csdn.net/course/detail/27216</a>播放页面右侧点击课件进行资料打包下载 </p> <p> <br /> </p> <p> <br /> </p> <p> <br /> </p>
©️2020 CSDN 皮肤主题: 数字20 设计师:CSDN官方博客 返回首页