import java.awt.*;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener; public class WindowListenerTest { private Frame f = new Frame();
private TextArea ta = new TextArea(,);
private Button bt = new Button("bt");
public void init(){
f.addWindowListener(new MyListener());
bt.addMouseListener(new MyMouseListener());
f.add(bt,BorderLayout.NORTH);
f.add(ta);
f.pack();
f.setVisible(true);
}
class MyListener implements WindowListener{
public void windowOpened(WindowEvent e){
ta.append("window first be opened" + "\n");
} public void windowClosed(WindowEvent e){
ta.append("window closed " + "\n");
System.exit();
} public void windowClosing(WindowEvent e){
ta.append("window close by x" + "\n");
System.exit();
} public void windowIconified(WindowEvent e){
ta.append("window iconified be trigger" + "\n");
}
public void windowDeiconified(WindowEvent e){
ta.append("window deiconified be trigger" + "\n");
} public void windowActivated(WindowEvent e){
ta.append("window activated be trigger" + "\n");
} public void windowDeactivated(WindowEvent e){
ta.append("window deactivated be trigger" + "\n");
} }; class MyMouseListener implements MouseListener{
public void mouseEntered(MouseEvent event){
System.out.println("mouseEntered");
} public void mouseExited(MouseEvent event){
System.out.println("mouseExited");
}
public void mouseClicked(MouseEvent event){
System.out.println("mouseClicked");
}
public void mousePressed(MouseEvent event){
System.out.println("mousePressed");
}
public void mouseReleased(MouseEvent event){
System.out.println("mouseReleased");
} } public static void main(String[] args) {
new WindowListenerTest().init();
}
}

output:

learning java AWT widowEvent and MouseEvent的更多相关文章

  1. learning java AWT 手绘窗口

    import java.awt.*;port java.awt.event.ActionListener; import java.awt.event.MouseAdapter; import jav ...

  2. learning java AWT 右键菜单

    import java.awt.*; import java.awt.event.*; public class SimpleMenu { private Frame f = new Frame(&q ...

  3. learning java AWT 剪贴板 传递文本

    import javax.swing.*; import java.awt.*; import java.awt.datatransfer.Clipboard; import java.awt.dat ...

  4. learning java AWT 画图

    import javax.swing.*; import java.awt.*; import java.util.Random; public class SimpleDraw { private ...

  5. learning java AWT MenuBar Menu MenuItem菜单

    import java.awt.*; import java.awt.event.ActionListener; import java.awt.event.KeyEvent; import java ...

  6. learning java AWT EventQs

    import javax.swing.*; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.Ac ...

  7. learning java AWT Dialog

    import java.awt.*; public class DialogTest { Frame f = new Frame("test"); Dialog d1 = new ...

  8. learning java AWT 常见组件

    import javax.swing.*; import java.awt.*; public class CommonComponent { Frame f = new Frame("te ...

  9. learning java AWT BoxLayout布局管理器

    import javax.swing.*; import java.awt.*; public class BoxSpaceTest { private Frame f = new Frame(&qu ...

随机推荐

  1. maven 打包错误 Cannot access central in offline mode

    出错的场景是这样的,先是在一台联网的linux机器上下载项目需要的包,linux机器上jdk为1.8 springboot1.5.然后将项目代码和.m2目录拷贝到一台windows机器上,window ...

  2. spring session cpu占用过高

      集成spring session很简单,只需几行代码即可. @Configuration @EnableRedisHttpSession public class SessionConfig { ...

  3. UOJ343 清华集训2017 避难所 构造、打表

    传送门 玄学题 考虑构造三个数\(p_1p_2,p_1p_2,p_1p_2\)满足贪心分解会分解为\(p_1^3,p_2,p_2,p_2\),那么需要满足条件 1.\(p_1 , p_2 \in Pr ...

  4. db跟随集群自启动

    AME=ora.newora920.db TYPE=ora.database.type ACL=owner:oracle:rwx,pgrp:oinstall:r--,other::r--,group: ...

  5. 贴一个markdown语法,mweb自带的说明

    Markdown 语法和 MWeb 写作使用说明 Markdown 的设计哲学 Markdown 的目標是實現「易讀易寫」.不過最需要強調的便是它的可讀性.一份使用 Markdown 格式撰寫的文件應 ...

  6. UCOSII消息队列

    主结构体 typedef struct os_q { /* QUEUE CONTROL BLOCK */ struct os_q *OSQPtr; /* Link to next queue cont ...

  7. Linux多IP配置

    # ifconfig eth0:1 172.168.1.222

  8. c# System.Collections接口图

  9. Flask之flask-sqlalchemy

    接下来基于这个Flask项目,我们要加入Flask-SQLAlchemy让项目变得生动起来 1.加入Flask-SQLAlchemy第三方组件 from flask import Flask # 导入 ...

  10. Python如何打印文字对应的索引

    用python编写一个简单的小程序:将文字对应的索引打印出来. test=input('>>>') print(test) l=len(test) print(l) r=range( ...