先定义接口MyFrame 继承 Frame
在TestFrame02中实现
package com.liner.lesson01;
import java.awt.*;
public class TestFrame02 {
public static void main(String[] args) {
//展示多个窗口
new MyFrame(100,100,200,200,Color.blue);
new MyFrame(300,100,200,200,Color.yellow);
new MyFrame(100,300,200,200,Color.red);
new MyFrame(300,300,200,200,Color.magenta);
}
}
class MyFrame extends Frame {
static int id = 0;//可能存在多个窗口,我们需要一个接收器
public MyFrame(int x,int y,int w,int h,Color color){
super("MyFrame"+(++id));
setBackground(color);
setBounds(x, y, w, h);
setVisible(true);
}
}