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)