1. Java AWT
Container (container): window (FRAME), Panel
Component (Component): button ,,,
Others: layout, color ,,,
2, container (container)
1) Frame
public class FrameTest {public static void main(String[] args) {Frame f1 = new Frame();Frame f2 = new Frame();f1.setSize(100, 200);f2.setSize(200,100);f1.setVisible(true);f2.setVisible(false);}}
2) Panel
Import Java. AWT. *; import Java. applet. *; public class appletpaneltest extends applet // note the panel Implementation Method {public void Init () {panel P = new Panel (); p. setbackground (color. red); p. setsize (100,100); setbackground (color. green); setsize (200,200); add (p );}}
3. layout Configuration
1) borderlayout (east, west, north, and South)
Frame F = new frame ("borderlayout test ");
Button b1 = new button ("one ");
F. Add (B1, borderlayout. East );
2) flowlayout)
3) cardlayout
4) gridlayout
Frame F = new frame ("gridlayout test ");
F. setlayout (New gridlayout (2, 3); // two rows and three columns
5) gridbaglayout design your own Layout
Import Java. AWT. *; public class gridbaglayoutstep1 {public static void main (string argv []) {frame F = new frame ("gridbaglayout Step 1"); F. setlayout (New gridbaglayout (); button B [] = new button [4]; int ATT [] [] = {0, 0, 1, 1}, {1, 0, 1, 1}, {2, 0, 1, 1}, {0, 1, 3, 1}; For (INT I = 0; I <B. length; I ++) {B [I] = new button ("button" + (I + 1); add (F, B [I], ATT [I]);} f. pack (); F. setvisible (true);} Private Static void add (container con, component COM, int ATT []) // Add the com {gridbagconstraints cons = new gridbagconstraints () component according to the limitation array ATT in the container con; // obtain a restriction object cons. gridx = ATT [0]; cons. gridy = ATT [1]; cons. gridwidth = ATT [2]; cons. gridheight = ATT [3]; con. add (COM, cons); // Add the component COM in the container according to the limitation cons }}