Re: How to draw a simple line....
- From: Tom Hawtin <usenet@xxxxxxxxxxxxxxxxx>
- Date: Sun, 27 May 2007 22:27:06 +0100
visionset wrote:
"Tom Hawtin" <usenet@xxxxxxxxxxxxxxxxx> wrote in message news:4659c977$0$8715$ed2619ec@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxThere were a number of problems with the original program.
Yes, but do you think the OP is at a stage to take on board your post?
I hoped more people than the original poster would read my message...
But taking my points:
o Painting directly on a top-level window isn't a brilliant idea - can be obscured by child components, there are insets to worry about, it cannot be used as a component, etc.
Yup, given that painting to a top-level component has been shown, need to know it's actually a really bad idea and it should not be copied.
o Swing should be used from the Event Dispatch Thread, not other threads, such as the main thread.
Standard boilerplate for every Swing application. Something you need to start with (although actually possibly not if you are using BlueJ - I don't know).
o Extending JFrame, JPanel, JApplet, etc., is a bad idea. Don't use inheritance more than necessary. Extend JComponent to do the painting, but do most of the work outside.
Yup. There's a lot of really crap tutorial code. Don't do it!
o Setting location (via bounds) of a top-level is peculiar.
Given that the bad code had been shown, it's important not to copy that.
o It's good form to allow frames to be closed, and the program to exit appropriately.
It's a PITA not to.
o Using ... in the declaration of main is obscure.
Yup. ... serves no purpose and is going to cause confusion. Best to ignore that code and do the normal thing.
o If you are using 1.5+ (1.4 is in end of life), use @Override to really make sure you are overriding methods.
It's bad enough for an experienced programmer that hasn't realised he (or she) hasn't overridden a method. Do this right from the start.
Tom Hawtin
.
- Follow-Ups:
- Re: How to draw a simple line....
- From: visionset
- Re: How to draw a simple line....
- References:
- How to draw a simple line....
- From: TheBigPJ
- Re: How to draw a simple line....
- From: visionset
- Re: How to draw a simple line....
- From: visionset
- Re: How to draw a simple line....
- From: TheBigPJ
- Re: How to draw a simple line....
- From: Tom Hawtin
- Re: How to draw a simple line....
- From: visionset
- How to draw a simple line....
- Prev by Date: Re: How to draw a simple line....
- Next by Date: Re: How to draw a simple line....
- Previous by thread: Re: How to draw a simple line....
- Next by thread: Re: How to draw a simple line....
- Index(es):