Hurdler
Hurdler

Reputation: 891

Making windows with Java

;) I'm trying to do a sequence of GUI windows in Java. Firstly, question about the design. I'm planning to have 8/9 similar types of windows:

I thought about doing one abstract class "DummyWindow" which would be the base for any other one and then expand it. What do you say? Also, what would you advise regarding the actual code approach to the windows? Thanks a lot.

Upvotes: 1

Views: 1160

Answers (2)

Costis Aivalis
Costis Aivalis

Reputation: 13728

Take a look at this article. Shows you how to make Wizard Dialogs, which looks to me quite similar to what you are doing.

Upvotes: 2

chubbsondubs
chubbsondubs

Reputation: 38676

So you'll want to use Swing. Here is a simple hello world demo you can copy and paste.

http://www.java2s.com/Code/Java/Swing-JFC/HelloWorldSwing.htm

For what you're doing you'll want to look at using CardLayout. CardLayout makes creating wizards, like the one you describe, very simple. I'd create several subclasses of JPanel for each individual screen you plan on displaying. Those series of JPanel can be added together in a larger JPanel using CardLayout. Each of the sub-screens will be an individual screen that is displayed alone. Then that larger panel can be face-plated on a JFrame or JDialog.

I also recommend using TableLayout over GridBagLayout, GridLayout, nested BoxLayout which is provided in Swing. You can learn about TableLayout here and download it:

http://java.sun.com/products/jfc/tsc/articles/tablelayout/

I usually subclass things like JPanel for window-like things because JPanel is just a simple container, and that can be added to JFrame, JDialog, etc without any internal changes. If you subclass JFrame, JWindow, or JDialog you can only ever be that. JPanel gives you flexibility.

Upvotes: 2

Related Questions