The relationship between JFrame and JPanel-differences (study notes)

Source: Internet
Author: User

when learning the graphical user interface, make sure JFrame and JPanel are very critical.

Here are two examples to differentiate

use of JFrame:

java.awt.*javax.swing.*frame1 {(string[] args) {JFrame F = JFrame (); F.setsize (); F.setvisible () ; }}


use of JPanel:

java.awt.*javax.swing.*frame2 {(string[] args) {JFrame F = JFrame (); F.setsize (); JLabel x = JLa Bel (); F.getcontentpane (). Add (x); f.setvisible ();}}

can also be used to do top-level form To place the control in the interface, the control must be placed in the jpanel jpanel put it in jframe Span style= "font-family: ' Times New Roman ';" >jpanel used as a container.

is a static control component that can be used to display a row of static information , cannot jframe .

jpanel is placed on its face, The same interface has only one jframe a jframe can put multiple Span style= "font-family: ' Times New Roman ';" >jpanel jframe , just plain page

J Panel You can put it in JFrame , not the other way.

The general usage in the actual application is:

JAVA.AWT.*JAVAX.SWING.*FRAME4A {(string[] args) {JFrame F = JFrame (); JLabel L = JLabel (); Jpane L P = JPanel (); P.add (L); F.getcontentpane (). Add (P); F.setsize () f.setvisible ();}}


This article is from the "Monkey Moving Brick" blog, please be sure to keep this source http://silianbo.blog.51cto.com/6627757/1632391

The relationship between JFrame and JPanel-differences (study notes)

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.