Skip to main content
gamedev.net
🔒 Locked

[java] Graphics?

Started by Jumei 1 reply 500+ views
Original Post
Jumei
Jumei
Ok im some what new to java... Ive been working with graphics windows and paint method... i have the usual public void paint(Graphics g) { } ... but now im working on getting the window to change on mouseClicks and such... how would i do that? Also, lets say i wanted like an image... for example an image of a cat... to walk.."move" back and forth across the Graphics window... how would that work? Hope someone can help me... Thank you
capn_midnight
capn_midnight
assuming you have the appropriate mouse listeners setup, then the repaint method will *work*, however, I doubt that the update method calling the paint method will elliminate flickering. double buffering is needed to elliminate flicker.


class something extends JFrame{ //JFrame or any other child of awt.Window

BufferStrategy bs;
public something(){
this.createBufferStrategy(2, new BufferCapabilities(new ImageCapabilites(true), new ImageCapabilities(true), null); //start setting up double buffering

bs=this.getBufferStrategy();
}

public void paint(Graphics gOld){
//ignore gOld, we don''t need it

Graphics g=bs.getDrawGraphics();
//anything you need to paint

bs.show();
}
}

I generally also call this.setIgnoreRepaint(true) in the constructor, and setup a Timer thread to call a painting method, and not even worring about having the Graphics parameter passed to it, because I would never use it.



capn_midnight | Captain Midnight | deviantArt
ACM | SIGGRAPH | Generation5
"I''m tired of all this nonsense about beauty being only skin-deep. That''s deep enough. What do you want - an adorable pancreas?" -Jean Kerr

Topic Locked

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

Sign in to reply to this topic.