📄 selflistener.java
字号:
package org.course.gui;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
public class SelfListener extends Frame implements WindowListener{
Button bClose;
public SelfListener() {
super("Listener is itself");
bClose = new Button("close");
this.add(bClose, BorderLayout.SOUTH);
this.addWindowListener(this);
bClose.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
close();
}
});
this.setSize(400, 300);
this.setVisible(true);
}
void close() {
this.dispose();
}
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
new SelfListener();
}
public void windowOpened(WindowEvent e) {
// TODO Auto-generated method stub
}
public void windowClosing(WindowEvent e) {
// TODO Auto-generated method stub
this.dispose();
}
public void windowClosed(WindowEvent e) {
// TODO Auto-generated method stub
}
public void windowIconified(WindowEvent e) {
// TODO Auto-generated method stub
}
public void windowDeiconified(WindowEvent e) {
// TODO Auto-generated method stub
}
public void windowActivated(WindowEvent e) {
// TODO Auto-generated method stub
}
public void windowDeactivated(WindowEvent e) {
// TODO Auto-generated method stub
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -