Thursday, November 27, 2008

Existentialism Capitalize

Let's go down to take a look


INTERFACES OF LOW

Well, in the earlier talk of high-level interfaces, commented that these interfaces are the easiest to implement because its look is in charge of device running the application.
This allows us to save time and effort, but sometimes will need to take control of your presentation, for example: If you're developing a video game.

RULE No. 1:
Before starting, it is desirable to set a rule: "All screens we create using the low-level APIs inherit from the Canvas class.

For this reason, first of all get to know this class and then go deeper into each of the elements that compose it.
Canvas Class is the superclass of all screens that use low-level APIs, as it was for Screen displays worn by high-level APIs.

PEACEFUL COEXISTENCE:
However, the relationship APIs high and low, there is nothing in writing, that is: "There is no impediment in allowing us to use both screens the same MIDlet as derived from Canvas Screen"

Canvas class allows handle low-level events and draw anything on screen. That is why it is used as a basis for conducting games.

This class has an abstract method paint () we must implement a mandatory (for our own will) and is responsible for drawing on the screen of the device.


An example familiar to go:


BajoNivel.java


import java.io.IOException;
javax.microedition.lcdui import. *;
lowlevel public class extends Canvas implements CommandListener {
private PBajoNivel midlet;
private Command salir;
private Image imgFondo, imgTriste;
public BajoNivel(PBajoNivel mid) {
try {
imgFondo = Image.createImage("/fondo.PNG");
imgTriste = Image.createImage("/triste.PNG");
} catch (IOException e) {
e.printStackTrace();
}
salir = new Command("Salir", Command.EXIT,1);
this.midlet = mid;
this.addCommand(salir);
this.setCommandListener(this);
}
public void paint(Graphics g) {
g.setColor(255,255,255);
g.fillRect(0,0,getWidth(),getHeight());
g.setColor(0,0,0);
g.drawImage (imgFondo, 0, 0, 0);
g.drawImage (imgTriste, 40, 40, 0);

} public void commandAction (Command c, Display d) {
if (c == exit) {
midlet.salir ();

}}}



This routine is the one we show in the display device, note that we are using two images and fondo.PNG triste.PNG , these files are placed in the res directory in your project.


Now let MIDlet code that will summon.


PBajoNivel.java
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
public class PBajoNivel extends MIDlet {
private BajoNivel panCanvas;
private Display pantalla;
public PBajoNivel() throws Exception{
pantalla = Display.getDisplay(this);
panCanvas = new BajoNivel(this);
}
public void startApp() {
pantalla.setCurrent(panCanvas);
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
}
public void salir(){
destroyApp(false);
notifyDestroyed();
}
}

As noted, PBajoNivel.java simply declare a class inherited pancanvas lowlevel.


Two examples of running this application in two different models of cellular, so that the reader can verify the deployment difference between one and another.












Sunday, November 23, 2008

In How Many Units Does Heparin

THE REST OF THE INTERFACE

two deliveries in the latter one, we seen the use of two components to the use of menus, we saw the kind LIST and CHOICEGROUP , we found that basically the difference between the two is that the class LIST is not subordinate to the class FORM , that is, it is not necessary to first create an object type FORM then add the object LIST.



private Display display;

private mylist;

...

display = Display.getDisplay (this);

