Window settings, Windows 7 settings

Source: Internet
Author: User

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.

 

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.