Java full screen

Source: Internet
Author: User

Update: 2012 07 17

You can also use another simple method to achieve full screen form effect.
This. setextendedstate (jframe. maximized_both );
This. setundecorated (true );

--------------------------------------------------------------------------------

When will the full screen mode be used?
There may be few opportunities to use it, but JDK still provides us with this function. Like the print preview feature in many software programs, some text editors also use full screen mode for larger editing images. If you are interested in writing a software like ACDSee, the full screen mode allows you to see larger images.

How to use full screen mode?
The key is the two display device-related classes in Java. AWT. *: graphicsenvironment and graphicsdevice.

Graphicsenvironment provides graphicsdevice of a specific platform for Java applications.
Object and font object set. These graphicsdevices can be resources of various local and remote machines, such as screens, printers, image buffers, and even target objects of graphics2d plotting methods.

Graphicsdevice refers to a specific graphic environment, such as a screen or a printing device. In this way, we can use graphicsdevice to manipulate the screen. The setfullscreenwindow () method provided by graphicsdevice is used to set the full screen.

Since the graphicsenvironment constructor is protected, we cannot directly construct
Graphicsenvironment object to obtain the graphicsdevice object. Fortunately, it provides the getlocalgraphicsenvironment () method to obtain a graphicsenvironment instance:
Graphicsenvironment Ge = graphicsenvironment. getlocalgraphicsenvironment ();
With graphicsenvironment, you can call the getdefascrescreendevice method to obtain the current screen device:
Graphicsdevice GD = Ge. getdefascrescreendevice ();

Try it yourself
With the introduction above, write an instance to try it out:

Import java. AWT .*;
Import java. AWT. event .*;
Import javax. Swing .*;

Public class fullscreentest
{
Public static void main (string [] ARGs)
{

Graphicsenvironment Ge =
Graphicsenvironment. getlocalgraphicsenvironment ();
Graphicsdevice GD = Ge. getdefascrescreendevice ();
Fullscreenwindow mywindow = new fullscreenwindow ();
If (Gd. isfullscreensupported ())
GD. setfullscreenwindow (mywindow );
Else
System. Out. println ("unsupported full screen .");

}
}

Class fullscreenwindow extends jwindow
{
Public fullscreenwindow ()
{
This. addmouselistener (New mouseadapter ()
{
Public void mousepressed (mouseevent EVT)
{
Quit ();
}
});
}

Public void quit ()
{
This. Dispose ();
}

Public void paint (Graphics g)
{
G. setfont (new font ("default", Font. Bold, 30 ));
G. setcolor (color. Red );
G. drawstring ("this is full screen mode", 100,100 );

}

}

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.