線程是程序的一部分
線程的現實是通過java
import java
import java
import javax
public class Cartoon extends JApplet implements Runnable
{
Graphics screenBuffer = null;//創建圖形緩沖區
Image screenImage = null;
private Thread runner;
private int x =
private int move =
public void init ( )
{
screenImage = createImage (
screenBuffer = screenImage
}
public void start ( )
{
if (runner == null)
{
runner = new Thread( this );
runner
}
}
public void run( )
{
Thread circle = Thread
while ( runner == circle )//指向同一對象
{
x += move;
if ( ( x >
move *=
repaint ( );
}
}
public void drawCircle( Graphics gc )
{
Graphics
g
g
g
g
g
g
}
public void paint( Graphics g )
{
screenBuffer
screenBuffer
drawCircle ( screenBuffer );
//將緩沖區的圖像復制到主緩沖區中
g
}
}
From:http://tw.wingwit.com/Article/program/Java/gj/201311/27531.html