• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JFrame not conforming to Canvas

 
Muteking Tonello
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm trying to use Canvas and putting it into a JFrame.
The problem is that the JFrame is not packing the content I've drawn. The frame is small and I have to resize the window manually to see what's inside. Clues?



and the main class
 
E Armitage
Rancher
Posts: 989
9
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Set the preferred dimensions before calling pack

 
Muteking Tonello
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks!
 
Richard Tookey
Bartender
Posts: 1166
17
Java Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mixing AWT and Swing used to be a bad idea and though I have heard rumors that it is not so dangerous these days I still don't do it. It is normal to use a JPanel instead of Canvas and override the paintComnponent(Graphics g) method rather than paint(Graphics g).
 
Muteking Tonello
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've seen this guy using awt and Swing together. The game runs perfectly. I'm starting to suspect this is more of a urban legend.
Jframe is just the window border! How much do you think that will impact on performance?
I mean, having a good timer, good graphics and good engine is way better.
That said, this other guy uses JPanel instead of Canvas and the game runs equally smooth.
http://www.youtube.com/watch?v=qJpdRFvSj1A

So, I still don't know wich to prefer, in developing games.
 
Darryl Burke
Bartender
Posts: 5125
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Muteking Tonello wrote:I'm starting to suspect this is more of a urban legend.

It's no urban legend. Check this out: Mixing Heavyweight and Lightweight Components. Make sure you read all of it.

But more than that, why should any programmer want to use classes that were superseded by more modern counterparts more than a decade ago? There's nothing you can do with an extended Canvas that you can't do with an extended JPanel or JComponent.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic