Two Laptop Bag*
The moose likes Game Development and the fly likes JFrame not conforming to Canvas Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Game Development
Bookmark "JFrame not conforming to Canvas" Watch "JFrame not conforming to Canvas" New topic
Author

JFrame not conforming to Canvas

Muteking Tonello
Greenhorn

Joined: Jul 18, 2013
Posts: 8
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

Joined: Mar 17, 2012
Posts: 892
    
    9
Set the preferred dimensions before calling pack

Muteking Tonello
Greenhorn

Joined: Jul 18, 2013
Posts: 8
Thanks!
Richard Tookey
Ranch Hand

Joined: Aug 27, 2012
Posts: 1050
    
  10

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

Joined: Jul 18, 2013
Posts: 8
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

Joined: May 03, 2008
Posts: 4531
    
    5

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.


luck, db
There are no new questions, but there may be new answers.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JFrame not conforming to Canvas