Creating new classes

The creation of Java classes is handled with the New Java Class wizard. With this wizard, you can set details for the Java class. This includes the class name and package. You can also select a base class for the new class or an interface to be implemented, and you can add your own methods and variables to the new class.
When creating new Java classes for MTJ projects, you need to conform to the project-specific definitions. In other words, in case of a MIDP project, you must use java classes that are defined in MIDP platform specifications. The following lists the Java classes for MIDP platform and the CDLC configuration:

To create a new class for an MTJ project, you must have an MTJ project created in your workspace.

Creating a Java class

  1. In the Package Explorer view, highlight the desired MTJ project.
  2. In the menu bar, select File -> New -> Class.
    The New Java Class window opens.
  3. In the New Java Class window, in the the Source folder field, define the source folder for the new java class.
    The system chooses the project folder as the default source folder. If you want the source folder to be something other than the project folder, select Browse and choose a different source folder.

  4. In the Package field, enter the name of the package folder or select Browse and choose the package folder.
    Note
    : If you have chosen the default package for your project, it is not recommended that you use that as the source folder for your java class.
  5. In the Name field, enter a name for the new class.
  6. In the Modifiers field, you can select one or more of the following access modifiers for the new class:
  7. In the Superclass field, if the superclass that the system proposes is not the one you want, enter the desired superclass or select Browse and choose the correct class.
    The system proposes either the type that was selected when the wizard was chosen or <java.lang.object>.
    If you are creating a MIDlet, the superclass must be javax.microedition.midlet.MIDlet.
  8. In the Interfaces field, if you want to add interfaces that the new class implements, click Add and choose the interfaces.
  9. In the Which method stubs would you like to create field, you can define one or more of the following method stubs to be created in the new class:
  10. In the Do you want to add comments as configured in the properties of the current project? field, if you want to add comments, check the box next to Generate comments.
  11. Click Finish.
    The .java file appears in the file structure of the project and the new class is displayed in the editor.


Mobile Tools for the Java Platform


Creating your first MIDlet


Editors