/** * *
Titulo: Servidor de respuestas a preguntas
*Descripcion: Este programa permite generar mensajes de la parte grafica * y recepcionar las respuestas a esta. *
* @author Diego Gonzalez Barrientos * @version 1.0 */ //Paquetes requeridos por el programa import javax.microedition.lcdui.*; import java.util.*; public class MensajeUI extends Canvas { // list of available message to display public Vector msgs = new Vector(); // current message idx int midx = 0; // graphic width and height int w, h; // font height int fh; // font to write message on screen Font f; int x0=0, y0=0; public int bookmarkId = 1; // 0 = BTBroserMain // 1 = ListServicesUI // 2 = ServiceDetailsUI public int backTo = 0; public MensajeUI() { addCommand(new Command("Back", Command.BACK, 1)); } protected void paint(Graphics g) { if ( f == null ) { // cache the font and width,height value // when it is used the first time f = Font.getFont( Font.FACE_MONOSPACE, Font.STYLE_PLAIN, Font.SIZE_SMALL ); w = this.getWidth(); h = this.getHeight(); fh = f.getHeight(); } // // detemine midx based on the screen height and number of message /* midx = msgs.size() - (h/fh) ; if ( midx < 0 ) midx = 0; */ int y = fh; // 1st line y value // message will be rendered in black color, on top of white backgound g.setColor( 255, 255, 255 ); g.fillRect( 0, 0, w, h ); g.setColor( 0, 0, 0 ); g.setFont( f ); g.translate(-x0, -y0); // render the messages on screen for ( int i= midx; i< msgs.size(); i++ ) { String s = (String)msgs.elementAt(i); g.drawString( s, 0, y, Graphics.BASELINE | Graphics.LEFT ); y += fh; } } public void keyPressed( int key ) { if ( getGameAction( key ) == Canvas.RIGHT ) { x0+=50; } else if ( getGameAction( key ) == Canvas.LEFT ) { x0-=50; } else if ( getGameAction( key ) == Canvas.UP ) { // note: change this from 50 to 100 if you want to scroll faster y0-=50; } else if ( getGameAction( key ) == Canvas.DOWN ) { // note: change this from 50 to 100 if you want to scroll faster y0+=50; } repaint(); } public void clear() { msgs.removeAllElements(); midx = 0; x0 = 0; y0 = 0; bookmarkId = 1; repaint(); } public void add( String s ) { msgs.addElement( s ); repaint(); } public void addNoRepaint( String s ) { msgs.addElement( s ); } }