Presentation is loading. Please wait.

Presentation is loading. Please wait.

Java2D Graphics Summary Images,. Full-Screen Exclusive Mode -Full-screen exclusive mode is a powerful feature of J2SE TM version 1.4 that allows the programmer.

Similar presentations


Presentation on theme: "Java2D Graphics Summary Images,. Full-Screen Exclusive Mode -Full-screen exclusive mode is a powerful feature of J2SE TM version 1.4 that allows the programmer."— Presentation transcript:

1 Java2D Graphics Summary Images,

2 Full-Screen Exclusive Mode -Full-screen exclusive mode is a powerful feature of J2SE TM version 1.4 that allows the programmer to suspend the windowing system so that drawing can be done directly to the screen. -Full-screen exclusive mode is handled through a java.awt.GraphicsDevice object. -For a list of all available screen graphics devices (in single or multi-monitor systems), you can call the method getScreenDevices on the local java.awt.GraphicsEnvironment; for the default (primary) screen (the only screen on a single- monitor system), you can call the method getDefaultScreenDevice

3 Full-Screen Exclusive Mode In a full-screen exclusive application, the program can control the bit depth and size (display mode) of the screen. Finally, many more advanced techniques, such as page flipping and stereo buffering (utilizing systems which use a separate set of frames for each eye) require, on some platforms, that an application first be in full-screen exclusive mode.

4 Hardware-Accelerated Image Basics Once you have the graphics device, you can call one of the following methods: public boolean isFullScreenSupported() This method returns whether or not full-screen exclusive mode is available. On systems where full-screen exclusive mode is not available, it is probably better to run an application in windowed mode with a fixed size rather than setting a full-screen window. public void setFullScreenWindow(Window w) Given a window, this method enters full-screen exclusive mode using that window. If full-screen exclusive mode is not available, the window is positioned at (0,0) and resized to fit the screen. Use this method with a null parameter to exit full-screen exclusive mode.

5 Summary: Programming Full Screen Exclusive Mode GraphicsDevice myDevice; Window myWindow; try { myDevice.setFullScreenWindow(myWindow);... } finally { myDevice.setFullScreenWindow(null); }

6 Summary: Programming Full Screen Exclusive Mode Most full-screen exclusive applications are better suited to use undecorated windows. (Turn off decorations in a frame or dialog using the setUndecorated method—scroll bar, titles, etc). frame.setUndecorated(false); Full-screen exclusive applications should not be resizable, since resizing a full-screen application can cause unpredictable (or possibly dangerous) behavior. frame.setResizable(false); For security reasons, the user must grant fullScreenExclusive permission when using full-screen exclusive mode in an applet.

7 Programming: Changing the Display Mode The display mode is in (java.awt.DisplayMode) The method getDisplayMode gets current display mode. The method getDisplayModes get ALL possible display modes. GraphicsDevice myDevice; Window myWindow; DisplayMode newDisplayMode; DisplayMode oldDisplayMode = myDevice.getDisplayMode(); try { myDevice.setFullScreenWindow(myWindow); myDevice.setDisplayMode(newDisplayMode);... } finally { myDevice.setDisplayMode(oldDisplayMode); myDevice.setFullScreenWindow(null); }

8 Passive vs Active Rendering // Traditional GUI Application paint method: // This can be called at any time, usually from the event dispatch thread public void paint(Graphics g) { // Use g to draw my Component } This is sometimes referred to as passive rendering. As you can imagine, such a system incurs a lot of overhead, much to the annoyance of many performance-sensitive AWT and Swing programmers.

9 Active Rendering Instead of relying on the paint method in full-screen exclusive mode, drawing code is usually more appropriately done in a rendering loop: public void myRenderingLoop() { while (!done) { Graphics myGraphics = getPaintGraphics(); // Draw as appropriate using myGraphics myGraphics.dispose(); }

10

11 BufferStrategy class – Double Buffering -Suppose you had to draw an entire picture on the screen, pixel by pixel or line by line. -If you were to draw such a thing directly to the screen (using, say, Graphics.drawLine), you would probably notice with much disappointment that it takes a bit of time. -You will probably even notice visible artifacts of how your picture is drawn. Rather than watching things being drawn in this fashion and at this pace, most programmers use a technique called double-buffering. - The traditional notion of double-buffering in Java applications is fairly straightforward: create an offscreen image, draw to that image using the image's graphics object, then, in one step, call drawImage using the target window's graphics object and the offscreen image. You may have already noticed that Swing uses this technique in many of its components, usually enabled by default, using the setDoubleBuffered method.

12 JFrame window = new JFrame(); DisplayMode displayMode = new DisplayMode(800, 600, 16, 75); // get the GraphicsDevice GraphicsEnvironment environment = GraphicsEnvironment.getLocalGraphicsEnvironment(); GraphicsDevice device = environment.getDefaultScreenDevice(); // use the JFrame as the full screen window device.setFullScreenWindow(window); // change the display mode device.setDisplayMode(displayMode); // After you are finished change the graphics mode back // by setting the full screen window to null device.setFillScreenWindow(null);


Download ppt "Java2D Graphics Summary Images,. Full-Screen Exclusive Mode -Full-screen exclusive mode is a powerful feature of J2SE TM version 1.4 that allows the programmer."

Similar presentations


Ads by Google