Graffiti (URGENT!!!)
Hi!
Can I recognize someway the graffitis that are introduced on the PDA device? I am using JUST a Canvas object, without TextField or anything like that. Just a simple Canvas.
If someone knows the answer, please replay ASAP, it's really urgent.
Thank You.
Fritz
> do i take it from the lack of a reply that it is
> impossible to get text characters (via graffiti) from
> the keyPressed/keyReleased call backs in Canvas
> subclasses on midp4palm? if so, why was the Canvas
> class implemented this way? how am i supposed to get
> text input without having to suffer the atrocious ui
> designs in Form/TextField and TextBox?
>
> HELP...
>
> --nikk
You can use graffiti to get stylus and text input. There are three classes given below, I hope they help.
import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;
public abstract class GameCanvas extends Canvas {
protected MIDlet midlet;
protected intfireKey;
protected intleftKey;
protected intrightKey;
protected intupKey;
protected intdownKey;
public GameCanvas( MIDlet midlet ){
this.midlet = midlet;
fireKey = getKeyCode( FIRE );
leftKey = getKeyCode( LEFT );
rightKey = getKeyCode( RIGHT );
upKey = getKeyCode( UP );
downKey = getKeyCode( DOWN );
}
}
========================================
import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;
public class ConcreteCanvas extends GameCanvas {
private String message = "Press any key";
public ConcreteCanvas( MIDlet midlet ){
super( midlet );
}
protected void paint( Graphics g ){
g.setColor( 255, 255, 255 );
g.fillRect( 0, 0, getWidth(), getHeight() );
g.setColor( 0, 0, 0 );
g.drawString( message, getWidth()/2, 0,
g.TOP | g.HCENTER );
}
protected void keyPressed( int keyCode ){
if( keyCode == fireKey ){
message = "FIRE";
} else if( keyCode == leftKey ){
message = "LEFT";
} else if( keyCode == rightKey ){
message = "RIGHT";
} else if( keyCode == upKey ){
message = "UP";
} else if( keyCode == downKey ){
message = "DOWN";
} else {
message = getKeyName( keyCode );
}
repaint();
}
protected void pointerPressed( int x, int y ){
message = "Coord: " + String.valueOf(x) + ", " + String.valueOf(y);
repaint();
}
}
===========================================
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
public class MyCanvas extends MIDlet implements
CommandListener {
private Display display;
private ConcreteCanvas canvas;
private Command exitCommand = new Command(
"Exit", Command.SCREEN, 1 );
public MyCanvas(){
display = Display.getDisplay( this );
canvas = new ConcreteCanvas( this );
canvas.addCommand( exitCommand );
canvas.setCommandListener( this );
}
protected void startApp(){
display.setCurrent( canvas );
}
protected void pauseApp(){
}
protected void destroyApp( boolean unconditional ){
}
public void exit(){
destroyApp( true );
notifyDestroyed();
}
public void commandAction( Command c, Displayable d ){
if( c == exitCommand ){
exit();
}
}
}
======================================
Name your MIDlet MyCanvas as that is the main class. Convert into prc file as usual, and see what it does :)
Umer