OZONE Asylum
Forums
DHTML/Javascript
Open Source fullscreen stub for Java
This page's ID:
28405
Search
QuickChanges
Forums
FAQ
Archives
Register
Edit Post
Who can edit a post?
The poster and administrators may edit a post. The poster can only edit it for a short while after the initial post.
Your User Name:
Your Password:
Login Options:
Remember Me On This Computer
Your Text:
Insert Slimies »
Insert UBB Code »
Close
Last Tag
|
All Tags
UBB Help
Hello world, This is the most simple example of a fullscreen application starter for Java I could think of. As an applet, it has restrictions, unless ran from appletviewer. As a webstart app or normal app, it is decent, and very small in size (4 to 2kb if in a jar). Enjoy. [code] package ake; /* Applet code by Mauro Colella (c) 2006 ================ Feel free to use for personal needs. For commercial uses, include the source of this applet. ** Tips -- It is subject to security restructions when run from a browser -- works well when run from appletViewer -- Useful for inclusion in Java applications or webstarted applications -- JOGL friendly */ import java.applet.Applet; import java.awt.HeadlessException; import java.awt.GraphicsDevice; import java.awt.*; import java.awt.image.*; import java.awt.event.*; public class stub extends Applet implements Runnable, KeyListener { GraphicsDevice context = null; private static Thread runner = null; private static Frame window = null; private static BufferStrategy strategy = null; private static BufferCapabilities capabilities = null; GraphicsConfiguration gc = null; private int i = 0; DisplayMode newDisplayMode = null, oldDisplayMode = null; // = // myDevice.getDisplayMode(); public stub() throws HeadlessException { super(); // TODO Auto-generated constructor stub } public void init() { } public void start() { if (runner == null) { context = GraphicsEnvironment.getLocalGraphicsEnvironment() .getDefaultScreenDevice(); gc = context.getDefaultConfiguration(); oldDisplayMode = context.getDisplayMode(); newDisplayMode = new DisplayMode(800,600,32,85); window = new Frame(gc); window.setName("Fullscreen applet"); //myWindow.setSize(800, 600); window.addKeyListener(this); window.setUndecorated(true); window.setIgnoreRepaint(true); //window.setAlwaysOnTop(true); window.setVisible(true); runner = new Thread(this); strategy = window.getBufferStrategy(); capabilities = strategy.getCapabilities(); try { context.setFullScreenWindow(window); if(context.isDisplayChangeSupported()){ context.setDisplayMode(newDisplayMode); } } catch(Exception e) { context.setFullScreenWindow(null); if(context.isDisplayChangeSupported()){ context.setDisplayMode(oldDisplayMode); } } System.out.println(capabilities.isMultiBufferAvailable()); runner.start(); } } public void run() { BufferStrategy bs; while (true) { // repaint(); //g = myWindow.getGraphics(); //if (context.isFullScreenSupported() /* /* && * context.isDisplayChangeSupported() *///) { i++; i %= window.getHeight(); try{ //window.createBufferStrategy(1,capabilities); bs = window.getBufferStrategy(); if (!bs.contentsLost()) { Graphics g = bs.getDrawGraphics(); render(g); bs.show(); g.dispose(); } } catch(Exception e){ e.printStackTrace(); } //} } } private final void render(Graphics g){ g.setColor(new Color(0, 0, 255)); g.drawLine(0, i, window.getWidth(), i); try{ Thread.sleep(1); } catch(InterruptedException e){ //e.printStackTrace(); } g.setColor(new Color(255, 255, 255)); g.drawLine(0, i, window.getWidth(), i); } public void paint(Graphics g) { //myWindow.paintComponents(myFrame.getGraphics()); } public void update() { } public void keyPressed(KeyEvent e) { runner.interrupt(); window.setVisible(false); System.exit(0); } public void keyTyped(KeyEvent e) { } public void keyReleased(KeyEvent e) { } } [/code]
Loading...
Options:
Enable Slimies
Enable Linkwords
« Backwards
—
Onwards »