public synchronized void go() {
notify();
}
这样效率比较高了!当用户进行联网操作的时候我们应该做一个提示界面,比如一个动画告诉用户正在进行联网操作。这样比较友好。那么当用户选择联网动作的时候,我们让我提前做好的欢迎界面显示在屏幕上,联网结束后再把返回的结果显示出来。这样就是一个出色的联网应用程序了。下面的这个代码可以在屏幕上描绘一个动画的效果,当然你也可以修改一下做成自己喜欢的样子。
import java.util.*;
import javax.microedition.lcdui.*;
public class WaitCanvas
extends Canvas {
private int mCount, mMaximum;
private int mInterval;
private int mWidth, mHeight, mX, mY, mRadius;
private String mMessage;
public WaitCanvas() {
mCount = 0;
mMaximum = 36;
mInterval = 100;
mWidth = getWidth();
mHeight = getHeight();
// Calculate the radius.
int halfWidth = (mWidth - mRadius) / 2;
int halfHeight = (mHeight - mRadius) / 2;
mRadius = Math.min(halfWidth, halfHeight);
// Calculate the location.
mX = halfWidth - mRadius / 2;
mY = halfHeight - mRadius / 2;
// Create a Timer to update the display.
TimerTask task = new TimerTask() {
public void run() {
mCount = (mCount + 1) % mMaximum;
repaint();
}
};
Timer timer = new Timer();
timer.schedule(task, 0, mInterval);
}
public void setMessage(String s) {
mMessage = s;
repaint();
}
public void paint(Graphics g) {
int theta = -(mCount * 360 / mMaximum);
// Clear the whole screen.
g.setColor(255, 255, 255);
g.fillRect(0, 0, mWidth, mHeight);
// Now draw the pinwheel.
g.setColor(0, 0, 0);
g.drawArc(mX, mY, mRadius, mRadius, 0, 360);
g.fillArc(mX, mY, mRadius, mRadius, theta + 90, 90);
g.fillArc(mX, mY, mRadius, mRadius, theta + 270, 90);
// Draw the message, if there is a message.
if (mMessage != null)
g.drawString(mMessage, mWidth / 2, mHeight,
Graphics.BOTTOM | Graphics.HCENTER);
}
}
你可以从这里下载SUN提供的实例代码,仔细研究一下一定受益匪浅。
本文地址:http://com.8s8s.com/it/it15432.htm