GUI
1. Set a frame
package com.LILRICH.lesson1;
import java.awt.*;
public class Frame01 {
public static void main(String[] args) {
Frame frame = new Frame("First GUI");
frame.setSize(400,400);
frame.setLocation(200,200);
frame.setBackground(new Color(80,150,70));
frame.setResizable(false);
frame.setVisible(true);
}
}
2.You can also encapsulate the frame package like this way
package com.LILRICH.lesson1;
import java.awt.*;
public class Frame02 {
public static void main(String[] args) {
MyFrame myFrame1 = new MyFrame(100,100,200,200,Color.yellow);
MyFrame myFrame2 = new MyFrame(200,100,200,200,Color.gray);
}
}
class MyFrame extends Frame{
static int id = 0;
public MyFrame(int x, int y, int w, int d, Color color){
super("+ window"+(++id));
setBackground(color);
setBounds(x,y,w,d);
setVisible(true);
}
}
Comments
Post a Comment