AWT containers have a layout, and then add components and threads (for example, fireworks)

Source: Internet
Author: User

AWT containers have a layout, and then add components and threads (for example, fireworks)

The container is also a class, which is actually a subclass of component. Therefore, the container itself is also a component and has all the properties of the component, however, its main function is to accommodate other components and containers. Layoutmanager: each container has a layout manager. When the container needs to locate a component or determine its size, it calls its corresponding layout manager.
Component
Container
Panel windows (frame DIALOG)
The corresponding class of panel is Java. AWT. Panel, which can contain components of other container types or in browser windows. A Panel identifies a rectangular area that allows other components to be placed. A panel must be placed in a window or its subclass to be displayed.
The standard layout manager of AWT has the following five types:

1. flowlayout: This layout manager places components from left to right or from top to bottom. It is the default layout manager for panel and applet;

2. borderlayout: The layout manager divides components into the east, west, south, north, and middle areas. It is the default layout manager for Windows, dialog, and frame containers;

3. cardlayout: The layout manager adds the component to the container as a card and places each component on a separate card. The cards behind the layout will overwrite the previous card and only one card can be seen at a time;

4. gridlayout: The layout manager divides containers into grids of the same size and places components into grids in sequence;

5. gridbaglayout: The layout manager divides containers into grids of the same size, but the components not only occupy one grid, but one component can occupy multiple grid locations;
F = new frame ("Gui example ");
F. setlayout (New flowlayout (); // you can specify flowlayout as the layout manager.
B1 = new button ("press me"); // the character "press me" is displayed on the button"
B2 = new button ("Don't press me ");
F. Add (B1 );
F. Add (B2 );
F. Pack (); // used in flowlayout. Compact arrangement, which is equivalent to setsize (), that is, to make the window as small as possible, as small as the two buttons B1 and B2.
F. setvisible (true );

F. setlayout (New borderlayout ());
F. Add (New button ("North"), borderlayout. North );

F. setlayout (New gridlayout (); // The container is evenly divided into three rows, two columns, and six columns.
F. Add (...); // Add to the first grid...
F. Add (...); // Add to the second grid

F. addwindowlistener (New windowadapter (){
Public void windowclosing (windowevent e ){
System. Exit (0 );
}
});
North, south, center, west, east
The default layout manager of frame is borderlayout.
The default layout manager of the Panel is flowlayout.
If you use setlayout (null), you must use setlocation (), setsize (), setbounds (), and other methods to manually set the size and position of the component, not encouraged.

 

 

 

Graphics public class lines extends applet {
Public void paint (Graphics g ){
// G. drawline (50, 50,100,100 );
// G. drawline (50,100,100, 50 );
G. Fig (0, 0, 50,150 );
G. setcolor (color. Black );
// Draw an elliptical border.
}}
G. drawarc (50, 50,100,100, 0,270); upper left corner of the rectangle, long and wide. The rounded corner starts to draw an arc from the right.
Basic Method of Applet running status control
Init
Start
Stop

 

Thread one;
One = new thread (this );????? Same as addmouselistener (this); this
One. Start ();
One = NULL;
Where can I clear my previous paintings? Graphics G1;
G1 = getgraphics ();
G not required = NULL

  

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.