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 );
}
}