编程语言
首页 > 编程语言> > 2021-10-20(java-gui-贪吃蛇)

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 

标签:10,20,300,gui,class,import,java,public,MyFrame
来源: https://blog.csdn.net/qq_45688193/article/details/120869566