import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;
public class GraphicsTest extends MIDlet{
private Display display;
public GraphicsTest() {
display=Display.getDisplay(this);
}
protected void destroyApp(boolean unconditional) {
}
protected void pauseApp() {
}
protected void startApp(){
MyCanvas mc=new MyCanvas();
display.setCurrent(mc);
}
}
class MyCanvas extends Canvas {
public void paint(Graphics g){
int width=getWidth();
int height=getHeight();
String a[]={"静夜思","李白","床前明月光","疑是地上霜","举头望明月","低头思故乡"};
g.setColor(0);
g.fillRect(0, 0, width, height);
g.setColor(0Xffff00);
Font font=g.getFont();
font=Font.getFont(Font.FACE_PROPORTIONAL,Font.STYLE_UNDERLINED,Font.SIZE_LARGE);
g.setFont(font);
for(int i=0;i<a.length;i++){
g.drawString(a[i], 0, i*20,Graphics.LEFT|Graphics.BASELINE );
}
}
}
//--------------------------------------------------------------------------------------------
利用移动原点坐标动起来之后的静夜思
import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;
public class GraphicsTest extends MIDlet{
private Display display;
public GraphicsTest() {
display=Display.getDisplay(this);
}
protected void destroyApp(boolean unconditional) {
}
protected void pauseApp() {
}
protected void startApp(){
MyCanvas mc=new MyCanvas();
display.setCurrent(mc);
}
}
class MyCanvas extends Canvas {
int aa=300;
MyCanvas(){
Walk w = new Walk();
w.start();
}
public void paint(Graphics g){
int width=getWidth();
int height=getHeight();
String a[]={"静夜思","李白","床前明月光","疑是地上霜","举头望明月","低头思故乡"};
g.setColor(0);
g.fillRect(0, 0, width, height);
g.setColor(0Xffff00);
g.translate(80,aa);
Font font=g.getFont();
font=Font.getFont(Font.FACE_PROPORTIONAL,Font.FACE_SYSTEM,Font.SIZE_LARGE);
g.setFont(font);
for(int i=0;i<a.length;i++){
g.drawString(a[i], 0, i*20,20);
}
}
class Walk extends Thread{
public void run(){
while(aa>80){
aa--;
repaint();
try{
sleep(50);
}catch(Exception ee){}
}
}
}
}