The Java program is full of screens.

xiaoxiao2021-03-06  40

Package display;

/ **

* @Author administrator

*

* Todo to change the Template for this generated Type Comment Go To to

* WINDOW - Preferences - Java - Code Style - Code Templates

* /

Import java.awt. *;

Import java.awt.image.bufferstrate;

Import java.awt.image.bufferedImage;

Import java.lang.reflect.InvocationTargeTexception;

Import javax.swing.jframe;

/ **

The ScreenManager Class Manages Initializing and Displaying

Full Screen Graphics Modes.

* /

Public class screenmanager {

Private graphicsDevice device DEVICE DEVICE

/ **

Creates a New ScreenManager Object.

* /

Public screenManager () {

Graphicsenvironment environment =

Graphicsenvironment.getlocalgraphicsenvironment ();

Device = environment.getDefaultscreenDevice ();

}

/ **

Returns a list of compatible display modes for the

Default Device on the system.

* /

Public DisplayMode [] getcompatibleDisplaymodes () {

Return Device.getDisplayModes ();

}

/ **

Returns The First Compatible Mode in a list of modes.

Returns null if no modes are compatible.

* /

Public DisplayMode FindfirstCompAmodeMode

DisplayMode Modes [])

{

DisplayMode Goodmodes [] = device.getdisplayModes ();

For (int i = 0; i

For (int J = 0; j

IF (DisplayModesmatch (MODES [I], GoodModes [J])) {

Return Modes [I];

}

}

}

Return NULL;

}

/ **

Returns The Current Display Mode.

* /

Public DisplayMode getCurrentDisplayMode () {

Return Device.getDisplayMode ();

}

/ **

DETERMINES IF TW DISPLAY MODES "Match". Two Display

Modes Match if The Have The Same Resolution, Bit Depth,

And refresh Rate. The bit depth is ignored if one of there

Modes HAS A bit Depth of DisplayMode.bit_Depth_multi.

Likewise, The Refresh Rate Is Ignored if One of the of themodes Has a Refresh Rate of

DisplayMode.Refresh_rate_unknown.

* /

Public Boolean DisplayModesmatch (DisplayMode Mode1,

DisplayMode Mode2)

{

IF (Mode1.GetWidth ()! = mode2.getwidth () ||

Mode1.getHeight ()! = mode2.getHeight ())

{

Return False;

}

IF (Mode1.GetBitDepth ()! = DisplayMode.bit_Depth_Multi &&&&

Mode2.getbitDepth ()! = displaymode.bit_depth_multi &&&&

Mode1.GetBitDepth ()! = mode2.getbitDepth ())

{

Return False;

}

IF (Mode1.GetRefreshrate ()! =

DisplayMode.refresh_rate_unknown &&

Mode2.getRefreshrate ()! =

DisplayMode.refresh_rate_unknown &&

Mode1.getRefreshrate ()! = mode2.getrefreshrate ())

{

Return False;

}

Return True;

}

/ **

ENTERS FULL Screen Mode and Changes The Display Mode.

IF the specified display mode is null or not compatible

With this device, or if the display mode cannot be

Changed on this System, The Current Display Mode is used.

The Display Uses a bufferstrategy with 2 buffers.

* /

Public void setFullscreen (DisplayMode DisplayMode) {

Final JFrame Frame = New Jframe ();

Frame.setDefaultCloseOperation (jframe.exit_on_close);

Frame.Setundecoated (TRUE);

Frame.setoreRepaint (TRUE);

Frame.setresizable (false);

Device.SetfullScreenWindow (frame);

IF (DisplayMode! = NULL &&

Device.IsDisPlayChangeSupported ())

{

Try {

Device.SetDisplayMode (DisplayMode);

}

Catch (IllegaLaRgumentException EX) {}

// Fix for Mac OS X

Frame.setsize (DisplayMode.GetWidth (),

DisplayMode.getHeight ());

}

// Avoid Potential Deadlock in 1.4.1_02

Try {

EventQueue.invokeAndwait (New Runnable () {

Public void run () {

Frame.createBufferstrategy (2);

}

});

}

Catch (InterruptedException EX) {// ignore

}

Catch (InvocationTargeTexception EX) {

// ignore

}

}

/ **

Gets the graphics context for the display. The display.

ScreenManager Uses Double Buffering, So Applications Must

Call update () to show any graphics drawn.

The Application Must Dispose of The Graphics Object.

* /

Public graphics2d getgraphics () {

Window window = device.getfullscreenwindow ();

IF (window! = null) {

Bufferstrategy Strategy = WINDOW.GETBUFFERSTRATEGY ();

Return (graphics2d) strategy.getdrawgraphics ();

}

Else {

Return NULL;

}

}

/ **

Updates the display.

* /

Public void update () {

Window window = device.getfullscreenwindow ();

IF (window! = null) {

Bufferstrategy Strategy = WINDOW.GETBUFFERSTRATEGY ();

IF (! strategy.contentslost ()) {

Strategy.show ();

}

}

// Sync The Display on Some Systems.

// (on Linux, this fixes event queue problem)

Toolkit.getDefaulttoolkit (). SYNC ();

}

/ **

Returns the window Currently Used in full screen mode.

Returns Null IF The Device IS Not in Full Screen Mode.

* /

Public JFRAME GETFULLSCREENWINDOW () {

Return (jframe) device.getfullscreenwindow ();

}

/ **

Returns the width of the window currently used in full

Screen mode. Returns 0 if the device is not in full

Screen mode.

* /

Public int getWidth () {

Window window = device.getfullscreenwindow ();

IF (window! = null) {

Return window.getwidth ();

}

Else {

Return 0;

}

}

/ **

Returns the Height of the Window Currently Used in Full

Screen mode. Returns 0 if the device is not in full

Screen mode.

* /

Public int getHeight () {

Window window = device.getfullscreenwindow ();

IF (window! = null) {

Return window.getHeight ();

}

Else {

Return 0;

}

}

/ **

RESTORES The Screen's Display Mode.

* /

Public void restorescreen () {

Window window = device.getfullscreenwindow ();

IF (window! = null) {

Window.dispose ();

}

Device.SetfullscreenWindow (NULL);

}

/ **

Creates An Image Compatible with The Current Display.

* /

Public BufferedImage CreateCompatibleImage (int W, Int H,

Int transparancy)

{

Window window = device.getfullscreenwindow ();

IF (window! = null) {

GraphicsConfiguration GC =

WINDOW.GETGRAPHICSCONFIGURATION ();

Return gc.createcompatibleImage (w, h, transparancy);

}

Return NULL;

}

/ **

* @Return Returns the Device.

* /

Public graphicsDevice getDevice () {

Return Device;

}

}

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

New Post(0)