适配器形式做事件
组件事件没写
import java.awt.*;
import java.awt.event.*;
//3、适配器形式做事件
class MyEvent extends WindowAdapter
{
public void windowClosing(WindowEvent e)
{
System.out.println("轻轻的我走了......来了");
System.exit(1);
}
public void windowOpened(WindowEvent e)
{
System.out.println("窗口已经打开");
}
}
class MyKeyEvent extends KeyAdapter
{
public void keyPressed(KeyEvent e)
{
System.out.println(e.getKeyChar());
System.out.println(e.getKeyCode());
}
}
class MyActionEvent extends ActionEvent
{
}
public class Demo06 extends Frame
{
Button btn1 = new Button("按钮");
Demo06()
{
setSize(500,500);
setLayout(new FlowLayout());
add(btn1);
this.addWindowListener(new MyEvent());
this.addKeyListener(new MyKeyEvent());
setVisible(true);
show();
}
public static void main(String s[])
{
new Demo06();
}
}
网友评论