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:
- java.lang.*
- java.io.*
- java.util.*
- javax.microedition.io.*
- javax.microedition.ui.*
- javax.microedition.rms.*
- javax.microedition.midlet.*
To create a new class for an MTJ project, you must have an MTJ project
created in your workspace.
Creating a Java class
- In the Package Explorer view, highlight the desired
MTJ project.
- In the menu bar, select File
-> New -> Class.
The New Java Class window opens.
- 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.

- 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.
- Instead of defining the package, you can define an
enclosing type for the java class by checking the box next to Enclosing
type and typing in or browsing for the desired enclosing type.
- In the Name
field, enter a name for the new class.
- In the Modifiers field, you can select one or more
of the following access modifiers for the new class:
- Select public
or default
The private and protected
options are only available if you have specified the enclosing type.
- Select abstract
or final.
The static option is only
available if you have specified the enclosing type.
- 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.
- In the Interfaces
field, if you want to add interfaces that the new class implements, click
Add and choose the interfaces.
- 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:
- public static
void main(String [] args)
This adds a main method stub to the new class.
If you are creating a MIDlet, do not create a main method.
- Constructors
from superclass
This copies the constructors from the new class' superclass and
adds the stubs to the new class.
- Inherited abstract
methods
This adds to the new class any abstract methods from superclasses.
It also adds any methods from the interfaces that need to be implemented.
- 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.
- 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