Skip to main content
gamedev.net
🔒 Locked

[java] Java fullscreen game problems

Started by beethoven_425 Dec 15, 2004 at 4:06 PM 0 replies 550+ views
Original Post
beethoven_425
beethoven_425
Hi I have this sourcecode: import java.awt.*; import javax.swing.*; import java.awt.event.*; import java.awt.image.*; public class ProjectV2 extends Frame { private Image dbImage; private Graphics dbg; int xpos=100; Button knopje; Thread th; Image kolenwagon = Toolkit.getDefaultToolkit().getImage("kolenwagon.jpg"); Image rails = Toolkit.getDefaultToolkit().getImage("rails.jpg"); public static void main(String[] args) { ProjectV2 projectV2 = new ProjectV2(); projectV2.mainloop(); } public ProjectV2() { GraphicsDevice myDevice = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice(); DisplayMode oldMode = myDevice.getDisplayMode(); DisplayMode newMode = new DisplayMode(1024, 768, 32, oldMode.getRefreshRate()); if(myDevice.isFullScreenSupported()) { try { this.setVisible(false); this.dispose(); this.setUndecorated(true); myDevice.setFullScreenWindow(this); myDevice.setDisplayMode(newMode); } catch (Exception e) { myDevice.setDisplayMode(oldMode); } } else { System.out.println("Sorry No Fullscreen"); System.exit(0); } requestFocus(); Button knopje = new Button("knoopje"); knopje.setBounds(200,200,200,200); knopje.setVisible(true); //add(knopje); } /** Doublebuffer */ public void update( Graphics g ) { if( dbImage == null ) { dbImage = createImage( this.getSize().width, this.getSize().height ); dbg = dbImage.getGraphics(); } dbg.setColor( getBackground () ); dbg.fillRect( 0, 0, this.getSize().width, this.getSize().height ); dbg.setColor( getForeground() ); paint( dbg ); g.drawImage( dbImage, 0, 0, this ); } public void paint(Graphics g) { g.drawString("Hello World", 100, 100); g.drawImage(rails,200, 200,this); g.drawImage(kolenwagon,xpos, 100,this); } public void mainloop () { Thread.currentThread().setPriority(Thread.MIN_PRIORITY); while (true) { xpos+=1; repaint(); try { Thread.sleep (100); } catch (InterruptedException ex) { } Thread.currentThread().setPriority(Thread.MAX_PRIORITY); } } } is it right that it takes a while for the images to load? My PC is pretty fast. But it takes a while for the images to load it seems. Sometimes when I click right at the start it suddenly appears. Like it needs a focus or something. What I also think is strange is the fact that i cant see my button (i disabled it now). When you click the button it will appear and right after that it disappears. very fast. Edit: The first picture loads right away, but the second one only appears later. [Edited by - beethoven_425 on December 15, 2004 4:23:02 PM]
tjoink
tjoink
That is not how you implement a double buffer. Your problem lies there, you're doing too much operations in your update and paint methods. You should only create the buffer graphics once, draw to it, and in the update method just blit that to the screen.
Hope that's of help, didn't feel like going through your code line by line or rewrite it.
8! bits.. wow..

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.