Containers (Container) frames and panels

Source: Internet
Author: User
Tags set background

    • Frames

1) is the sub-class of window

2) with title and zoom angle

3) Inherit from container and add component as add

4) can create an invisible frame object as a string-defined caption

5) BorderLayout can be used as default layout manager

6) Change the default layout manager in SetLayout mode

7) frame is a sub-class of window. It is a window with a caption and a zoom angle. It inherits from Java.awt.Container, so you can add components to the framework using the Add () method. The default layout manager for the framework is border layout. It can be changed in SetLayout () mode.

8) The constructor in the framework class frame (string) creates a new, invisible frame object with the caption specified by string. When it is still in an invisible state, add all components to the frame.

To view the construction method of a frame class in a JDK doc document

public Frame(String title)     throws HeadlessException

The title in this method is the caption that is displayed.

The program looks like this:

Package com.ahuier.awt;Import Java.awt.Color;Import Java.awt.Frame;public class myframe extends Frame{public myframe (String title) {super (title);} Span class= "Hljs-keyword" >public static void main (string[] args) {MyFrame frame = new myframe (500, 500); //set width and height frame.setbackground (color.blue); //Set background color frame.setvisible (true); //Settings Visible}}             
    • Panels

1) Provide space for components

2) Allow sub-panels to have their own layout manager

3) Add a component with the Add method

(1) Like frames, panels provides space to connect to any GUI component, including other panels. Each panel can have its own cloth management program.

(2) Once a panel object is created, it must be added to the window or frame object in order to be visible. This can be done using the Add () method in the container class.

Package com.ahuier.awt;Import Java.awt.Color;Import Java.awt.Frame;Import Java.awt.Panel;PublicClassFramewithpanelExtendsframe{Publicframewithpanel (String title) {super (title);} public static void  Main (string[] args) {Framewithpanel frame = new framewithpanel ( "Frame with panel"); panel panel = new panel (); Frame.setsize (200,200); Frame.setbackground (Color.Black); Frame.setlayout (null); //the layout manager, we set to empty, that is, not to use its own layout manager panel.setsize (100, 100); Panel.setbackground (Color.yellow); Frame.add (panel); //set Panel on frame frame.setvisible (true);}}    

Containers (Container) frames and panels

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.