As we have discussed before we will discuss the new APIs of MIDP 2.0 is this section. The following are the four new packages that have been added in MIDP 2.0: Public Key Package: ü javax.microedition.pki Sound and Tone Media Packages: ü javax.microedition.media ü javax.microedition.media.control Gaming Package: ü javax.microedition.lcdui.game We will now discuss the above listed packages in detail. We will not discuss the javax.microedition.lcdui.game package here as the gaming package has been discussed in the next chapter in great detail. javax.microedition.pki The certificates are needed to authenticate information for securing the connections. The Certificate interface in the javax.microedition.pki package provides to the application information about the origin and type of the certificate. The class CertificateException provides us the information about failures that have occurred while verifying or using the certificates. The MIDP 2.0 specification has made it compulsory for device manufacturers to support X.509 certificates in there javax.microedition.pki package implementation. The device may also support other types of certificates but there support is optional. It has also been made compulsory for the device to support RSA signature algorithm with SHA-1 hash function while implementing the javax.microedition.pki package. public interface Certificate What is it? o The Certificate interface is common to all certificates. The Certificate interface has features such as : · Issuer · Dates of valid use · Serial number · Signing algorithm name · Subject · Type · Version · Serial number. This interface provides the getter methods for the above discussed features. o Methods · public java.lang.String getIssuer() This method returns the name of issuer of this Certificate. This value should not be null for a valid certificate. · public long getNotAfter() This method returns the time (in milliseconds) after which this Certificate is not valid (i.e. the expiry date). The value for Long.MAX_VALUE is returned if the certificate does not have a time based restriction on its validity. The value returned is always positive. · public long getNotBefore() This method returns the time (in milliseconds) before which this Certificate is not valid. The value 0 is returned if the certificate does not have a time based restriction on its validity. The value returned is always positive. · public java.lang.String getSerialNumber() This method returns a string containing the serial number in a user friendly form. This method returns a null value if there is no serial number in the certificate. · public java.lang.String getSigAlgName() This getter method returns the name of algorithm that is used to sign the certificate. This value being very important for reading the certificate can not be null. · public java.lang.String getSubject() This method gets the name of the subject of this Certificate. The value being important can not be null. · public java.lang.String getType() This method returns the type of the Certificate. The value being important can not be null. For a X.509 certificate this method will return ‘X.509’ · public java.lang.String getVersion() This method returns the version number of the Certificate. The value being important can not be null. For a X.509 certificate this method will return ‘2’. public class CertificateException extends java.io.IOException What is it? o The CertificateException is thrown when a problem is encountered while a Certificate is being used. In case multiple errors are found while processing a Certificate the most significant error should be reported in the CertificateException. o Constructors · public CertificateException(Certificate certificate, byte status) · public CertificateException(String message, Certificate certificate,byte status) o Fields · public static final byte BAD_EXTENSIONS This field indicates that a certificate has unrecognized critical extensions. Value: 1 · public static final byte BROKEN_CHAIN This field indicates that a certificate in a chain was not issued by the next authority in the chain. Value: 11. · public static final byte CERTIFICATE_CHAIN_TOO_LONG This field indicates that the server certificate chain exceeds the length allowed by an issuer’s policy. Value: 2. · public static final byte EXPIRED This field indicates that a certificate is expired. Value: 3. · public static final byte INAPPROPRIATE_KEY_USAGE This field indicates that a certificate public key has been used in way deemed inappropriate by the issuer. Value: 10. · public static final byte MISSING_SIGNATURE This field indicates that a certificate public key has been used in way deemed inappropriate by the issuer. Value: 10. · public static final byte NOT_YET_VALID This field indicates that a certificate is not yet valid. Value: 6. · public static final byte ROOT_CA_EXPIRED This field indicates that the root CA’s public key is expired. Value: 12. · public static final byte SITENAME_MISMATCH This field indicates that a certificate does not contain the correct site name. Value: 7. · public static final byte UNAUTHORIZED_INTERMEDIATE_CA This field indicates that an intermediate certificate in the chain does not have the authority to be a intermediate CA. Value: 4. · public static final byte UNRECOGNIZED_ISSUER This field indicates that a certificate was issued by an unrecognized entity. Value: 8. · public static final byte UNSUPPORTED_PUBLIC_KEY_TYPE This field indicates that the type of the public key in a certificate is not supported by the device. Value: 13. · public static final byte UNSUPPORTED_SIGALG This field indicates that a certificate was signed using an unsupported algorithm. Value: 9. · public static final byte VERIFICATION_FAILED This field indicates that a certificate failed verification. Value: 14. o Methods · public Certificate getCertificate() This method returns the Certificate was the cause of failure. · public byte getReason() This method returns the reason code for the failure. The reason codes have been discussed in detail above. javax.microedition.media One of the key problems with the MIDP 1.0 was that it was lacking the in built support of multimedia APIs. To solve this problem MIDP 2.0 has provisioned for a Media API. But Sun had also introduced Mobile Media API (JSR 135). To solve the problem of interoperability the MIDP 2.0 Media API is directly compatible with Mobile Media API (JSR-135) specification. The compatibility of MIDP 2.0 API with the Mobile Media API is a step in the right direction and makes it easier for the developers to scale up there application and use Mobile Media API in devices which support it. The MIDP 2.0 Media APIs give us a good set of tools to use multimedia in our applications. This API gives us the player and control functionality for use in our code. Although the number of controls available to us a very few when compared to Mobile Media API but at least it is enough for basic games. 1. Wave audio files: audio/x-wav 2. AU audio files: audio/basic 3. MP3 audio files: audio/mpeg 4. MIDI files: audio/midi 5. Tone sequences: audio/x-tone-seq public interface Control What is it? o An object which implements Control object is used to control some sort of media processing functions. It is normal for one object to implement multiple controls. An example of type of Control is VolumeControl which is used to control the volume of the player. public interface Controllable What is it? o The Controllable interface provides us with the tool for obtaining the Controls from an object like a Player. Controllable interface provides methods to get all the supported Controls in an object or to obtain a specific Control based on its class name. o Methods
This method returns an object that implements the control or null value.
This method returns to us the collection of Control objects. public final class Manager What is it?
o Fields
This field refers to the locator to create a tone player to play back tone sequences. o Methods
This method returns a new Player from the specified inputstream.
throws IOException, MediaException This method returns a new Player from the specified media locator string.
This method returns the list of supported content types for the given protocol.
This method returns the list of supported protocols for the given content type.
throws MediaException This method plays back a tone as specified by a note and its duration. Notes range from 0 to 127 inclusive. public class MediaException What is it?
o Constructors
public interface Player extends Controllable What is it?
The following are the states in which a Player can be:
o Fields
This field indicates that the Player is closed. Value: 0
This field indicates that the Player has acquired all the resources to begin playing. Value: 300
This field indicates that it has acquired the required information but not the resources to function. Value: 200
This field indicates that the Player has already started. Value: 400
This field indicates that the requested time is unknown. Value: -1
This field indicating that the Player has not acquired the required information and resources to function properly. Value: 100 o Methods
This method adds a player listener for this player.
This method closes the Player and releases its resources.
This method releases the scarce/exclusive resources like the audio device acquired by the Player.
This method returns the content type being played back by this Player.
This method returns the duration in microseconds or TIME_UNKNOWN.
This method returns the current media time in microseconds or TIME_UNKNOWN.
This method returns the Player’s current state.
This method makes the player acquire the scarce and exclusive resources and process as much data as necessary to reduce the start latency.
This method constructs portions of the Player without acquiring the scarce and exclusive resources.
This method removes a player listener for this player.
This method sets the number of times the Player should loop and play the content.
This method returns the actual media time set in microseconds
This method starts the Player as soon as possible for it to start. If the Player was previously stopped by calling stop, this method will resume playback from where it was previously stopped.
This method stops the Player. This method will pause the playback at the current media time. public interface PlayerListener What is it?
o Fields
This field is posted when a Player is closed.
This field is posted when the system or another higher priority application has released an exclusive device which is now available to the Player.
This field is posted when the system or another higher priority application has temporarily taken control of an exclusive device which was previously available to the Player.
This field is posted when the duration of a Player is updated. This happens for those media types where the duration cannot be derived ahead of time.
This field is posted when a Player has reached the end of the media.
This field is posted when an error has occurred.
This field is posted when a Player is started.
This field is posted when a Player stops in response to the stop method call.
This field is posted when the volume of an audio device is changed. o Method
The method playerUpdate(Player player, String event,Object eventData) is called to deliver an event to a registered listener when an event for the specified Player is observed. javax.microedition.media.control The javax.microedition.media.control package defines the specific types of controls that can be used with a Player.public interface ToneControl extends javax.microedition.media.Control o Programmer specified monotonic tone sequences can be generated with the help of this interface o Fields · public static final byte BLOCK_END This field defines an ending point for a block. Value: -6 · public static final byte BLOCK_START This field defines a starting point for a block. Value: -5 · public static final byte C4 This field stands for the Middle C. Value: 60 · public static final byte PLAY_BLOCK This field plays a defined block. Value: -7 · public static final byte REPEAT This field stands for the REPEAT event tag. Value: -9 · public static final byte RESOLUTION This field stands for the RESOLUTION event tag. Value: -4 · public static final byte SET_VOLUME This field stands for the SET_VOLUME event tag. Value: -8 · public static final byte SILENCE This field stands for the Silence. Value: -1 · public static final byte TEMPO This field stands for the TEMPO event tag. Value: -3 · public static final byte VERSION This field stands for the VERSION attribute tag. Value: -2 o Methods · public void setSequence(byte[] sequence) This method sets the tone sequence that has to be played. public interface VolumeControl What is it? o The interface VolumeControl provides us methods for manipulating the audio volume of a Player. o Methods · public int getLevel() This method returns the current volume level or -1. · public boolean isMuted() This method returns the mute state. · public int setLevel(int level) This method returns the level that was actually set by this method. · public void set Mute(boolean mute) This method sets the mute status of the Player associated with this VolumeControl. javax.microedition.io · HTTP Networking javax.microedition.io.HttpConnection is used for working with HTTP connections. MIDP 2.0 enabled device must support the HTTP 1.1 servers and services.
· Secure Connections javax.microedition.io.HttpsConnection is used for working with secure connections.
· Low Level Networking Support The MIDP 2.0 specification also supports the TCP/IP sockets and the UDP/IP datagrams.
· Push Applications Support MIDP 2.0 includes the support for PushRegistry. The PushRegistry maintains a list of inbound connections. Whenever the application management software receives a notification for a MIDlet that has registered itself for inbound notifications the particular MIDlet is started by the application management software. This feature can be used for chat, news and ERP applications.
· Serial Port Connections We can access the local serial port in form of a stream connection with the help of the interface javax.microedition.io.CommConnection.
The networking support in this package is based on the Generic Connection Framework provided to us in the Connected, Limited Device Configuration. public interface CommConnection What is it? o A logical serial port connection is defined by the interface javax.microedition.io.CommConnection. A logical serial port may be a RS – 232 port or an IrDA IRCOMM port. One serial port can be used by only one application at a particular time. What is a logical serial port? A logical connection through which bytes are transferring serially can be termed as a logical serial port. o Methods · public int getBaudRate() This method returns the baud rate of the connection. · public int setBaudRate(int baudrate) This method is used for setting the baud rate for a serial port connection. This method returns the previous baud rate of the connection. public class Connector What is it? Connector is a factory class for creating new Connection objects. This class dynamically returns the appropriate type on Connection based upon the value of the arguments in its open method. o Fields · public static final int READ The field for the access mode READ. Value: 1 · public static final int READ_WRITE READ_WRITE is the field for the access mode READ_WRITE. Value: 3 · public static final int WRITE WRITE is the field for the access mode WRITE. Value: 2 o Methods · public static javax.microedition.io.Connection open(String name) This method returns a new Connection object. · public static javax.microedition.io.Connection open(String name, int mode) This method returns a new Connection object. · public static javax.microedition.io.Connection open(String name, int mode, boolean timeouts) This method returns a new Connection object · public static java.io.DataInputStream openDataInputStream(String name) This method returns a DataInputStream. · public static java.io.DataOutputStream openDataOutputStream(String name) This method returns a DataOutputStream. · public static java.io.InputStream openInputStream(String name) This method returns an InputStream. · public static java.io.OutputStream openOutputStream(String name) This method returns an OutputStream. public interface HttpsConnection What is it? HttpsConnection defines the necessary methods and constants to establish a secure network connection. What is HTTPS? HTTPS protocol is the secure version of HTTP protocol. It is a request-response protocol in which the parameters of request must be set before the request is sent. o Methods · public int getPort() This method returns the network port number of the URL for this HttpsConnection. If no port number is passed in the string is passed to Connector.open then the default HTTPS port number (443) is returned. · public SecurityInfo getSecurityInfo() This method returns the security information associated with this open connection. public interface SecureConnection What is it? o SecureConnection interface defines the secure socket stream connection. A CertificateException is thrown if the secure connection cannot be established due to errors related to certificates. o Methods · public SecurityInfo getSecurityInfo() This method returns the security information associated with this open connection. public interface SecurityInfo What is it? o SecurityInfo interface provides us with the methods to access information about a secure network connection. This interface provides the following: · Protocol · Version · Certificate · Cipher suite o Methods · public java.lang.String getCipherSuite() This method returns a String containing the name of the cipher suite in use. · public java.lang.String getProtocolName() This method returns the name of the secure protocol. The following are the return values for the respective connections: · TLS (RFC 2246) /WAP TLS Profile and Tunneling (WAP-219-TLS) Return value: “TLS” · SSL V3 (The SSL Protocol Version 3.0) Return value: “SSL” · WTLS (WAP 199) Return value: “WTLS”. · public java.lang.String getProtocolVersion() This method returns a String containing the version of the protocol. · public javax.microedition.pki.Certificate getServerCertificate() This method returns the Certificate used to establish the secure connection with the server. public interface ServerSocketConnection What is it? o ServerSocketConnection interface defines the server socket stream connection. o Methods · public java.lang.String getLocalAddress() This method returns the local address to which this socket is bound. · public int getLocalPort() This method returns the local port number to which the socket is connected. public interface SocketConnection What is it? o SocketConnection defines the socket stream connection. o Fields
· public static final byte KEEPALIVE · public static final byte LINGER · public static final byte RCVBUF · public static final byte SNDBUF o Methods
This method returns the remote address to which the socket is bound. · public java.lang.String getLocalAddress() This method returns the local address to which the socket is bound. · public int getLocalPort() This method returns the local port number to which this socket is connected. · public int getPort() This method returns the remote port number to which this socket is connected. · public int getSocketOption(byte option) This method returns numeric value for specified option or -1 if the value is not available. · public void setSocketOption(byte option, int value) This method is used for setting a socket option for the connection. public interface UDPDatagramConnection What is it? o UDPDatagramConnection interface defines a datagram connection. This protocol is transaction oriented and the delivery can not be guaranteed. o Methods
This method returns the local address to which the datagram connection is bound. · public int getLocalPort()throws Exception This method returns the local port number to which this datagram connection is connected. public class PushRegistry What is it? This class maintains a list of inbound connections. An application can register for the inbound connections by the following ways: · Entry in the application descriptor file · By calling the registerConnection method When an application is not running, the application management software (AMS) keeps the track for inbound notification requests. When a notification arrives for a MIDlet that has registered itself, AMS will start that MIDlet normally through the startApp method. When the application is running, the application is responsible for all input and output operations associated with the inbound connection. o Methods · public static java.lang.String getFilter(String connection) This method returns a filter string indicating which senders are allowed to cause the MIDlet to be launched. If the connection was not registered by the current MIDlet suite or if the connection argument was containing null this method will return null. · public static java.lang.String getMIDlet(String connection) This method returns class name of the MIDlet to be launched when the new external data is available. If the connection was not registered by the current MIDlet suite or if the connection argument was containing null this method will return null. · public static java.lang.String[] listConnections(boolean available) This method returns array of registered connection strings. · public static long registerAlarm(String midlet, long time) This method returns the time at which the most recent execution of this MIDlet was scheduled to occur. The format is the same as returned by Date.getTime() · public static void registerConnection(String connection, String midlet, Stringfilter) This method register’s a dynamic connection with the application management software (AMS). Once a connection is registered, the dynamic connection acts just like a connection pre-allocated from the descriptor file. · public static boolean unregisterConnection(String connection) This method returns true if the un-registration process was successful or it returns false if the connection was not registered or if the connection argument was null. javax.microedition.lcdui In MIDP 2.0 many new changes have been introduced in javax.microedition.lcdui package. Some classes have been introduced for the first time. All the methods and fields have been given for such classes. Some of the existing classes and interfaces have also been changed. For these classes and interfaces, I have at some places given only the additions made by MIDP 2.0 and at some other places given all the methods or fields as the need arose. For example in case of Alert only the new additions are given while in case of Canvas all the methods are given for a better understanding. I would also recommend you to read the appendix D of this book which contains the short description and a list of all the fields and methods of each and every interface and class in MIDP 1.0. public class Alert What is it The alert class is a kind of screen that shows some data to the user. It waits for a certain period of time before proceeding to the next Displayable. It is basically a sort of simple dialog box that only gives some information. o Fields
DISMISS_COMMAND is a Command that is delivered to a command listener to indicate that the Alert has been dismissed. o Methods · public javax.microedition.lcdui.Gauge getIndicator() This method returns a reference to this Alert's activity indicator. It returns null if there is no indicator in the alert. · public void removeCommand (javax.microedition.lcdui.Command cmd) The important thing to keep in mind while using this method is that calling this method with DISMISS_COMMAND as the parameter has no effect. · public void setIndicator (javax.microedition.lcdui.Gauge indicator) This method sets an activity indicator on this Alert. public abstract class Canvas What is it? This class is the base class for applications that need to handle low-level events and to issue graphics calls for drawing to the display. This class is very useful for graphics programming. o Methods · public int getGameAction(int keyCode) This method returns the game action for this key. It will return 0 if no game action is there for the key.
This method returns height of the displayable area. The value returned by this method can change during the execution of the application due variety of factors. The sizeChanged method has been added in MIDP 2.0 to notify us when the size of the displayable area is changed.
This method returns a key code corresponding to the game action given in the argument.
This method returns a string name for the key specified in the keyCode argument.
This method returns width of the displayable area. The value returned by this method can change during the execution of the application due variety of factors. The sizeChanged method has been added in MIDP 2.0 to notify us when the size of the displayable area is changed.
This method returns true if device supports pointer events.
This method returns true if device supports pointer motion events.
This method returns true if device supports repeat events
This method is called shortly after the Canvas has been removed from the display.
This method returns true if double buffering is there else this method will return false.
This method is called when a key is pressed.
This method is called when a key is released.
This method is called when a key is repeated (held down).
This method is called for rendering the Canvas.
This method is called when the pointer is dragged.
This method is called when the pointer is pressed.
This method is called when the pointer is released.
This method requests a repaint for the entire Canvas.
This method is requests a repaint for the specified region of the Canvas.
This method forces any pending repaint requests to be serviced immediately.
· public void setFullScreenMode(boolean mode) This method provides us with a much desired control over the full screen mode of the Canvas. For setting the full screen mode the argument should be true otherwise it should be false.
The showNotify () method is called immediately prior to this Canvas being made visible on the display.
This method is called when the area of the Canvas which can be used for drawing upon has been changed. This method can be called due to a variety of factors. public interface Choice What is it? This interface defines the characteristics of a user interface component implementing selection from predefined number of choices. o Fields
This field stands for EXCLUSIVE choice. This kind of user interface element has exactly one element selected at one time.
This field stands for IMPLICIT choice. In this kind of user interface element the currently focused element is selected when a Command is initiated.
This field stands for MULTIPLE choices. This kind of user interface element can have an arbitrary number of elements selected at a given time.
This is a new field that has been added in MIDP 2.0. This is kind of a choice having exactly one element selected at one time and only this selected option is displayed until the user performs the particular action that will make all the elements visible. This choice type is not valid type for List class.
This is a new field that has been added in MIDP 2.0. This field indicates that the application has no preference as to wrapping or truncation of text element contents and that the implementation should use its default behavior.
This is a new field that has been added in MIDP 2.0. This field indicates that text element contents should be limited to a single line.
This is a new field that has been added in MIDP 2.0. This field indicates that text element contents should be wrapped to multiple lines if necessary to fit available content space. o Methods
This method deletes all the elements from this Choice.
This method gets the application’s preferred policy for fitting Choice element contents to the available screen space. This method will return one of the 3 options given below: · public static final int TEXT_WRAP_DEFAULT · public static final int TEXT_WRAP_OFF · public static final int TEXT_WRAP_ON
This method returns the preferred font to use to render the specified element.
This method sets the application’s preferred policy for fitting Choice element contents to the available screen space. This method can contain one of the 3 options given below in its argument: · public static final int TEXT_WRAP_DEFAULT · public static final int TEXT_WRAP_OFF · public static final int TEXT_WRAP_ON Note This method can only give its recommendation to the device. The actual policy will be dependent on the particular device.
This method sets the preferred font for rendering the specified element of this Choice. public class ChoiceGroup What is it? The changes in ChoiceGroup are mainly due to the changes in Interface Choice which is implemented in ChoiceGroup and class Item, which is the super class of ChoiceGroup. The changes in Choice and Item are given in detail in there respective texts. public class Command What is it? This class encapsulates the semantic information of an action. The implementation of Command is device dependent. On some devices the commands are displayed on soft keys while on others they are shown in form of menus and lists. Thus care should be taken of testing the reaction of devices on adding commands. Generally the devices add the first 2 commands above the soft keys. o Constructors
This constructor constructs a new command object with the given long and short labels, type and priority. o Methods
This method returns the Command's long label. If the command has no long label a null is returned. public abstract class CustomItem What is it? One of the problems in MIDP 1.0 was that we could not create customized items. To eliminate this problem the CustomItem has been introduced. This class is customizable by sub classing to introduce new kinds of visual and interactive elements into Forms. This class is very similar to the Canvas class but it has been written keeping in mind that sub classes of this class will be appended to forms. o Constructors · public protected CustomItem(String label) This constructor has been provided so that the CustomItem subclass can specify its label. o Fields
Value: 4.
Value: 8.
Value: 0x10.
Value: 0.
Value: 0x80.
Value: 0x20.
Value: 0x40.
Value: 1.
Value: 2. o Methods · public int getGameAction(int keyCode) This method returns the game action corresponding to the key specified in this argument. It returns 0 if no game action is there for this key.
This method returns a bit mask of the available interaction modes
This method returns the minimum content height in pixels.
This method returns the minimum content width in pixels.
This method returns the preferred content height in pixels.
This method returns the preferred content width in pixels.
This method is called by the system to notify that the item is now completely invisible. No further calls to the paint() method will be made on this item until after a showNotify() has been called again.
This method signals that the CustomItem's size and traversal location need to be updated.
This method is called by the system when a key is pressed.
This method is called by the system when a key is released.
This method is called by the system when a key is repeated.
This method will be called to render the sub class of CustomItem. This method will be called only if the height and width of the CustomItem is greater than 0.
This method is called by the system when a pointer drag action has occurred within the item. The x and y coordinates of this method are relative to the origin of the item.
This method is called by the system when a pointer down action has occurred within the item. The x and y coordinates of this method are relative to the origin of the item.
This method is called by the system when a pointer up action has occurred after a pointer down action had occurred within the item. The x and y coordinates of this method are relative to the origin of the item.
This method is called by subclass code to request that the item needs to be repainted.
This method is called by subclass code to request that the specified rectangular area of the item needs to be repainted.
This method is called by the system to notify the item that it is now at least partially visible.
This method is implemented by the subclass in order to handle size change events.
This method is called by the system when traversal has entered the item or has occurred within the item.
This method is called by the system when traversal has occurred out of the item. public class Display What is it? The class Display represents the manager of the display and input devices of the system and it also includes methods for retrieving properties of the device and for requesting that objects be displayed on the device. o Fields
This field represents the Image type for Alert image.
This field represents the Image type for ChoiceGroup element image.
This field specifies the color type for use with getColor method. This field specifies the background color of the screen.
This field specifies the color type for use with getColor method. This field specifies the color for boxes and borders when the object is to be drawn in a non-highlighted state.
This field specifies the color type for use with getColor method. This field specifies the foreground color, for text characters and simple graphics on the screen.
This field specifies the color type for use with getColor method. This field specifies the color for the focus or focus highlight, when it is drawn as a filled in rectangle.
This field specifies the color type for use with getColor method. This field specifies the color for boxes and borders when the object is to be drawn in a highlighted state.
This field specifies the color type for use with getColor method. This field specifies the color for text characters and simple graphics when they are highlighted.
This field represents the Image type for List element image. o Methods · public void callSerially(Runnable r) This method causes the r (Runnable object) to have its run () method called later, serialized with the event stream soon after the completion of repaint cycle.
This method requests a flashing effect for the device’s backlight. This method is quite useful in games and can be used to attract the user’s attention or as a special effect for games.
This method returns the best image height for the image type. The return value may be zero if there is no best size. The return value will never be negative.
This method returns the best image width for the image type. The return value may be zero if there is no best size. The return value will never be negative.
This method returns the stroke style for drawing the border. This method will return either of the following: · Graphics.DOTTED · Graphics.SOLID
This method returns specified kind of color from high level user interface color scheme in the form of 0x00RRGGBB.
This method returns the MIDlet's current Displayable object
This method returns the display object that application can use for its user interface.
This method returns true if the display supports color else it will return false.
This method returns number of alpha transparency levels supported. This method will at least return a value of 2 which stands for full transparency and full opacity. In case alpha blending is supported this value will be greater than 2.
This method returns number of colors a device can support. If the isColor () method has returned false then this method will give the number of grayscale values this device supports.
This method requests that this Alert be made current Displayable and that next Displayable be made current after the Alert is dismissed.
This method requests that a different Displayable object shall be made visible on the display.
This method requests that the Displayable that contains this Item be made current. This method scrolls the Displayable so that this Item is visible and if possible assigns the focus to the Item passed in the argument.
This method is used for vibrating the device for a specified number of milliseconds. If we want to switch off the vibrator then we should pass 0 in the argument for this method. This method returns true if the vibrator can be controlled by the application and this display is in the foreground else it returns false. public abstract class Displayable What is it? Any class which needs to be placed on the display should be a sub class of this class. A Displayable object may have the following: · Title · Ticker · Zero or more commands · A command listener associated with it. The sub classes of this class define the contents to be displayed and their interaction with the users. o Methods · public void addCommand(Command cmd) This method adds the specified command to the Displayable. One command can not be added more than once on a Displayable even by calling this method repeatedly.
This method returns height of the area available to the application.
This method returns ticker object used. This method returns a null value if no ticker is present in this Displayable.
This method returns the title. It returns a null if no title is there.
This method returns width of the area available to the application.
This method returns true if this Displayable is currently visible.
This method removes the specified command from the Displayable. If the same command is repeatedly removed from the Displayable this method will have no effect.
This method sets a listener for Commands to this Displayable, replacing any previous CommandListener.
This method sets a ticker for use with this Displayable. In the process it removes any previous ticker.
This method sets the title of the Displayable. If null is given is the argument this method removes the title.
The implementation calls the sizeChanged (int w, int h) method when the available area of the Displayable has changed.
public final class Font What is it? One peculiar feature of MIDP 1.0 as well as MIDP 2.0 is that applications can not create there own fonts. The application can only demand particular kind of fonts and if they are there on the device they will returned. If the desired font is not there an approximate match is returned. This class is used to represent fonts and font metrics. o Fields
This field specifies a Font to be used to draw text input by a user. Value: 1.
This field specifies a default Font to be used to draw Item and Screen contents. Value: 0 o Methods
This method returns font that corresponds to the Font passed in the argument. public class Form What is it? The Form contains an arbitrary mixture of items namely: · Images · Read-only text fields · Editable text fields · Editable date fields · Gauges · Choice groups · Custom items. o Methods
This method deletes all the items from this Form leaving it without any items.
This method returns the height of the displayable area of the Form in pixels.
This method returns the width of the Form in pixels. public class Gauge What is it? This item shows an integer value in a graphical display. Some devices implement it in form of a bar graph while other show it as a progress screen. o Fields
This field represents the continuous idle state of a non-interactive Gauge with an indefinite range.
This field represents the continuous running state of a non-interactive Gauge with an indefinite range.
This field represents the incremental idle state of a non-interactive Gauge with indefinite range.
This field represents the incremental updating state of a non-interactive Gauge with indefinite range.
This field represents a special value used for the maximum value in order to indicate that the Gauge has indefinite range. public class Graphics What is it? This class acts as a pen/brush for drawing. It provides us with a simple 2D geometric rendering capability. o Fields
This field is the constant for positioning the anchor point at the baseline of text.
This field is the constant for positioning the anchor point of text and images below the text or mage.
This field is the constant for the DOTTED stroke style.
This field is the constant for centering text and images horizontally around the anchor point.
This field is the constant for positioning the anchor point of text and images to the left of the text or image.
This field is the constant for positioning the anchor point of text and images to the right of the text or image.
This field is the constant for the solid stroke style.
This field is the constant for positioning the anchor point of text and images above the text or image.
This field is the constant for centering images vertically around the anchor point. o Methods
This method copies the contents of a rectangular area (given by first 4 co-ordinates) to a destination area whose anchor point identified by the variable anchor is located at the variables represented by ‘x_dest’ and ‘y_dest’.
This method copies a region of the specified source image to a location within the destination, possibly transforming (rotating and reflecting) the image data using the chosen transform function.
This method renders a series of device-independent color values in a specified region. The values are stored in the integer array ‘rgbData’ in a format with 24 bits of RGB and an eight-bit alpha value (0xAARRGGBB), with the first value stored at the specified offset.
This method is used for drawing filled rectangles. This method fills the specified triangle will the current color. The lines connecting each pair of points are included in the filled triangle.
This method returns the corresponding color that will be displayed on the device’s screen (in 0x00RRGGBB format). This method is useful as the programmer can determine the actual drawing color that will be used due to the device constraints instead of the color he/she has given as the current color. public class Image What is it? The Image class is used to hold graphical image data. This class holds the data in off-screen memory and it is not painted in the Display till an explicit call is not made to display it either by low level user interface classes like Canvas or high level user interface classes like the Form o Methods
This method returns the created image from the specified co-ordinate area of the source image and suitably transforms it according to the transform parameter.
This method returns the created image from the decoded data obtained from an InputStream.
This method returns the created image from a sequence of ARGB values.
This method obtains ARGB pixel data from the specified region of this image and stores it in the array of integers provided in the method signature. public class ImageItem What is it? ImageItem is an item that can contain an image. o Constructors
Creates a new ImageItem object with the given label, image, layout directive, alternate text string, and appearance mode. Either label or alternative text may be present or null. o Methods
This method returns the appearance mode value which can be one of the following values: Item.PLAIN, Item.HYPERLINK or Item.BUTTON public abstract class Item What is it? This is the super class for all the components that can be added to a Form o Field
A field which stands for an appearance mode value indicating that the Item is to appear as a button.
A field which stands for an appearance mode value indicating that the Item is to appear as a hyperlink.
A field which stands for a layout directive indicating that new MIDP 2.0 layout rules are in effect for this Item. If this bit is clear it indicates that MIDP 1.0 layout behavior applies to this Item.
A field which stands for a layout directive indicating that this Item should have a bottom-aligned layout.
A field which stands for a layout directive indicating that this Item should have a horizontally centered layout.
A field which stands for a layout directive indicating that this Item should follow the default layout policy of its container.
A field which stands for a layout directive indicating that this Item's width may be increased to fill available space.
A field which stands for a layout directive indicating that this Item should have a left-aligned layout.
A field which stands for a layout directive indicating that this Item should the last on its line or row, and that the next Item (in case there is any) in the container should be placed on a new line or row.
A field which stands for a layout directive indicating that this Item should be placed at the beginning of a new line or row.
A field which stands for a layout directive indicating that this Item should have a right aligned layout.
A field which stands for a layout directive indicating that this Item's width may be reduced to its minimum width.
A field which stands for a layout directive indicating that this Item should have a top aligned layout.
A field which stands for a layout directive indicating that this Item should have a vertically centered layout.
A field which stands for a layout directive indicating that this Item's height may be increased to fill available space.
A field which stands for a layout directive indicating that this Item's height may be reduced to its minimum height.
This field indicates that the item should have a normal appearance. o Methods · public void addCommand(Command cmd) This method adds a context sensitive Command to the item.
This method returns a combination of layout directive values
This method returns the minimum height of this item.
This method returns the minimum width of this item.
This method returns the preferred height of this Item.
This method returns the preferred width of this Item.
This method causes this Item's containing Form to notify the Item's ItemStateListener.
This method removes the context sensitive command from this item.
This method sets default Command for this Item.
This method sets a listener for Commands to this Item replacing any previous ItemCommandListener.
This method sets the layout directives for this item.
This method sets the preferred width and height for this Item. public interface ItemCommandListener What is it? This is a new form of event listener which has been introduced in MIDP 2.0 for receiving notification of commands that have been invoked on Item objects. o Methods · public void commandAction(Command c, Item item) This method is called by the system to indicate that a command has been invoked on a specific item. public class List What is it? List is a Screen containing list of choices. This class gives us a very good user interface element for situation where a user has to choose between different choices or choose some elements among many. An example of an application where a list can be particularly useful is a restaurant menu application where a user can choose items to order for home delivery. o Methods
This method gets the application’s preferred policy for fitting Choice element contents to the available screen space.
This method returns the preferred font to use to render the specified element.
This method overrides the removeCommand method in Displayable.
This method sets the application’s preferred policy for fitting Choice element contents to the available screen space.
This method sets the application’s preferred font for rendering the specified element of this Choice.
This method sets the Command to be used for an IMPLICIT List selection action. This method will have no effect for other types of Lists. Setting a null value is allowed. The command should be null only if you want to have no select command for the List. public abstract class Screen What is it? Screen is the common super class of all high-level user interface classes. The contents that are displayed and their interaction with the user are defined by subclasses of Screen. In MIDP 2.0 the 4 methods of Screen that were there in MIDP 1.0 have been shifted to Displayable. public class Spacer What is it? A Spacer is a blank, non-interactive item that has a settable minimum size. o Constructors · public Spacer(int minWidth, int minHeight) This constructor creates a new Spacer with the given minimum size. o Methods · public void addCommand(Command cmd) Spacers can not contain Commands. Therefore this method will always throw IllegalStateException whenever it is called for a Spacer.
Spacers can not contain Commands. Therefore this method will always throw IllegalStateException whenever it is called for a Spacer.
Spacers can not contain labels. Therefore this method will always throw IllegalStateException whenever it is called for a Spacer.
This method sets the minimum size for this spacer. The Form will not be allowed to make the Spacer smaller than this size. The minimum size of Spacer must be zero or greater. To do List public class StringItem What is it? StringItem
is an item that can contain a non – editable string. It contains a label and a
text element.
o Constructors
This constructor is a new edition in MIDP 2.0. It creates a new object with the given label, textual content and appearance mode. The label or text elements may be present or they may have null value. o Methods · public int getAppearanceMode() This method returns the appearance mode value. The value may be one of the following: · Item.PLAIN · Item.HYPERLINK · Item.BUTTON
This method returns the preferred font of the application that will be used to render this StringItem
This method sets the application’s preferred font for rendering this StringItem.
public class TextBox What is it? The TextBox class is a Screen that allows the user to enter and edit text. o Methods
This method sets a hint to the implementation as to the input mode that should be used when the user initiates editing of this TextBox. What are Input Modes?
A string parameter is passed in the method setInitialInputMode(). This parameter is used to name the Unicode character subset that is desired as an input mode. This method gives a hint to the device about the application’s desire for a particular input mode. This input mode is not necessary to be the one that user sees on this device as there are a lot of variations in different devices. Thus the device can only try to match the input mode. If it can not find the match it will show the default input mode.
Unicode character blocks that can be used as the value for the parameter can be named by adding the prefix “UCB_” to the string names of fields representing Unicode character blocks as defined in the J2SE class java.lang.Character.UnicodeBlock. Unicode character blocks may be named in this fashion. The most common Unicode character blocks are as follows: · UCB_BASIC_LATIN · UCB_GREEK · UCB_CYRILLIC · UCB_ARMENIAN · UCB_HEBREW · UCB_ARABIC · UCB_DEVANAGARI · UCB_BENGALI · UCB_THAI · UCB_HIRAGANA · UCB_KATAKANA · UCB_HANGUL_SYLLABLES
You can also use the “Input subsets” as defined by the J2SE class java.awt.im.InputSubset by adding the prefix “IS_” to the string names of fields representing input subsets as defined in that class. The following are the names of the currently defined input subsets: · IS_FULLWIDTH_DIGITS · IS_FULLWIDTH_LATIN · IS_HALFWIDTH_KATAKANA · IS_HANJA · IS_KANJI · IS_LATIN · IS_LATIN_DIGITS · IS_SIMPLIFIED_HANZI · IS_TRADITIONAL_HANZI
Mobile Information Device Profile has also defined the following character subsets: · MIDP_UPPERCASE_LATIN – This is the subset of IS_LATIN that corresponds to uppercase Latin letters. · MIDP_LOWERCASE_LATIN – This is the subset of IS_LATIN that corresponds to lowercase Latin letters. The device implementations may also have specific character subsets that may be named with strings that have a prefix of “X_”. public class TextField What is it? A TextField is an editable text component that may be placed into a Form. o Fields
When you use this field the user is allowed to enter numeric values with optional decimal fractions.
This flag is a hint to the implementation that during text editing of the contents of TextField the initial letter of each sentence should be capitalized.
This flag is a hint to the implementation that during text editing of the contents of TextField the initial letter of each word should be capitalized.
This field indicates that the text entered by the user would not consist of words that are likely to be found in dictionaries typically used by predictive input schemes.
This field indicates that the text entered is sensitive data. The device must never store into a dictionary or table for use in predictive, auto-completing or other accelerated input schemes. A security ID is an example of sensitive data.
This field indicates that editing is currently disallowed. When this flag is set the device will prevent the user from changing the text contents of this object. o Methods
|
Mobile Technology > Java ME (J2ME) > Book - Mobile Phone Programming using Java ME (J2ME) > UNIT III >