2021-10-20(java-gui-贪吃蛇)

匿名内部类:

package six;

import java.awt.*;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

public class six {
    public static void main(String[] args) {
        new MyFrame();
    }

}
class MyFrame extends Frame{
    public MyFrame(){
        setBackground(Color.blue);
        setBounds(300,300,300,300);
        setVisible(true);

        this.addWindowListener(new WindowAdapter() {
            @Override
            public void windowClosing(WindowEvent e) {
                System.out.println("匿名内部类");
            }
        });
    }
}

内部类:

class MyFrame extends Frame{
    public MyFrame(){
        setBackground(Color.blue);
        setBounds(300,300,300,300);
        setVisible(true);
        
    }
    class MyWindowListener 
上一篇:GUI学生管理系统


下一篇:GUI程序设计--班级信息收集系统