# Creating a Bean Project

JavaBeansTM are reusable software components that you write once and can use anywhere. To create JavaBeans that can be imported into the GUI builder palette, you will need to create a beans project (or projects) that contains the individual beans.

A JavaBeans project can contain a single bean or multiple beans. When a bean project is built, a single JAR file is generated which contains all of the beans in the bean project. To reduce the time of loading the JAR file in the GUI builder, unrelated beans should be created in separate bean projects.

The files you can create using the Create Project wizard include:

- BeanName`.java` This is the bean source file.
- BeanName`BeanInfo.java` The BeanInfo file provides explicit information about the methods, properties, events, and icons of the bean. If a BeanInfo file is not specified, the Introspector will use the Core Reflection API's to analyze the bean class and its superclasses to determine the bean's information.
- BeanName`Customizer.java` The Customizer is a customized property sheet for the bean. It allows the programmer of the bean to provide the user interface for editing the properties of the bean.

To create a bean project:

1. Click the Projects button on the Java WorkShop main toolbar.
2. Double-click on the portfolio name where you want the bean project to be placed.
   You can create a bean project in any portfolio for which you have write permission.
3. In the project manager, choose File -> New -> Project.
   The Create Project wizard is displayed.
4. Type the name of your project in the box where `untitled` appears.
   Make sure you are consistent in the use of capitalization in project and file names; Java WorkShop is case-sensitive.
5. Click the Beans radio button.
6. Click Next.
7. Type the project's package name, using the `sun.jws.browse` format, in the Package name box.
   Completing this text box is necessary for a beans project.
8. In the Root directory box, type the directory where the package's class hierarchy is located.
   Completing this text box is optional.
9. If you want to keep the source files in a directory other than the default listed in the box, replace the project storage default directory with the directory you want to use.
10. Decide if you have existing files you want to add to the project.
    - If there are no existing files to add, click Next; then, follow the steps in Adding a Bean.
    - If you want to add existing files to the beans project, complete the following steps:
      1. Click Yes.
      2. Click Next.
      3. Add files to the project by either clicking the All in Directory button; or clicking Add, and using the file chooser to select each file you want to add.
         If you add a project's `.java` file, and the `BeanInfo.java` and `Customizer.java` files for the bean exist in the same location, they are automatically added to the new bean project.
      4. Click Next.
      5. Follow the steps below in Adding a Bean.

# Adding a Bean

This is the part where you actually create the bean that will go in your project.

1. Type the name of your bean into the Bean Name box.
   The name of the bean can be one of the following:
   - A short file name, for example, `Jelly`
   - A full path name, for example, `my-install-dir\BeanBag\Jelly`
2. Decide if you want the bean to have an accompanying BeanInfo file and/or a Customizer file, and select the appropriate checkbox(es).
   You can select both the BeanInfo check box and Customizer check box, or just one, depending on your component plan.
   - By selecting the BeanInfo file checkbox, Java WorkShop creates a default BeanInfo source file for the bean that you can modify or extend.
   - By selecting the Customizer file checkbox, Java WorkShop creates a default Customizer source file that you can modify.
3. Click Create New Java Bean.
   Java WorkShop automatically adds the `.java` suffix to each bean file name, and adds the file to the Java Files list.
4. Decide if you want to add another bean to this project.
   - If you want to add another bean, repeat steps 1 - 3 above.
   - If you do not want to add another bean, click Finish.

   Java WorkShop creates source templates for each non-existing file in the New Bean Card list. The source editor shows the source code for the project's first file. And, the project is added to the project manager.

JavaBeans are packaged and distributed within JAR files. After successfully compiling and building a bean project, a single JAR file is created for the project containing all of the classes and resources needed by the beans in the project.

When the project is built, Java WorkShop adds the following to the JAR file:

- All class files. If the class file is a bean, it is identified as a bean in the manifest of the JAR file.
- All project source files except the `.java` or `.gui` files.
- If a source file is a JAR file, the JAR file is expanded and its files are added to the project JAR file.

Although a JAR file can contain more than one bean, having separate JAR files for unrelated beans is recommended.

You can change the default attribute values for the project by choosing Edit -> Project. See Editing Project Attributes for information.

See also:

  Beans In Java WorkShop
  Importing Components (includes importing a JAR File)
  Creating an Applet Project
  Creating a Standalone Program Project
  Creating a Java Package Project
  Using the Create Project Wizard