0
我開發了一個簡單時鐘應用程序在Java midlet在Netbeans。 現在我想在手機中設置Java Midlet應用爲壁紙。如何啓用JAVA MIDLET設置爲StandBy Wallpaper?
在我的項目中有兩個文件。 AnimationLoopMidlet:包含startApp()
函數。
AnimationLoop:更新時間並在屏幕上繪製。 這些是我的代碼。
AnimationLoopMidlet.java
package mobileapplication1;
import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;
import java.util.*;
public class AnimationLoopMIDlet extends MIDlet{
static AnimationLoopMIDlet obj;
public AnimationLoopMIDlet()
{
AnimationLoopMIDlet.obj=this;
}
public void startApp() {
Display.getDisplay(this).setCurrent(new AnimationLoop());
}
public void pauseApp()
{
}
public void destroyApp(boolean unconditional) {
}
}
AnimationLoop.java
package mobileapplication1;
import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;
import java.util.*;
import javax.microedition.lcdui.game.GameCanvas;
public class AnimationLoop extends GameCanvas implements Runnable{
boolean running;
public AnimationLoop()
{
super(false);
start();
}
void start()
{
Thread t=new Thread(this);
t.setPriority(Thread.MAX_PRIORITY);
t.start();
}
public void run()
{
running=true;
while(running)
{
update();
flushGraphics();
}
}
public void update()
{
Graphics g=getGraphics();
Date c= new Date();
String s=new String();
s=""+c;
g.setColor(0xffffff);
g.setStrokeStyle(Graphics.SOLID);
g.fillRect(0,0,240,320);
g.setColor(0x000000);
g.setFont(Font.getDefaultFont());
g.drawString("Day:"+s.substring(0,4),0,14,g.LEFT | g.TOP);
g.drawString("Month"+s.substring(4,7),0,30,g.LEFT | g.TOP);
g.drawString("Date:"+s.substring(8,10),0,50,g.LEFT | g.TOP);
g.drawString("Hour:"+s.substring(11,13),0,70,g.LEFT | g.TOP);
g.drawString("Minute:"+s.substring(14,16),0,90,g.LEFT | g.TOP);
g.drawString("Seconds:"+s.substring(17,19),0,120,g.LEFT | g.TOP);
}
}