Window settings, Windows 7 settings
/**
* This is a GUI case program;
*
*/
Package w160412.wang. main;
Import java. awt. Color;
Import java. awt. Container;
Import java. awt. Dimension;
Import java. awt. Toolkit;
Import java. io. ObjectInputStream. GetField;
Import javax. swing. ImageIcon;
Import javax. swing. JFrame;
Import javax. swing. JLabel;
/**
* @ Author
*
* March April 12, 2016
*
*/
Public class GUI {
Public static void main (String [] args ){
// Create a form:
JFrame jframe = new JFrame ("JAVA_GUI_DEMO ");
/**
* Set the form:
*/
// Set the name: jframe. setTitle (name );
// Set the size:
Jframe. setSize (500,400 );
// Set the location:
Jframe. setLocationRelativeTo (null );
// Set the window Image to ensure setIconImage (); an Image object is obtained;
ImageIcon img = new ImageIcon ("image/java.png ");
Jframe. setIconImage (img. getImage ());
// Jframe. setIconImage (Toolkit. getdefatooltoolkit (). createImage ("image/1.png "));
// Set the background color
// Jframe. setBackground (Color. green );
// Jframe. setBackground (new Color (204,255,204 ));
// Jframe. getContentPane (). setVisible (false); // sets the form to hide the contentPane of the form;
Jframe. getContentPane (). setBackground (new Color (204,255,204); // set the contentPane Color of the form;
// Set the background image (this is incorrect)
Container con = jframe. getContentPane ();
JLabel jlb = new JLabel (new ImageIcon (Toolkit. getdefatooltoolkit (). createImage ("image/chutian.jpg ")));
Jlb. setBounds (0, 0, jlb. getWidth (), jlb. getHeight ());
Jframe. add (jlb );
// Set the disable Function
Jframe. setdefaclocloseoperation (JFrame. EXIT_ON_CLOSE );
// Set whether the window size is changed
Jframe. setResizable (false); // The size cannot be changed;
// Set the window to be visible
Jframe. setVisible (true );
}
}
/*
* Obtain the screen size and window size, at the position of the defined vertex;
* Dimension dim = Toolkit. getDefaultToolkit (). getScreenSize (); // obtain the screen size;
Dimension dimjf = jframe. getSize ();
Int width = (dim. width-dimjf. width)/2;
Int height = (dim. height-dimjf. height)/2;
Jframe. setLocation (width, height );
Equivalent to: jframe. setLocationRelativeTo (null );
Note: The window size must be set before the window position; otherwise, the window cannot be centered.
I saw folders in other projects and moved the images to other projects.
JFrame structure: RootPane, LayeredPane, ContentPane, Classpath;
**/
I. JFrame structure:
JFrame has four layers of structure: Frame, Rootpanel, Compenetpanel, and Classpanel. I don't understand it either. I will be working on it later.