My Java Learning notes (21) about frame positioning

Source: Internet
Author: User

The inheritance hierarchy of the framework and component classes in 1.AWT and swing.




2. Many of the methods of component classes are to get or set up a method pair form.

Public String getTitle ();p ublic void Settitle (stirng title);


3. For a property of type Boolean, the Get method starts with the IS.

public boolean islocationbyplatform ();p ublic void Setlocationbyplatform (Boolean B);


4. If the size of the specified frame is not explicitly indicated, the default value for all frames is 0*0 pixels.

There is a way to get the screen size in the 5.Toolkit class.

Toolkit kit = Toolkit.getdefaulttoolkit ();D imension screensize = kit.getscreensize (); int screenheight = Screensize.height;int screenwidth = screensize.width;


6. The way to set the frame icon is seticonimage ();

Image img = new ImageIcon ("Icon.gif"). GetImage (); Seticonimage (IMG);


7. If the framework contains only standard components, you can set the frame size by calling the pack method.

8. If you are writing an application that uses multiple displays, you can use the Graphicsenvironment and GraphicsDevice classes to get the display size.

Instance Code

Test class

Import Java.awt.eventqueue;import Javax.swing.jframe;public class Test {public static void main (string[] args) { Eventqueue.invokelater (New Runnable () {public void run () {JFrame frame = new Sizeframe (); Frame.settitle ("Test It"); Frame.setdefaultcloseoperation (Jframe.exit_on_close); frame.setvisible (True);}});}}

function Class

Import Java.awt.dimension;import java.awt.image;import Java.awt.toolkit;import Javax.swing.imageicon;import Javax.swing.jframe;public class Sizeframe extends Jframe{public sizeframe () {Toolkit kit = Toolkit.getdefaulttoolkit () ;D imension screensize = kit.getscreensize (); int screenheight = Screensize.height;int ScreenWidth = screenSize.width; SetSize (SCREENWIDTH/2,SCREENHEIGHT/2); Setlocationbyplatform (TRUE); Image img = new ImageIcon ("Icon.gif"). GetImage () ; Seticonimage (IMG);}}

Output Results



My Java Learning notes (21) about frame positioning

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.