A survey using a wizard : Wizard « SWT JFace Eclipse « Java

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. JDK 6
25. JNDI LDAP
26. JPA
27. JSP
28. JSTL
29. Language Basics
30. Network Protocol
31. PDF RTF
32. Reflection
33. Regular Expressions
34. Scripting
35. Security
36. Servlets
37. Spring
38. Swing Components
39. Swing JFC
40. SWT JFace Eclipse
41. Threads
42. Tiny Application
43. Velocity
44. Web Services SOA
45. XML
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java » SWT JFace Eclipse » WizardScreenshots 
A survey using a wizard
A survey using a wizard

import org.eclipse.jface.wizard.IWizardPage;
import org.eclipse.jface.wizard.Wizard;
import org.eclipse.jface.wizard.WizardDialog;
import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;

/**
 * This class displays a survey using a wizard
 */
public class Survey {
  /**
   * Runs the application
   */
  public void run() {
    Display display = new Display();

    // Create the parent shell for the dialog, but don't show it
    Shell shell = new Shell(display);

    // Create the dialog
    WizardDialog dlg = new WizardDialog(shell, new SurveyWizard());
    dlg.open();

    // Dispose the display
    display.dispose();
  }

  /**
   * The application entry point
   
   @param args
   *            the command line arguments
   */
  public static void main(String[] args) {
    new Survey().run();
  }
}

/**
 * This class shows a satisfaction survey
 */
class SurveyWizard extends Wizard {
  public SurveyWizard() {
    // Add the pages
    addPage(new ComplaintsPage());
    addPage(new MoreInformationPage());
    addPage(new ThanksPage());
  }

  /**
   * Called when user clicks Finish
   
   @return boolean
   */
  public boolean performFinish() {
    // Dismiss the wizard
    return true;
  }
}


/**
 * This class determines if the user has complaints. If not, it jumps to the last
 * page of the wizard
 */
class ComplaintsPage extends WizardPage {
  private Button yes;
  private Button no;

  /**
   * ComplaintsPage constructor
   */
  public ComplaintsPage() {
    super("Complaints");
  }

  /**
   * Creates the page controls
   */
  public void createControl(Composite parent) {
    Composite composite = new Composite(parent, SWT.NONE);
    composite.setLayout(new GridLayout(2true));

    new Label(composite, SWT.LEFT).setText("Do you have complaints?");
    Composite yesNo = new Composite(composite, SWT.NONE);
    yesNo.setLayout(new FillLayout(SWT.VERTICAL));

    yes = new Button(yesNo, SWT.RADIO);
    yes.setText("Yes");

    no = new Button(yesNo, SWT.RADIO);
    no.setText("No");

    setControl(composite);
  }

  public IWizardPage getNextPage() {
    // If they have complaints, go to the normal next page
    if (yes.getSelection()) { return super.getNextPage()}
    // No complaints? Short-circuit the rest of the pages
    return getWizard().getPage("Thanks");
  }
}
/**
 * This page gathers more information about the complaint
 */
class MoreInformationPage extends WizardPage {
  /**
   * MoreInformationPage constructor
   */
  public MoreInformationPage() {
    super("More Info");
  }

  /**
   * Creates the controls for this page
   */
  public void createControl(Composite parent) {
    Composite composite = new Composite(parent, SWT.NONE);
    composite.setLayout(new GridLayout(1false));

    new Label(composite, SWT.LEFT).setText("Please enter your complaints");
    Text text = new Text(composite, SWT.MULTI | SWT.BORDER | SWT.V_SCROLL);
    text.setLayoutData(new GridData(GridData.FILL_BOTH));

    setControl(composite);
  }
}

/**
 * This page thanks the user for taking the survey
 */
class ThanksPage extends WizardPage {
  /**
   * ThanksPage constructor
   */
  public ThanksPage() {
    super("Thanks");
  }

  /**
   * Creates the controls for this page
   */
  public void createControl(Composite parent) {
    Label label = new Label(parent, SWT.CENTER);
    label.setText("Thanks!");
    setControl(label);
  }
}

           
       
Related examples in the same category
1. Wizard DemoWizard Demo
2. An address book, using a wizard to add a new entryAn address book, using a wizard to add a new entry
3. SWT Wizard Composite
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.