File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Drawing images in Jpanel, JFrame and game loop

 
Muteking Tonello
Greenhorn
Posts: 8
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello, I'm new, here!
I'm learning to code my first game.
I need to figure how to paint a simple image in the game loop.
As now, I did this but I cannot see anything.
I have another class wich is a Jframe that sets the content of the following

 
Maneesh Godbole
Saloon Keeper
Posts: 10971
11
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
 
Muteking Tonello
Greenhorn
Posts: 8
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think the problem was just in the other class. Silly me.
Now I'm moving to the keylistener.
Thanks for the link.
One thing I did was moving the load method in the init clas. I suppose it's better because it only calls images once and the leave the repaint in the run method.
I guess.
 
Maneesh Godbole
Saloon Keeper
Posts: 10971
11
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Muteking Tonello wrote:I think the problem was just in the other class. Silly me.

Not really. Your myPanel extends JPanel.
As per the link I posted, the recommended way to go is override paintComponent
 
Muteking Tonello
Greenhorn
Posts: 8
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes. It's working like a charm. It doesn't flicker. Does that mean that paintComponent and Jpanel don't need double buffering?
Thanks for the support!
 
Maneesh Godbole
Saloon Keeper
Posts: 10971
11
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Muteking Tonello wrote:Does that mean that paintComponent and Jpanel don't need double buffering?

Double buffering is turned on by default for JPanel. You don't explicitly need to switch it on.
 
Christopher McKay
Ranch Hand
Posts: 50
Android Eclipse IDE Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In future, using a game library would probably be beneficial as you don't run into low-level problems like this. I am using LibGDX and am finding it much easier to code games in than the built-in java libs.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic