Sto studiando sulla guida di html.it
Ho inserito questo codice, come c'è scritto.
Ora se provo ad eseguire, mi da
Unable to create MIDlet MyCanvas
java.lang.InstantiationException: Class not a MIDlet
at com.sun.midp.midlet.MIDletState.createMIDlet(MIDle tState.java:153)
at com.sun.midp.midlet.Selector.run(Selector.java:151 )
Non capisco dove sia l'errore... Ma non c'era bisogno di startApp() etc???
import java.io.IOException;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
public class MyCanvas extends Canvas {
private Image image = null;
private int width = 0;
private int height = 0;
private String lastKeyPressed = "Nessun tasto";
public MyCanvas() {
super();
try {
image = Image.createImage("/tramonto.PNG");
setFullScreenMode(true);
width = getWidth();
height = getHeight();
}
catch (IOException e)
{
e.printStackTrace();
}
}
protected void paint(Graphics g) {
g.setColor(0, 0, 255);
g.fillRect(0, 0, width, height);
if (image != null)
{
g.drawImage(image, width/2, height/2, Graphics.VCENTER | Graphics.HCENTER);
}
g.setColor(255,255,255);
g.drawString(lastKeyPressed, width/2, height - 10, Graphics.BASELINE | Graphics.HCENTER);
}
protected void keyPressed(int arg0) {
switch (arg0)
{
case KEY_NUM0:
lastKeyPressed = "0";
break;
case KEY_NUM1:
lastKeyPressed = "1";
break;
case KEY_NUM2:
lastKeyPressed = "2";
break;
case KEY_NUM3:
lastKeyPressed = "3";
break;
case KEY_NUM4:
lastKeyPressed = "4";
break;
case KEY_NUM5:
lastKeyPressed = "5";
break;
case KEY_NUM6:
lastKeyPressed = "6";
break;
case KEY_NUM7:
lastKeyPressed = "7";
break;
case KEY_NUM8:
lastKeyPressed = "8";
break;
case KEY_NUM9:
lastKeyPressed = "9";
break;
}
repaint();
}
}

Rispondi quotando
sono ignorante.
