GUI之展示多个frame窗口

展示多个窗口

package day14;

 

import java.awt.*;

 

public class AwtDemo2 {

    public static void main(String[] args) {

        Myframe myframe1 = new Myframe(200, 300, 200, 200, Color.yellow);

        Myframe myframe2 = new Myframe(400, 300, 200, 200, Color.gray);

        Myframe myframe3 = new Myframe(600, 300, 200, 200, Color.red);

 

    }

}

 

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

    }

}

执行结果:

欢迎批评指正,提出问题,谢谢!
原文地址:https://www.cnblogs.com/xxeleanor/p/15110551.html