Java/Swing  Step-by-Step Guide

Tutorial 1

Simple JFrame-based Java(Swing) Application


GOAL: To gain understanding of the GUI API and basic Java (Swing) JFrame PREREQUISITES: none

Creating the Dialog Window
  1. Open NetBeans.org IDE
  2. Click the menu item File >> New Project...
  3. In the 'Choose Project' step, select
    1. Categories: General
    2. Projects: Java Application


  4. Figure 1.1 - New Project, 'Choose Project' step
  • In the 'Name and Location' step, select a Name and Location for the application. (We will name ours Tutorial inside a project created folder).
    1. Make sure that the 'Create Main Class' checkbox is UNchecked, as depicted in Figure 1.2, below.

    Figure 1.2 - New Project, 'Name and Location' step
  • Left-Mouse-Button click on the small box with the the '+' in it, to the left of the Source Packages folder, to open up the folder.
  • Right-Mouse-Button click on the <default package>, and then select New >> Java Package, as in Figure 1.3, below

    Figure 1.3 - Creating a new Java Package
  • In the New Java Package dialog, pick a name for your package.  We'll name ours CCSC.  Click 'Finish' to return to the main window of the IDE
     


    Figure 1.4 - Creating a new Java Package
  • Right-Mouse-Buttton click on the project (the bold-faced Tutorial), in the Projects window.  If the Projects window isn't visible, then use the Window >> Projects menu item to make it visible.  Select New >> JFrame Form...


      Figure 1.5 - Adding a new JFrame
    1. In the New JFrame Form dialog
      1. Set Class Name: to be SwingExampleFrame
      2. Left-Mouse-Button click on Package, and select CCSC
      3. Left-Mouse-Button click on Finish

    Figure 1.6 - Adding a new JFrame
  • In the window that contains a picture of an empty application, Left-Mouse-Button single-click on the form (the empty application), then , in the Properties window (to the left - if it's not visible, then use Window >> Properties to reveal it), scroll down to title.  Set this to Swing Tutorial.
  • In the main window, click
    1. Build >> Build Main Project
    2. Run >> Run Main Project to run
    3. In the Run Project dialog, click on CCSC.SwingExampleFrame to set the main class (the start-up object), then click OK.

  • Figure 1.7 - Selecting the main class

     

     


    » Written by William Frankhouser (wjf2@washington.edu)
    » Adapted by Michael Panitz.
    » Advised by Kelvin Sung (ksung@washington.edu) as part of the project sponsored by the National Science Foundation under Grant No. 0442420. Any opinions, findings, and conclusions or recommendations expressed in this material are those of the author(s) and do not necessarily reflect the views of the National Science Foundation.
    » Produced in the "Essential Concepts for Building Interactive Computer Graphics Applications", A.K. Peters, Ltd.