Results 1 to 7 of 7
Thread: Which component to draw on?
- 04-17-2013, 12:14 PM #1
Member
- Join Date
- Aug 2011
- Posts
- 63
- Rep Power
- 0
Which component to draw on?
Hello forum,
I have read some tutorials on game programming and Java 2D, but I am still confused about the architecture of such programs. Some people draw on Canvas and add that to a JFrame, some draw directly on a JFrame and others on a JPanel inside a JFrame. Which option would you recommend and where are the advantages/disadvantages of every single approach? Thanks.
- 04-17-2013, 12:30 PM #2
Re: Which component to draw on?
Hi,
Canvas and JFrame doesn't work. Never mix lightweight and heavyweight components, i.e. Swing and AWT. I'd go for JPanels in JFrames. Read this tutorial: Lesson: Performing Custom Painting (The Java™ Tutorials > Creating a GUI With JFC/Swing)Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
The Ubiquitous Newbie Tips
- 04-17-2013, 01:08 PM #3
Member
- Join Date
- Aug 2011
- Posts
- 63
- Rep Power
- 0
Re: Which component to draw on?
Thank you. Should the JFrame be extended in the game class (which is often done) or better used as a property?
- 04-17-2013, 01:15 PM #4
Re: Which component to draw on?
As a property. You're not modifying it's behaviour, you're only using it.
Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
The Ubiquitous Newbie Tips
- 04-17-2013, 01:15 PM #5
Moderator
- Join Date
- Apr 2009
- Posts
- 13,541
- Rep Power
- 27
Re: Which component to draw on?
It is almost never necessary to extend JFrame.
A JFrame is simply the top level container of a Swing app, all the bits of the GUI ending up in its base JPanel.
Extending JFrame to add things to it would by like extending ArrayList simply to populate it with values.Please do not ask for code as refusal often offends.
** This space for rent **
- 04-19-2013, 07:10 PM #6
Member
- Join Date
- Aug 2011
- Posts
- 63
- Rep Power
- 0
Re: Which component to draw on?
Thanks to all of you. It's somehow annoying that so many bad code examples can be found on the internet. Apart from the Oracle docs, which Java coding websites are really reliable?
- 04-25-2013, 09:12 PM #7
Member
- Join Date
- Aug 2011
- Posts
- 63
- Rep Power
- 0
Similar Threads
-
can several seperate paint component classes draw on the one jpanel
By such orb in forum AWT / SwingReplies: 1Last Post: 11-05-2012, 08:09 PM -
Calling methods of a component from a different component
By Mate de Vita in forum AWT / SwingReplies: 0Last Post: 10-26-2012, 09:15 PM -
why cant i draw this box???
By stefandanielsen in forum New To JavaReplies: 2Last Post: 05-12-2011, 03:53 PM -
how to draw an arc
By Baker in forum New To JavaReplies: 1Last Post: 04-16-2009, 10:05 PM -
help me draw... please...
By kureikougaiji in forum New To JavaReplies: 1Last Post: 01-28-2008, 01:22 PM
Bookmarks