Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Jumei

[java] Graphics?

This topic is 5220 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
call repaint() to ask java to call your paint method again. if you''re redrawing the whole screen over again, you can also add this to eliminate flicker:

public void update(Graphics g){
paint(g);
}

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!