dgiac
07-03-2011, 23:12
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
public class Disegna extends MIDlet {
public void startApp() {
Display display = Display.getDisplay(this);
display.setCurrent(new Linea());
} // startApp
public void pauseApp() {
} // pauseApp
public void destroyApp(boolean unconditional) {
} // destroyApp
protected class Linea extends Canvas {
private int xAtt, yAtt, xPrec, yPrec;
private boolean primoTouch = true;
public Linea() {
setFullScreenMode(true);
} // Linea
public void pointerReleased (int x, int y) {
primoTouch = true;
} // pointReleased
public void pointerDragged (int x, int y) {
if(primoTouch) {
xAtt = x;
yAtt = y;
primoTouch = false;
} // if
xPrec = xAtt;
yPrec = yAtt;
xAtt = x;
yAtt = y;
repaint();
} // pointDragged
public void paint (Graphics g) {
g.drawLine(xPrec, yPrec, xAtt, yAtt);
} // paint
} // Linea
} // Disegna
Il problema è che finchè lo provo sull'emulatore funziona, ma sul telefono disegna le linee tutte tratteggiate, come su il repaint() non riuscisse a star dietro al movimento del dito.. Cosa posso fare?
import javax.microedition.lcdui.*;
public class Disegna extends MIDlet {
public void startApp() {
Display display = Display.getDisplay(this);
display.setCurrent(new Linea());
} // startApp
public void pauseApp() {
} // pauseApp
public void destroyApp(boolean unconditional) {
} // destroyApp
protected class Linea extends Canvas {
private int xAtt, yAtt, xPrec, yPrec;
private boolean primoTouch = true;
public Linea() {
setFullScreenMode(true);
} // Linea
public void pointerReleased (int x, int y) {
primoTouch = true;
} // pointReleased
public void pointerDragged (int x, int y) {
if(primoTouch) {
xAtt = x;
yAtt = y;
primoTouch = false;
} // if
xPrec = xAtt;
yPrec = yAtt;
xAtt = x;
yAtt = y;
repaint();
} // pointDragged
public void paint (Graphics g) {
g.drawLine(xPrec, yPrec, xAtt, yAtt);
} // paint
} // Linea
} // Disegna
Il problema è che finchè lo provo sull'emulatore funziona, ma sul telefono disegna le linee tutte tratteggiate, come su il repaint() non riuscisse a star dietro al movimento del dito.. Cosa posso fare?