美文网首页
适配器事件(继承)

适配器事件(继承)

作者: 招风小妖怪 | 来源:发表于2019-07-12 08:41 被阅读0次

    适配器形式做事件

    组件事件没写

    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();
        }
    }
    

    相关文章

      网友评论

          本文标题:适配器事件(继承)

          本文链接:https://www.haomeiwen.com/subject/nruckctx.html