Search
Feedback
Running Tutorial Examples in NetBeans IDE

The examples in the Swing Tutorial are also provided as NetBeans projects that are ready to be opened and run inside of NetBeans IDE, a free integrated development environment that you can use to simplify application development.

This page provides information on the following tasks:

- Downloading, Installing, and Launching NetBeans IDE
- Opening a Project for an Example
- Compiling and Running a Project

## Downloading, Installing, and Launching NetBeans IDE

The easiest way to get NetBeans IDE is to download the NetBeans IDE installer for your operating system from the NetBeans download page.

You can then run the installer and complete a short sequence of steps in the installation wizard to set up the IDE. You can find more details on the installation process from the installation instructions that are linked to from the download page.

You can then launch the IDE in one of the following ways:

- On Microsoft Windows systems, you can use the NetBeans IDE item in the Start menu.
- On Solaris OS and Linux systems, execute the IDE launcher script by navigating to the IDE's bin directory and typing ./netbeans.
- On Mac OS X systems, click the NetBeans IDE application icon.

## Opening a Project for an Example

Opening a project in NetBeans IDE consists of the following steps:

- Download a tutorial example or the whole set of examples. Individual examples are available in the Example as NetBeans IDE Project column on the various example index pages (such as the components index page). You can download all of the examples as part of one of the bundles listed on the tutorial download page.
- If you have downloaded an individual project, unzip the project on your system. If you have downloaded a zip file of the the whole tutorial or a zip file of all of the examples, unzip that file.
- In NetBeans IDE, choose File > Open Project. In the file chooser, select the project and click Open Project Folder.

  NetBeans project folders are marked with the icon.

Once opened, the project appears in the IDE's Projects window. Expand the nodes of the project to show the project's structure. The project includes the following main subnodes:

- Source Packages. Contains nodes representing Java packages for your source files. Expand these nodes to access the `.java` source files for the project.
- Libraries. Contains nodes representing the libraries on which the application depends. For the examples in the Swing Tutorial, just the JDK is listed here.

To open a file, double-click the file's node in the Projects window. When opened, a file is displayed in the Source Editor, to the right of the Projects window.

The Projects window represents the "logical" structure of the project, which does not correspond to the layout of the files on your system. This logical structure highlights the parts the project that you need to access most often. The Projects window does not display compiled `.class` files. If you want to see how the entire project is physically represented on disk, open the Files window.

## Compiling and Running a Project

To compile your whole project, right-click the project's node in the Projects window and choose Build Project.

The Output window opens and displays output on the compilation progress.

If the build output concludes with the statement `BUILD FAILED`, you probably have a syntax error in your code. Errors are reported in the Output window as hyperlinked text. You double-click such a hyperlink to navigate to the source of an error. You can then fix the error and once again choose Build Project.

When you build the project, bytecode `.class` files are generated. You can see where the new files are generated by opening the Files window and expanding the folder for the project.

To run your project, right-click the project's node in the Projects window and choose Run Project.

> Note: You can also use the Build Main Project and Run Main Project commands in the main menu. However, these commands work only work on the project that is currently designated as the "main" project. You can make a project the main project by right-clicking its node in the Projects window and choosing Set Main Project.

For more tips on using NetBeans IDE with the Java Tutorial, see Continuing the Tutorial with the NetBeans IDE.