aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Can I base all of my windows on JFrame? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Can I base all of my windows on JFrame?" Watch "Can I base all of my windows on JFrame?" New topic
Author

Can I base all of my windows on JFrame?

Kaydell Leavitt
Ranch Hand

Joined: Nov 18, 2006
Posts: 689

I'm used to a class library (pre-Java, but object-oriented), that based all windows on a single base class. If written in Java, it would be like the following:



Is the above design possible in Swing, using the JFrame class? I'd like everything, deep-down to have a common anscestor class like JFrame. I'd rather do this than use three different classes:

JFrame for modeless windows.
JDialog for modal windows.
and
JOptionPane for simple alerts.

Is my design a good use of Swing or am I "going against the grain."

Kaydell
[ May 27, 2007: Message edited by: Kaydell Leavitt ]
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

All of these classes already have java.awt.Component as an ancestor; maybe you can make use of that fact.

But as far as top level windows go, I don't think there's any reason you're forced to use JDialog or JOptionPane, except for modality; off the top of my head I don't believe you can implement a true modal dialog with JFrame (someone may prove me wrong here, though.) If you can live without true modal dialogs, then there's no reason not to do what you suggest, other than the reinventing-the-wheel that' you'd be doing instead of using JOptionPane.


[Jess in Action][AskingGoodQuestions]
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39791
    
  28
. . . Go through the API and you will find that JWindow, JDialog and JFrame already inherit from Object in the same fashion.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Can I base all of my windows on JFrame?