mylist = new List ("Options" List.IMPLICIT)
miLista.append ("High", null);
miLista.append ( low ", null);
miLista.append (" Query ", null);
miLista.append (" Amendments ", null);
miLista.append (" Print ", null);
...


display.setCurrent (mylist);



CHOICEGROUP While an object must be attached to a Form.



private Display miDisplay;
Form miForma private, private
ChoiceGroup myGroup;


...

miDisplay = Display.getDisplay (this);
miForma = new Form ("MAIN MENU");


...

ChoiceGroup myGroup = new ("Options:" ChoiceGroup.EXCLUSIVE)
miGrupo.append ("High", null);
miGrupo.append ("Low", null);
miGrupo.append ( "Consultations", null);
miGrupo.append ("Amendments", null);
miGrupo.append ("Print", null);


...

miForma.append (myGroup)

...
display.setCurrent (mylist);




But besides these classes we have many more like ...


Class Ticker

Util to display messages in the form of a canopy gliding side to side of the user's screen.


Class DateField

Useful for handling dates, either for display or to request the user to provide a specific date.



Class ImageItem

Useful for work with image files in your application. We shall see later, but with this tool you can add a visual appeal that makes it more friendly and user friendly.


Class TextField

Useful for text handling, which can be deployed alone or, to ask the user to enter data. Such as password, numbers, names, etc.



should be noted that high-level graphics classes, have the facility to suit the type of deployment available to the device in which we work.

In other words, we call the classes and create the objects in our application, but the display is under the control of the hardware.



Let's see, the use of the classes mentioned above, in one example.


import java.io.IOException;
import java.util.Date;
javax.microedition.lcdui.Command import, import
javax.microedition.lcdui.CommandListener;
javax.microedition.lcdui.DateField import;
javax.microedition.lcdui.Display import, import
javax.microedition.lcdui.Displayable;

import javax.microedition.lcdui.Form;

import javax.microedition.lcdui.Image;

import javax.microedition.lcdui.ImageItem;

import javax.microedition.lcdui.Item;

import javax.microedition.lcdui.ItemStateListener;

import javax.microedition.lcdui.TextField;

import javax.microedition.lcdui.Ticker;

import javax.microedition.midlet.MIDlet;

import javax.microedition.midlet.MIDletStateChangeException;






public class MIDOtros extends MIDlet implements CommandListener, ItemStateListener {

private Ticker miMarquesina;

private DateField miFecha;

private ImageItem miImagen;

private TextField miHumor;

private Image imgSerio, imgFeliz, imgTriste;

private Command Salir;

private Display miDisplay;

private Form miForma;





public MIDOtros() {

try {

imgSerio = Image.createImage("/serio.PNG");

imgFeliz = Image.createImage("/feliz.PNG");

imgTriste = Image.createImage("/triste.PNG");

} catch (IOException e) {

e.printStackTrace();

}





Date wHoy = new Date();

miDisplay = Display.getDisplay(this);

miFecha = new DateField("Dia de hoy",DateField.DATE);

miFecha.setDate(wHoy);

miHumor = new TextField("% de Animo", "50", 2, TextField.NUMERIC);

miMarquesina = new Ticker("Ejemplo de Graficos de Alto Nivel. Tutorial para el Desarrollo de aplicaciones en móviles, País México. Noviembre del 2008");

miForma = new Form("Otros Items");

Salir = new Command("Salir", Command.EXIT, 0);

miImagen = new ImageItem(null, imgSerio, 0, null);

miForma.setTicker(miMarquesina);

miForma.append(miFecha);

miForma.append(miImagen);

miForma.append(miHumor);

miForma.addCommand(Salir);

miForma.setCommandListener(this);

miForma.setItemStateListener(this);

}





protected void destroyApp(boolean arg0) throws MIDletStateChangeException {

}





protected void pauseApp() {

}





protected void startApp() throws MIDletStateChangeException {

this.miDisplay.setCurrent(this.miForma);

}





public void commandAction(Command arg0, Displayable arg1) {

if (arg0 == Salir){

try {

destroyApp(false);

} catch (MIDletStateChangeException e) {

e.printStackTrace();

}
notifyDestroyed ();

}} public void


itemStateChanged (Item arg0) {
if (arg0 == miHumor) {int
wValor = Integer.parseInt (miHumor.getString ());
if (wValor <> 70) {
miImagen.setImage (imgFeliz)} else {

miImagen.setImage (imgSerio)

}}}


}}




As noted, in this application handle image files:


imgSerio = Image.createImage ("/ serio.PNG");
imgFeliz = Image.createImage ("/ feliz.PNG");
imgTriste = Image.createImage ("/ triste.PNG");




What are PNG files, this allows us to handle images with a good reasonable resolution and store in a small space.
Well, once compiled our code, we can run it and see it in action.