• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JFrame not conforming to Canvas

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Rancher
Posts: 989
9
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Set the preferred dimensions before calling pack

 
Muteking Tonello
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks!
 
Bartender
Posts: 1166
17
Netbeans IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
"Don't believe every tiny ad you see on the internet. But this one is rock solid." - George Washington
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic