Dynamic Wizard Dialog : Wizard « Swing Components « Java

Home
Java
1.2D Graphics GUI
2.3D
3.Advanced Graphics
4.Ant
5.Apache Common
6.Chart
7.Class
8.Collections Data Structure
9.Data Type
10.Database SQL JDBC
11.Design Pattern
12.Development Class
13.EJB3
14.Email
15.Event
16.File Input Output
17.Game
18.Generics
19.GWT
20.Hibernate
21.I18N
22.J2EE
23.J2ME
24.JavaFX
25.JDK 6
26.JDK 7
27.JNDI LDAP
28.JPA
29.JSP
30.JSTL
31.Language Basics
32.Network Protocol
33.PDF RTF
34.Reflection
35.Regular Expressions
36.Scripting
37.Security
38.Servlets
39.Spring
40.Swing Components
41.Swing JFC
42.SWT JFace Eclipse
43.Threads
44.Tiny Application
45.Velocity
46.Web Services SOA
47.XML
Java » Swing Components » Wizard 




Dynamic Wizard Dialog
Dynamic Wizard Dialog
 
package jwizardcomponent.example;

import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;

import javax.swing.JLabel;
import javax.swing.JRadioButton;
import javax.swing.ButtonGroup;

import jwizardcomponent.Utilities;
import jwizardcomponent.JWizardPanel;
import jwizardcomponent.JWizardComponents;
import jwizardcomponent.frame.JWizardFrame;

/**
 * <p>Title: JWizardComponent</p>
 * <p>Description: Swing-Based Wizard Framework for Wizards</p>
 * <p>Copyright (C) 2003 William Ready
 *
 * <br>This library is free software; you can redistribute it and/or
 * <br>modify it under the terms of the GNU Lesser General Public
 * <br>License as published by the Free Software Foundation; either
 * <br>version 2.1 of the License, or (at your option) any later version.
 *
 * <br>This library is distributed in the hope that it will be useful,
 * <br>but WITHOUT ANY WARRANTY; without even the implied warranty of
 * <br>MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * <br>See the GNU Lesser General Public License for more details.
 *
 * <br>To receive a copy of the GNU Lesser General Public License
 * <br>write to:  The Free Software Foundation, Inc.,
 * <br>59 Temple Place, Suite 330
 * <br>Boston, MA 02111-1307 USA</p>
 @author Piotr Kaminski
 @version 1.0
 */

public class DynamicJWizard extends JWizardFrame {
    
    public static final int PANEL_FIRST = 0;
    public static final int PANEL_CHOOSER = 1;
    public static final int PANEL_OPTION_A = 2;
    public static final int PANEL_OPTION_B = 3;
    public static final int PANEL_LAST = 4;
    
    public DynamicJWizard() {
        super();
        init();
    }
    
    private void init() {
        this.setTitle("Dynamic JWizardComponent example");
        
        JWizardPanel panel = null;
        
        panel = new FirstWizardPanel(getWizardComponents());
        getWizardComponents().addWizardPanel(PANEL_FIRST, panel);
        
        panel = new ChooserWizardPanel(getWizardComponents());
        getWizardComponents().addWizardPanel(PANEL_CHOOSER, panel);
        
        panel = new OptionWizardPanel(getWizardComponents()"A");
        getWizardComponents().addWizardPanel(PANEL_OPTION_A, panel);
        
        panel = new OptionWizardPanel(getWizardComponents()"B");
        getWizardComponents().addWizardPanel(PANEL_OPTION_B, panel);
        
        panel = new LastWizardPanel(getWizardComponents());
        getWizardComponents().addWizardPanel(PANEL_LAST, panel);
        
        setSize(500300);
        Utilities.centerComponentOnScreen(this);
    }
    
    public static void main(String [] args) {
        DynamicJWizard wizard = new DynamicJWizard();
        wizard.setVisible(true);
    }
}

class LabelWizardPanel extends JWizardPanel {
    public LabelWizardPanel(JWizardComponents wizardComponents, String label) {
        super(wizardComponents);
        this.setLayout(new GridBagLayout());
        this.add(new JLabel(label)
        new GridBagConstraints(00110.00.0
        , GridBagConstraints.CENTER, GridBagConstraints.BOTH
        new Insets(0000)00));
    }
}
class FirstWizardPanel extends LabelWizardPanel {
    public FirstWizardPanel(JWizardComponents wizardComponents) {
        super(wizardComponents, "First panel");
        setPanelTitle("First simple static panel");
    }
}

class ChooserWizardPanel extends JWizardPanel {
    private JRadioButton optionARadioButton;
    private JRadioButton optionBRadioButton;
    private JRadioButton optionFRadioButton;
    private ButtonGroup bg;
    private char selectedOption = 'N'// 'N' is no option selected
    // 'A', 'B' & 'F' stands for options
    public ChooserWizardPanel(JWizardComponents wizardComponents) {
        super(wizardComponents, "Choose option A or B or F for finish ");
        init();
    }
    private void init() {
        optionARadioButton = new JRadioButton();
        optionBRadioButton = new JRadioButton();
        optionFRadioButton = new JRadioButton();
        ButtonGroup bg = new ButtonGroup();
        bg.add(optionARadioButton);
        bg.add(optionBRadioButton);
        bg.add(optionFRadioButton);
        this.setLayout(new GridBagLayout());
        
        this.add(optionARadioButton
        new GridBagConstraints(00110.00.0
        , GridBagConstraints.WEST, GridBagConstraints.BOTH
        new Insets(0000)00));
        optionARadioButton.addItemListener(new ItemListener() {
            public void itemStateChanged(ItemEvent e) {
                if (e.getStateChange() == ItemEvent.SELECTED) {
                    selectedOption = 'A';
                    update();
                }
            }
        });
        this.add(new JLabel("Choose option A")
        new GridBagConstraints(10110.00.0
        , GridBagConstraints.WEST, GridBagConstraints.BOTH
        new Insets(0000)00));
        
        this.add(optionBRadioButton,
        new GridBagConstraints(01110.00.0
        , GridBagConstraints.WEST, GridBagConstraints.BOTH
        new Insets(0000)00));
        optionBRadioButton.addItemListener(new ItemListener() {
            public void itemStateChanged(ItemEvent e) {
                if (e.getStateChange() == ItemEvent.SELECTED) {
                    selectedOption = 'B';
                    update();
                }
            }
        });
        this.add(new JLabel("Choose option B")
        new GridBagConstraints(11110.00.0
        , GridBagConstraints.WEST, GridBagConstraints.BOTH
        new Insets(0000)00));
        
        this.add(optionFRadioButton,
        new GridBagConstraints(02110.00.0
        , GridBagConstraints.WEST, GridBagConstraints.BOTH
        new Insets(0000)00));
        optionFRadioButton.addItemListener(new ItemListener() {
            public void itemStateChanged(ItemEvent e) {
                if (e.getStateChange() == ItemEvent.SELECTED) {
                    selectedOption = 'F';
                    update();
                }
            }
        });
        this.add(new JLabel("Choose option F")
        new GridBagConstraints(12110.00.0
        , GridBagConstraints.WEST, GridBagConstraints.BOTH
        new Insets(0000)00));
    }
    
    public void update() {
        setNextButtonEnabled((selectedOption == 'A'|| (selectedOption == 'B') );
        setFinishButtonEnabled(selectedOption == 'F');
        setBackButtonEnabled(false)// there is no way back
    }
    
    public void next() {
        if (selectedOption == 'A') {
            switchPanel(DynamicJWizard.PANEL_OPTION_A);
        else if (selectedOption == 'B') {
            switchPanel(DynamicJWizard.PANEL_OPTION_B);
        }
    }
    public void back() {
    }
}

class OptionWizardPanel extends LabelWizardPanel {
    public OptionWizardPanel(JWizardComponents wizardComponents, String option) {
        super(wizardComponents, "Option " + option + " was choosed");
        setPanelTitle("Option " + option + " panel");
    }
    public void next() {
        switchPanel(DynamicJWizard.PANEL_LAST);
    }
    public void back() {
        switchPanel(DynamicJWizard.PANEL_CHOOSER);
    }
}

class LastWizardPanel extends LabelWizardPanel {
    public LastWizardPanel(JWizardComponents wizardComponents) {
        super(wizardComponents, "Last panel, you can finish now");
        setPanelTitle("Last simple static panel");
    }
}

           
         
  














JWizardComponent.zip( 37 k)
Related examples in the same category
1.Swing Wizard component from yuvraj_sawant(at)persistent.co.in
2.Swing Wizard component with source code
3.Wizard Dialog with LogoWizard Dialog with Logo
4.Simple Dynamic Logo WizardSimple Dynamic Logo Wizard
5.Simple Modal Logo WizardSimple Modal Logo Wizard
6.Simple Dynamic WizardSimple Dynamic Wizard
7.Simple Wizard
8.A dialog that presents the user with a sequence of steps for completing a task.
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.