Java — 事件监听、事件处理 初体验
发布日期:2021-06-30 19:49:27
浏览次数:2
分类:技术文章
本文共 818 字,大约阅读时间需要 2 分钟。
package test1;import java.awt.*;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import javax.swing.*;public class test2 extends JFrame implements ActionListener{ //定义我需要的组件 JButton jb; JLabel jl; JTextField jtf; public static void main(String[] args) { test2 t2 = new test2(); } //构造器 public test2(){ //创建组件 jtf = new JTextField(10); jl = new JLabel(); jb = new JButton("OK"); //设置布局管理 this.setLayout(new GridLayout(3, 1)); //将组件加入到JFrame this.add(jtf,BorderLayout.NORTH); this.add(jl,BorderLayout.CENTER); this.add(jb,BorderLayout.SOUTH); //注册监听 jb.addActionListener(this); //设置大小和初始位置 this.setSize(200, 300); this.setLocation(200, 200); this.setVisible(true); } //事件处理的方法 public void actionPerformed(ActionEvent e) { String s = jtf.getText(); jl.setText(s); }}
转载地址:https://lipenglin.blog.csdn.net/article/details/49801881 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!
发表评论
最新留言
路过按个爪印,很不错,赞一个!
[***.219.124.196]2024年04月06日 11时50分18秒
关于作者
喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
轨迹规划 trajectory planning
2019-04-30
AGV自动导引运输车
2019-04-30
Trie树(字典树)
2019-04-30
COMP7404 Machine Learing——KNN
2019-04-30
COMP7404 Machine Learing——SVM
2019-04-30
COMP7404 Machine Learing——ROC
2019-04-30
Python量子计算qiskit
2019-04-30
Python的多线程不是真的多线程(GIL全局解释器锁)
2019-04-30
Python手动读取MNIST数据集
2019-04-30
Python手动读取CIFAR-10数据集
2019-04-30
Pytorch(十一) —— 分布式(多GPU)训练
2019-04-30
Deeplab v3
2019-04-30
NLP 之 Perplexity困惑度
2019-04-30