对enableEvents类的应用
来源:互联网 发布:insert sql 批量 编辑:程序博客网 时间:2024/06/02 15:10
实现代码如下:
MyButton.java文件代码:
import java.awt.*;import java.awt.event.*;public class MyButton extends Button { private MyButton friend = null; public MyButton(String title) { // TODO Auto-generated constructor stub super(title); enableEvents(AWTEvent.MOUSE_MOTION_EVENT_MASK); } public void setFriend(MyButton friend) { this.friend = friend; } protected void processMouseMotionEvent(MouseEvent e) { setVisible(false); friend.setVisible(true); }}
TestMyButton.java文件里的代码:
import java.awt.*;import java.awt.event.*;public class TestMyButton extends Frame { public TestMyButton() { addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { dispose(); System.exit(0); } }); } public static void main(String[] args) { // TODO Auto-generated method stub System.out.println("Starting TestMyButton..."); TestMyButton mainFrame = new TestMyButton(); MyButton btn1 = new MyButton("你来抓我呀!"); MyButton btn2 = new MyButton("你来抓我呀!"); btn1.setFriend(btn2); btn2.setFriend(btn1); mainFrame.add(btn1, "North"); mainFrame.add(btn2, "South"); mainFrame.setSize(400, 400); mainFrame.setTitle("TestButton"); mainFrame.setVisible(true); btn2.setVisible(false); }}
控制台运行结果:
窗口的运行结果:
0 0
- 对enableEvents类的应用
- Application.EnableEvents =false(true)的理解
- 对Properties类的应用
- 对RandomAccessFile类的应用
- 对Timer类的应用
- 对Dialog类的应用
- 对CheckBox类的应用
- Java.enableEvents.processXxxEvent(XxxEvent e)
- 对FileWriter/FileReader类的应用
- 对PipedOutputStream/PipedInputStream类的应用
- 对ByteArrayInputStream/ByteArrayOutputStream类的应用
- 对包装类DataInputStream/DataOutputStream的应用
- 3G对应用的影响
- Javascript对表单的应用
- dubbo对zookeeper的应用
- 对指针应用的总结
- 对FileOutputStream/FileInputStream的应用
- 对现代病理的应用
- 将文本内容添加到手机剪切板
- 跳转方式
- iOS应用崩溃日志分析 iOS应用崩溃日志揭秘
- Android更改状态栏
- js操作cookie
- 对enableEvents类的应用
- 递归5_简单的0/1背包问题
- 理解Java垃圾回收机制
- 为以后的我先留个比较小白的问题,这两段代码到底哪个好,如何评价。
- c++应用程序文件的编译过程
- Open vSwitch流表查找分析
- Convert videos, audio and image sequences quickly and efficiently.
- 工具类:给 ImageView 类增加下载图片的功能(模仿 SDWebImage/runtime 用法1:动态添加属性)
- pl/sql存储过程返回record类型和集合类型的结果,Java里如何调用呢