First NetBeans IDE Project


Once you have started the IDE, you are presented with a "welcome" window and some other empty windows. To help get you started, this section provides a quick run-through of setting up, compiling, and running a "Hello World" project.

To set up the project:

1.

Choose File | New Project (or press Ctrl-Shift-N).

2.

In the New Project wizard, expand the General node, select Java Application, and click Next (as shown in Figure 1-1).

Figure 1-1. New Project wizard, Choose Project page


The Java Application template sets up a basic project and includes a main class.

3.

In the Name and Location page of the wizard (as shown in Figure 1-2), type HelloWorld as the project name.

Figure 1-2. New Project wizard, Name and Location page


4.

In the Create Main Class field, change helloworld.Main to com.mydomain.myproject.HelloWorld. (When you enter a fully qualified class name in this field, the IDE generates directories for each level of the package structure.)

5.

Click Finish.

Once you have finished the wizard, the IDE will run a scan of the classpath that has been set for the project to enable features such as code completion to work.

The following windows are then populated:

  • The Projects window, which provides access to your sources, any tests you might have, and your classpath (represented through the Libraries and Test Libraries nodes). See Figure 1-3.

    Figure 1-3. Projects window with nodes for the HelloWorld project

  • The Navigator window, which provides an easy way for you to view and access members of the currently selected class. It also makes it easy to browse the inheritance tree of a class.

  • The Source Editor, where a tab for the HelloWorld source file opens. See Figure 1-4.

    Figure 1-4. Source Editor with HelloWorld.java open

To modify, build, and run the project:

1.

In the Source Editor, click within the main method at the end of the line that reads // TODO code application logic here.

2.

Press the Enter key and then type the following line:

     System.out.println("Hello World!");


3.

Press Ctrl-S to save the application.

4.

Press F11 (or choose Build | Build Main Project) to compile and package the application. This command triggers an Ant script that the IDE has generated and will maintain for the project.

The Output window opens and displays the output from the Ant script as it runs through its targets. See Figure 1-5.

Figure 1-5. Output window showing successful building of the HelloWorld project


5.

Press F6 (or choose Run | Run Main Project) to run the project.

The Output window should display a combination of Ant output and the "Hello World!" message from your application. See Figure 1-6.

Figure 1-6. Output window showing the successful running of the HelloWorld project


With that, you have created and run an application in the IDE. You can now move on to the next chapter to get a broader overview of the IDE, or you can skip ahead to Chapter 3 to cut straight to the details of creating and customizing projects.

Trying Out NetBeans IDE with Sample Code

If you want to check out the features of NetBeans IDE on working code without touching your existing projects, or if you just want to see what a working project looks like in the IDE, you can open one of the sample projects that come with the IDE.

When you create a sample project, the sample code is copied into a directory of your choosing, and all necessary project metadata is generated.

To create a sample project:

1.

Choose File | New Project.

2.

In the New Project wizard, expand the Samples folder; choose a template from one of the categories; and click Next.

The General category contains visual desktop applications.

The Web category contains several examples designed to run on the Tomcat server.

The NetBeans Plug-in Modules category contains an example of how you can create create a project to add features to the IDE itself.

The BluePrints Solutions category contains examples of useful design patterns for Java EE applications. These examples accompany the BluePrints Solutions Catalog, which is available from the Help menu and which provides documentation for these design patterns in a problem/solution format.

If you have the Mobility Pack installed, a Mobility category also appears and includes samples from the Java ME Wireless Toolkit.

3.

On the Name and Location page of the wizard, check the generated values for the name and location of the project and change them, if you wish. Then click Finish.

Once you have created a new sample project, you can view its source code and project structure and then build and run that application within the IDE.




NetBeans IDE Field Guide(c) Developing Desktop, Web, Enterprise, and Mobile Applications
NetBeans IDE Field Guide(c) Developing Desktop, Web, Enterprise, and Mobile Applications
ISBN: N/A
EAN: N/A
Year: 2004
Pages: 279

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net