[java] Graphics?
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
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);}
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.
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
class something extends JFrame{ //JFrame or any other child of awt.WindowBufferStrategy 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
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement