GUI-frame

 

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");
       //set window size
       frame.setSize(400,400);

       //location of window
       frame.setLocation(200,200);

       //background color
       frame.setBackground(new Color(80,150,70));

       //make window un-resizeable
       frame.setResizable(false);

       //make window visible
       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