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 ();
}}}
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();
}
} 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.