Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use Swing full screen mode

Shulou Source: shulou.com Published: 2022-06-02 08:32:50 09月15日 Update

This article mainly introduces how to use Swing full-screen mode, the article is very detailed, has a certain reference value, interested friends must read it!

How do I use Swing full-screen mode?

The key is the two display device-related classes in java.awt.*: GraphicsEnvironment and GraphicsDevice.

GraphicsEnvironment provides platform-specific collections of GraphicsDevice and Font objects for Java applications. These GraphicsDevice can be the resources of a variety of local and remote machines, such as screens, printers, or Image Buffer, or even the target of Graphics2D drawing methods.

GraphicsDevice refers to a specific graphics environment, such as screens and printing devices. In this way, we can manipulate the screen with GraphicsDevice. The setFullScreenWindow () method provided by GraphicsDevice is used to set up the full screen.

Because the constructor of GraphicsEnvironment is protected, we cannot directly construct a GraphicsEnvironment object to get the GraphicsDevice object. Fortunately, it provides a getLocalGraphicsEnvironment () method to get an instance of GraphicsEnvironment:

GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment ()

With GraphicsEnvironment, you can call the getDefaultScreenDevice method to get the current Swing full-screen mode device:

GraphicsDevice gd = ge.getDefaultScreenDevice ()

Do it yourself.

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

Importjava.awt.Color; importjava.awt.Font; importjava.awt.Graphics; importjava.awt.GraphicsDevice; importjava.awt.GraphicsEnvironment; importjava.awt.event.MouseAdapter; importjava.awt.event.MouseEvent; importjavax.swing.JWindow; publicclassFullScreenTest {publicstaticvoidmain (String [] args) {GraphicsEnvironmentGraphicsEnvironmentge= GraphicsEnvironment.getLocalGraphicsEnvironment (); GraphicsDevicegd=ge.getDefaultScreenDevice (); FullScreenWindowmyWindow=newFullScreenWindow (); if (gd.isFullScreenSupported ()) gd.setFullScreenWindow (myWindow); else System.out.println ("Unsupportedfullscreen.") } staticclassFullScreenWindowextendsJWindow {publicFullScreenWindow () {this.addMouseListener (newMouseAdapter () {publicvoidmousePressed (MouseEventevt) {quit ();}});} publicvoidquit () {this.dispose ();} publicvoidpaint (Graphicsg) {g.setFont (newFont ("Arial", Font.BOLD,30)); g.setColor (Color.RED); g.drawString ("this is full screen mode", 100100) } these are all the contents of the article "how to use Swing full-screen mode". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!

Tags: Screen pattern object method device content instance that is article experience two value key interest graphics partner platform application printer Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Huawei Linux OPPO Reno Microsoft Docker