Creating Packages and Files in the Project


Once the project is set up, you can create packages and files from the Projects window or the Files window. Right-click the node for the package or folder where you would like to add a class or package and choose New | File/Folder (Ctrl-N) to open the New File wizard. Or you can directly choose one of the templates below the File/Folder menu item.

To create a Java package:

  1. Right-click the Source Packages node in the Projects window and choose New | Java Package.

    If Java Package is not one of the choices in the New submenu, choose New | File/Folder instead. In the New File wizard, select the Java Classes node, select Java Package, and click Next.

  2. In the Package Name field of the wizard, type the name of the package, delimiting levels of the package with periods (for example, com.mydomain.myproject), and then click Finish.

When creating subpackages, you can save yourself a few keystrokes by choosing New | Java Package from a package node. The base package name is already filled in for you, so you just need to add the last part of the new package name.

You can also enter a new package when using the New File wizard to create a new Java class.


To create a file:

  1. Right-click the Source Packages node in the Projects window and choose New | File/Folder (Ctrl-N).

  2. In the New File wizard, browse the templates available, select the one you want, and click Finish.

You can also select a template straight from the New submenu, where a short list of templates commonly used for the selected project type is displayed. The list of files that are available there is updated to reflect the templates you commonly use.


See Chapter 5 for more information on editing Java files.

File Templates

File creation in the IDE begins with templates. The templates that are available depend on the features you have installed in the IDE. Following are some of the available categories.

Java Classes

Several templates that provide skeleton code for basic types of classes, such as main classes, interfaces, and exceptions.

Java GUI Forms

Swing and AWT templates for developing visual desktop applications. When you create a file from one of these templates, the Form Editor opens, which enables you to build forms visually (dragging and dropping components from a palette to the Form Designer, changing properties in the Component Inspector, and so on).

JavaBeans Objects

Various templates for classes that adhere to the JavaBeans component architecture. Included are templates for a bean with a skeleton getter and setter, BeanInfo classes, a property editor, and a customizer class.

JUnit

Templates that provide skeleton code for unit tests of Java classes.

Web Services

Templates for web service clients and WSDL files.

XML

XML-related templates for XML documents, XML schemata, DTDs, XSL stylesheets, and cascading stylesheets.

Ant Build Scripts

Provides a simple template for a simple skeleton for an Ant script and a template for a custom Ant task with detailed comments. These scripts could be useful if you want to extend the default behavior of the IDE's project system but are not necessary if the IDE's project system already provides all the features you need.

Web

Provides templates that are useful for web applications, including JSP files, HTML files, tag library files, and tag library descriptors (TLD files). Also provides Java class templates for servlets, filters, tag handlers, and web application listeners. See Chapter 8 for more information on working with these types of files.

Other

Provides templates for HTML, properties, and empty files.

Starting with a Blank File

If you want to start with a completely blank file without a predetermined file extension, you can use the Other | Empty File template. If you give the file an extension that the IDE recognizes, the IDE will treat it as that type of file in the editor (complete with syntax highlighting and other Source Editor features).



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