Results 1 to 6 of 6
- 07-20-2012, 07:10 PM #1
Member
- Join Date
- Jul 2012
- Posts
- 5
- Rep Power
- 0
- 07-20-2012, 07:44 PM #2
Re: What method is called first: main() or paint() if my class extends JFrame?
main? I know that paint() is a methods inherited from class java.awt.Window. By, main... are you talking about public static void main(). If you are talking about that function, then, yes, it executes first. It is the start of the program. The object JFrame must be initialized before you start using paint, and you have to start a program before creating or initializing an Object, thus, JFrame's Paint() method cannot be used until the program starts.
If it is another main() function thing, then explain what you mean by main(), in context.My API:Java Code:cat > a.out || cat > main.class
- 07-20-2012, 07:57 PM #3
Member
- Join Date
- Jul 2012
- Posts
- 5
- Rep Power
- 0
Re: What method is called first: main() or paint() if my class extends JFrame?
That was public static void main() I was referring to, thanks!
- 07-20-2012, 08:40 PM #4
Re: What method is called first: main() or paint() if my class extends JFrame?
No, problem!
My API:Java Code:cat > a.out || cat > main.class
- 07-23-2012, 10:46 AM #5
Moderator
- Join Date
- Apr 2009
- Posts
- 10,452
- Rep Power
- 16
Re: What method is called first: main() or paint() if my class extends JFrame?
Of course in 99.999% of cases you shouldn't be extending JFrame in the first place...
Please do not ask for code as refusal often offends.
- 07-24-2012, 09:35 AM #6
Moderator
- Join Date
- Apr 2009
- Posts
- 10,452
- Rep Power
- 16
Re: What method is called first: main() or paint() if my class extends JFrame?
kammce, I (like most of the mods here) don't tend to answer PMs on Java issues, so I'll answer your question here, which seems a fair enough place to do it.
A JFrame is a container. It's purpose is to hold stuff, generally a JPanel in which you then put everything else.Could you answer to me, why this is? I extend my JFrame some times. It depends on what I am doing. Why should extending JFrame be discouraged in Java programming. There seems to be quite a few Java programming practices that I do on a normal basis, that seem to be an discouraged on this forum even though I seem them used in Java Tutorials online and in the books that I have read in the past.
Thank you for reading.
Most people extend the JFrame just to put the code for building the JFrame in the new class:
That there is not an extension of a JFrame.Java Code:class MYFrame extends JFrame { public MyFrame() { buildPanels(); } }
It adds no functionality to a JFrame, it simply holds the information for adding stuff to the JFrame.
It's the equivalent of:
Which, hopefully, you'll agree is a silly thing to do.Java Code:class MyArrayList extends ArrayList { public MyArrayList() { add(something); add(somethingElse); } }
If you're not changing the functionality of the class (eg paintComponent on a JPanel, which is quite common) then you're not extending it.Please do not ask for code as refusal often offends.
Similar Threads
-
Why is the paint method in this ImageCanvas Class, being endlessly called?
By Joe88 in forum Java 2DReplies: 2Last Post: 08-23-2011, 11:04 PM -
Can't get my Java Program to Paint. Extends JFrame
By ttown in forum New To JavaReplies: 6Last Post: 04-27-2011, 05:27 AM -
Class that extends JFrame help
By javaman1 in forum New To JavaReplies: 5Last Post: 11-10-2010, 02:29 AM -
Paint(Graphics g) method is not called on its run.
By vsanandan in forum Java 2DReplies: 5Last Post: 10-22-2010, 01:55 PM -
Why the paint() method is called two times ?
By supremo in forum New To JavaReplies: 4Last Post: 06-03-2010, 06:21 PM


1Likes
LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks