国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

采用多線程制作動畫

2019-11-18 13:58:18
字體:
來源:轉載
供稿:網友

import java.awt.*;
import java.applet.*;

//注重到這個程序和Hello程序有什么不一樣嗎?在這個程序中多了implements Runnable。
public class carton extends Applet implements Runnable
{
Image img;
Thread thd = null;
int i;
int imgWidth = 150;
int imgHeight = 150;
int ncyc=1 ;

String namestr[] = new String[5] ;

//當線程被激活時開始運行run()函數。
public void run()
{
for (int j=0; j<5; j++)
{
namestr[j] = Integer.toString(j,8)+".jpg" ;
}

ncyc = -1 ;
while (true)
{
if (ncyc<=3) ncyc= ncyc+1 ; //初始化循環控制參數
else ncyc = 0 ;
img = getImage(getCodeBase(), namestr[ncyc]) ;

if (img != null)
{
i=imgHeight;
//repaint();
}

try {Thread.sleep(1000);} catch (InterruptedException e){}
i=0;
while (i<imgHeight)
{
repaint();
try {Thread.sleep(50);} catch (InterruptedException e){}
i+=4;
}
}
}

  //每次代碼在新位置處重畫位圖,它都要調用repaint。該函數調用可重載的update方法。update方法與paint方法是相同的,這里為啥不用怕paint(Graphics g)呢?除了paint方法在繪圖前要清除窗口,而update方法不清除(假如你把update方法改名為paint,你會看到有什么不同)。
public void update(Graphics g)
{
if (img != null)
{
g.clipRect(0, 0, imgWidth, i);
g.drawImage(img, 0, i - imgHeight, null);
}
}

public void start()
{
if (thd == null)
{
thd = new Thread(this);
thd.start();
}
}

public void stop()
{
thd = null;
}

上一篇:布爾型

下一篇:編譯器-Javac.exe

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 隆尧县| 台湾省| 稻城县| 昭通市| 涪陵区| 威信县| 久治县| 伽师县| 徐闻县| 泗洪县| 保山市| 永寿县| 安国市| 陆良县| 镇远县| 独山县| 桃江县| 鹤峰县| 赤峰市| 白城市| 砚山县| 德安县| 白河县| 宝丰县| 岚皋县| 宝坻区| 长阳| 祁门县| 麻栗坡县| 墨江| 四平市| 广汉市| 永定县| 惠安县| 山东省| 西和县| 永年县| 新建县| 德化县| 德化县| 汾阳市|