java_GUI2

package GUi;

import java.awt.*;

public class GuI2 {
public static void main(String[] args) {
MyFrame new1 = new MyFrame(100,100,300,100,Color.BLUE);
MyFrame new2 = new MyFrame(220,300,300,100,Color.green);
MyFrame new3 = new MyFrame(330,500,300,100,Color.yellow);
MyFrame new4 =new MyFrame(440,700,300,100,Color.red);
}
}
class MyFrame extends Frame {
// 计数器
static int id = 0;

public MyFrame(int x,int y,int w,int h,Color color){
super("窗口+"+(++id));

setVisible(true);

// 大小
setBounds(x,y,w,h);
// 设置背景
setBackground(color);
}
}
posted @ 2022-06-08 18:20  rainsc  阅读(20)  评论(0编辑  收藏  举报