第一个java图形窗口
package com.zeng.GUI;
import javax.swing.*;
import java.awt.*;
public class GGui {
public static void main(String args[]) {
Frame frame = new Frame("我的第一个java图形界面窗口");
frame.setSize(400, 400);
frame.setLocation(1200, 200);
frame.setBackground(new Color(15, 222, 120));
frame.setResizable(true);
frame.setVisible(true);
}
}
对界面类进行封装复用
package com.zeng.GUI;
import java.awt.*;
public class TestFrame2 {
public static void main(String[] args) {
Myframe myframe1 = new Myframe(100, 100, 400, 400, Color.red);
Myframe myframe2 = new Myframe(500, 100, 400, 400, Color.yellow);
Myframe myframe3 = new Myframe(100, 500, 400, 400, Color.blue);
Myframe myframe4 = new Myframe(500, 500, 400, 400, Color.green);
}
}
class Myframe extends Frame {
static int id = 0;
public Myframe(int x, int y, int w, int h, Color color) {
super("Myframe" + (++id));
setBounds(x, y, w, h);
setBackground(color);
setResizable(true);
setVisible(true);
}
}