博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Java SE (3) 之 事件监听
阅读量:7088 次
发布时间:2019-06-28

本文共 1694 字,大约阅读时间需要 5 分钟。

1 package com.sun; 2 import java.awt.*; 3 import javax.swing.*; 4 import java.awt.event.*; 5 public class Demo_1_1 extends JFrame implements ActionListener{ 6  7     Mypanel mp; 8     public static void main(String[] args) { 9         // TODO Auto-generated method stub10         Demo_1_1  demo1 = new Demo_1_1();11         12     }13     public Demo_1_1() {14          mp = new Mypanel();15         JButton jb1 = new JButton("Button");16         JButton jb2 = new JButton("Button2");17         jb1.addActionListener(this);18         jb1.setActionCommand("kaishi");19         jb2.addActionListener(this);20         jb2.setActionCommand("jieshu");21         this.add(mp);22         this.add(jb1,BorderLayout.EAST);23         this.add(jb2,BorderLayout.NORTH);24         // TODO Auto-generated constructor stub25         this.setTitle("demo");26         this.setSize(300,300);27         this.setLocation(40, 40);28         this.setDefaultCloseOperation(EXIT_ON_CLOSE);29         this.setVisible(true);30     }31     public void actionPerformed(ActionEvent e) {32         // TODO Auto-generated method stub33         if(e.getActionCommand().equals("kaishi")){34               System.out.println("this is yes ");35               mp.setBackground(Color.BLUE);36             37         }else if(e.getActionCommand().equals("jieshu")) {38              System.out.println("this is no ");39              mp.setBackground(Color.BLACK);40         }41     }42 }43 class Mypanel extends JPanel{44     45     public void paint(Graphics g){        46         super.paint(g);47             g.fillRect(0, 0, 300, 300);48             g.setColor(Color.YELLOW);49             g.fillRect(40, 40, 50, 50);50     }51 }

 

转载地址:http://slyql.baihongyu.com/

你可能感兴趣的文章
JQuery Ajax实例总结
查看>>
CentOS中文件夹基本操作命令
查看>>
VS2008 Project : error PRJ0019: 某个工具从以下位置返回了错误代码: "正在执行生成后事件..."解决方案...
查看>>
js判断图片是否存在,并做处理
查看>>
触摸屏
查看>>
webservice 测试窗体只能用于来自本地计算机的请求
查看>>
Java 中队列的使用
查看>>
再见 2014,你好 2015
查看>>
13 SELECT 以外的内容
查看>>
初中面谈招生网上招生报名系统
查看>>
.NET平台开源项目速览(9)软件序列号生成组件SoftwareProtector介绍与使用
查看>>
干货:史上最实用逃顶绝招十二式!
查看>>
鸟哥Linux私房菜 基础学习篇读书笔记(10):Linux磁盘和文件系统管理(3)
查看>>
简述Session 、Cookie、cache 区别
查看>>
large-scale analysis of malware downloaders
查看>>
pyqt声音输入
查看>>
FMX 模态窗体
查看>>
使用storyboard实现页面跳转,简单的数据传递
查看>>
有些事明显对自己有益,为什么却无法去做?
查看>>
IOS开发基础知识--碎片30
查看>>