The Secret of Java: Using full screen mode

Source: Internet
Author: User
When will the full screen mode be used?


may have a few chances to use, but the JDK provides us with this functionality. Like the print preview feature in many software and some text editors that use Full-screen mode in order to get bigger edits, if you're interested in writing a software like ACDSee, using Full-screen mode allows users to see larger picture images.





How do I use Full-screen mode?


key is the java.awt.* inside the two classes related to display devices: Graphicsenvironment and GraphicsDevice.





Graphicsenvironment provides a platform-specific graphicsdevice for Java applications


objects and a collection of Font objects. These graphicsdevice can be resources for a variety of native and remote machines, such as screens, printers, or image Buffer, or even target objects for graphics2d drawing methods.





and GraphicsDevice refers to the specific graphics environment, such as screen and printing equipment. In this way, we can use GraphicsDevice to manipulate the screen. The Setfullscreenwindow () method provided by GraphicsDevice is set up for full-screen use.





because the Graphicsenvironment constructor is protected (protected), we cannot directly construct a


Graphicsenvironment object to obtain the GraphicsDevice object. Fortunately it provides a getlocalgraphicsenvironment () method for obtaining a Graphicsenvironment instance:


graphicsenvironment ge = graphicsenvironment.getlocalgraphicsenvironment ();


has graphicsenvironment can invoke the Getdefaultscreendevice method to get the current screen device:


GraphicsDevice gd = Ge.getdefaultscreendevice ();





Hands-on Experience


with the above introduction, write an example to experience it:





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.getdefaultscreendevice ();


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 ("Arial", 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.