Java Secret: Using full screen mode

zhaozj2021-02-16  73

Sender: TTLINK (Anakin Skywalker), Word Area: Java Title: Java Secret: Using Full Screen Mode (ZZ) Send Station: Sun Moonlight (April 16, 2003 09:08:24 Wednesday), station letter

Http://www.9cbs.net/develop/Article/17/17856.shtm TurboChen (original) When will I use full screen mode? Perhaps the opportunity to use is very small, but JDK is a function of this. Like the print preview feature in many software, there are also some text editors in order to get a larger editing screen, but also use full-screen mode if you are interested in writing a software like ACDSEE, using full screen mode to make The user sees a larger picture picture.

How to use full screen mode? The key is two classes related to the display devices in java.awt. *: Graphicsenvironment and GraphicsDevice. Graphicsenvironment provides the Java application with a specific platform's GraphicsDevice object and Font object collection. These GraphicsDevice can be resources of various local and remote machines, such as screens, printers, or Image Buffers, or even target objects for Graphics2D drawing methods.

GraphicsDevice refers to a specific graphical environment, such as screens and printing devices. In this way, we can use GraphicsDevice to manipulate the screen. The setFullScreenWindow () method provided by GraphicsDevice is to set the full screen. Since Graphicsenvironment's constructor is protected (protected), we cannot directly configure a GraphicSenvironment object to get a GraphicsDevice object.

Fortunately, it provides getLocalGraphicsEnvironment () method, used to obtain a GraphicsEnvironment example: GraphicsEnvironment ge = GraphicsEnvironment getLocalGraphicsEnvironment (); With GraphicsEnvironment can call getDefaultScreenDevice method to obtain the current screen device:. GraphicsDevice gd = ge.getDefaultScreenDevice (); yourself Experience Let's have the above profile, 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 = n EW fullscreenWindow (); if (gd.isfullscreensupported ()) gd.setfullscreenwindow ("unsupported full screen.println);

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

转载请注明原文地址:https://www.9cbs.com/read-17315.html

New Post(0)