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