HomeDigital EditionSys-Con RadioSearch Java Cd
Advanced Java AWT Book Reviews/Excerpts Client Server Corba Editorials Embedded Java Enterprise Java IDE's Industry Watch Integration Interviews Java Applet Java & Databases Java & Web Services Java Fundamentals Java Native Interface Java Servlets Java Beans J2ME Libraries .NET Object Orientation Observations/IMHO Product Reviews Scalability & Performance Security Server Side Source Code Straight Talking Swing Threads Using Java with others Wireless XML

"Java Wizard Class"
Vol. 3, Issue 6, P.28


Listing 1: WizardInterface

import java.awt.Component;

//Interface for a Wizard Class
public interface WizardInterface
public void setWizardAdapter(WizardAdapter adapter);
public WizardAdapter getWizardAdapter();

public void setTitle(String title);

//Optional Help Button
public void setHelpVisible(boolean state);
public boolean isHelpVisible();

//Enter key behavior
public void setEnterKeyActive(boolean state);
public boolean isEnterKeyActive();

//Panels can be hidden - if hidden, they are skipped by previous,next
public void hidePanel(int index);
public void hidePanel(Component panel);
public boolean isPanelHidden(int index);
public boolean isPanelHidden(Component panel);
public void unHidePanel(int index);
public void unHidePanel(Component panel);

public int getNumberOfPanels();
public int getCurrentPanelIndex();
public Component getCurrentPanel();
public Component getPanel(int index);

public int getPanelIndex(Component panel);

//allows you to go directly to any panel in the wizard
//returns false if panel is hidden and could not be displayed
public boolean setCurrentPanel(int index);

public void doPrevious();
public void doNext();
public void doFinish();
public void doCancel();
public void doHelp();

public boolean isPreviousEnabled();
public boolean isNextEnabled();
public boolean isFinishEnabled();
public boolean isCancelEnabled();
public boolean isHelpEnabled();


Listing 2: WizardEvent

import java.util.*;

public class WizardEvent extends java.util.EventObject {
    Wizard wizard_;
    public WizardEvent(Object source, Wizard wiz){
    public Wizard getWizard(){
        return wizard_;
Listing 3: WizardListener

import java.util.EventListener;

public interface WizardListener extends EventListener {
    public void nextButtonClicked(WizardEvent evt);
    public void previousButtonClicked(WizardEvent evt);
    public void cancelButtonClicked(WizardEvent evt);
    public void finishButtonClicked(WizardEvent evt);
    public void helpButtonClicked(WizardEvent evt);
    public void wizardActivated(WizardEvent evt);

Listing 4: PreviousButtonListener Class

private class PreviousButtonListener implements ActionListener {
        public void actionPerformed(ActionEvent e) {
            //broadcast WizardEvent out to everyone
            WizardEvent evt;
            evt=new WizardEvent(e,thisWizard_);

Listing 5: NextEnterKeyListener

private class NextEnterKeyListener extends KeyAdapter {
        public void keyReleased(KeyEvent k) {
            if (enterKeyActive_){
                if (k.getKeyCode() == java.awt.event.KeyEvent.VK_ENTER) {
                    WizardEvent evt;
                    evt=new WizardEvent(k,thisWizard_);
                }//if keycode

Listing 6: UnfocusedTextArea Class

private class UnfocusedTextArea extends TextArea {
        public UnfocusedTextArea(String s, int row, int col, int visibility){

        public boolean isFocusTraversable(){
            return false;


All Rights Reserved
Copyright ©  2004 SYS-CON Media, Inc.
  E-mail: [email protected]

Java and Java-based marks are trademarks or registered trademarks of Sun Microsystems, Inc. in the United States and other countries. SYS-CON Publications, Inc. is independent of Sun Microsystems, Inc.