GUI Graphics user interface GUI
- AWT Abstract Window Toolkit abstract Windows Development Package
- Component Manager
- Layout Manager
- Event handling
- Java graphics
- Window Event
AWT abstracts graphical elements such as toolbars, menus, drop-down bars, input boxes, etc.
Component: All graphical elements that can be displayed
window: A top-level window that can be parked freely, typically by its subclass new out of the panel: accommodates other elements but cannot be displayed independently
Frame
Various properties of frame, SetBounds (x,y,width,height) x y is the upper-left coordinate, setSize, setlocation,setbackground,setvisible (this method must be set to TRUE if you want to see it) , settitle,setresizable
Direct new out of various frame
Importjava.awt.*; Public classTest { Public Static voidMain (string[] args)throwsException {Frame F1=NewFrame ("F1"); Frame F2=NewFrame ("F2"); Frame f3=NewFrame ("F3"); F1.setsize (300,400); F1.settitle ("Frame"); F1.setresizable (false); //f1.setopacity (0.1f); I don't understand.F1.setbackground (Color.Blue); F2.setbounds (300,0,300,400); F2.setbackground (Color.lightgray); F3.setbounds (0,0,300,400); F3.setbackground (Color.gray); F3.setlocation (0,400); F1.setvisible (true);//Window MethodF2.setvisible (true); F3.setvisible (true); } }
Create a frame by inheriting the frame class
Importjava.awt.*;classFrame1extendsFrame { PublicFrame1 (intXintYintz) { Super("Frame class");//how to construct a parent classSetSize (300,400); SetBackground (NewColor (x, Y, z)); SetVisible (true); } } Public classTestframe { Public Static voidMain (string[] args) {Frame1 F1=NewFrame1 (204,204,255); }} /*1. A file contains two classes, a public declaration, a default declaration, and when Javac compiles testframe, it compiles the Frame1 used in the Testframe class.*/
Panel
Panel itself cannot be displayed independently of
Panel.setbounds () method inside the parameter is placed in who is relative to who, not in the upper left corner of the screen as the standard
A frame contains a panel of four colors
Importjava.awt.*; Public classTest { Public Static voidMain (string[] args) {Panel1 P1=NewPanel1 (); } }classPanel1extendsPanel { PublicPanel1 () {Frame F1=NewFrame ();//new frame for adding a panelPanel P1 =NewPanel ();//The panel's construction method, using the panel's default layout manager FlowLayoutPanel P2 =NewPanel (); Panel P3=NewPanel (); Panel P4=NewPanel (); F1.setbounds (500,500,400,400); P1.setbounds (0,0,200,200); P2.setbounds (200,0,200,200); P3.setbounds (0,200,200,200); P4.setbounds (200,200,200,200); P1.setbackground (Color.Black); P2.setbackground (Color.Blue); P3.setbackground (Color. CYAN); P4.setbackground (Color.dark_gray); F1.add (p1); F1.add (p2); F1.add (p3); F1.add (p4); F1.setvisible (true); } }
A panel in the middle of the frame, the background color is yellow
Importjava.awt.*; Public classTest { Public Static voidMain (string[] args) {Panel1 P1=NewPanel1 (200,400); } }classPanel1extendsPanel {//int i,j; PublicPanel1 (intIintj) {//this.i = i; //THIS.J = j; intx = 400,y = 500; Frame F1=NewFrame ();//contains the default layout managerPanel P1 =NewPanel (); F1.setbounds (0,0, x, y); F1.setlayout (NULL);//manually set up the layout manager instead of the default layout managerP1.setbounds (X/2-I/2,Y/2-J/2, i,j); P1.setbackground (Color.yellow); F1.add (p1); F1.setvisible (true); } }
Java Learning notes GUI programming