> I had interview question. She asked me if you have 2 threads and you
> have class extending from the JFrame you can safely display class from
> each thread or not and why? I do not know answer. I know recomendation
> is to work with Swing from only main thread. Can someone explain me
> answer to such question? Thank you for this help.

Signature
Unemployed English Java programmer
http://jroller.com/page/tackline/
> If you've got a class extending JFrame, you are probably extending
> classes inappropriately. But apparently bad coding is fine for GUI
> applications...
Thank you for answer it is more clear now. I don't understand this
point about extendin classed inappropriately? Most sample code for
Swing tutorial has class MyFrame extends JFrame {...} Are you saying
the tutorial code are probably extending classes inappropriately?
Chris Smith - 15 Sep 2006 16:45 GMT
> Thank you for answer it is more clear now. I don't understand this
> point about extendin classed inappropriately? Most sample code for
> Swing tutorial has class MyFrame extends JFrame {...} Are you saying
> the tutorial code are probably extending classes inappropriately?
Yes, that's what Thomas is saying. He's right, too.

Signature
Chris Smith
Thomas Hawtin - 15 Sep 2006 16:56 GMT
>> If you've got a class extending JFrame, you are probably extending
>> classes inappropriately. But apparently bad coding is fine for GUI
[quoted text clipped - 4 lines]
> Swing tutorial has class MyFrame extends JFrame {...} Are you saying
> the tutorial code are probably extending classes inappropriately?
Yes.
See Effective Java, Item 14: Favor composition over inheritance.
Indeed almost all of the code should not be dependent on being in a
JFrame. There's two main motivations for this: Firstly, you want to keep
your code as simple as possible, so don't involve inheritance. A
secondary point is that you may want to move your JFrame contents to,
say, a JInternalFrame, a JDialog, a JSplitPane, a JApplet, a JFrame
subclassed for some genuine purpose, another layer of panels between
frame and your contents, or something you haven't thought of yet.
Tom Hawtin

Signature
Unemployed English Java programmer
http://jroller.com/page/tackline/