Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Can I base all of my windows on JFrame?

 
Kaydell Leavitt
Ranch Hand
Posts: 690
Eclipse IDE Firefox Browser Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 24212
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Campbell Ritchie
Sheriff
Pie
Posts: 50211
79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
. . . Go through the API and you will find that JWindow, JDialog and JFrame already inherit from Object in the same fashion.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic