概述
当前位置:我的异常网» J2SE » 请高手帮帮忙,Java多线程与图形界面的有关问题
请高手帮帮忙,Java多线程与图形界面的有关问题(2)
www.myexceptions.net 网友分享于:2013-08-15 浏览:9次
{
petePics[i] = kit.getImage(peteSrc[i]);
petePics1[i] = kit.getImage(peteSrc1[i]);
petePics2[i] = kit.getImage(peteSrc2[i]);
petePics3[i] = kit.getImage(peteSrc3[i]);
petePics4[i] = kit.getImage(peteSrc4[i]);
petePics5[i] = kit.getImage(peteSrc5[i]);
}
back = kit.getImage("30.jpg");
}
public void paint(Graphics comp) //创建绘图函数
{
Graphics2D comp2D = (Graphics2D) comp;
if (petePics[current] != null)
comp2D.drawImage(back,0,0,this);
comp2D.drawImage(petePics[current], x, y, this);
comp2D.drawImage(petePics1[current1], x1, y1, this);
comp2D.drawImage(petePics2[current2], x2, y2, this);
comp2D.drawImage(petePics3[current3], x3, y3, this);
comp2D.drawImage(petePics4[current4], x4, y4, this);
comp2D.drawImage(petePics5[current5], x5, y5, this);
}
}
class myammoo extends Thread
{
PetePanel pete ;
public myammoo(PetePanel pete)
{
this.pete=pete;
}
public void run()
{
for(;true;){
while(pete.live==1)
{
if(pete.current==0)
{
System.out.println("Thread is live");
pete.current5=0;
pete.x5=pete.x+10;
pete.y5=pete.y+10;
for(int i=0;i<500;i++)
{
pete.x5=pete.x5+1;
pete.y4=pete.y4+1;
try
{
sleep(1); //线程休眠
}
catch(InterruptedException e){}
pete.repaint();
}
}
else if(pete.current==1)
{
pete.current5=1;
pete.x5=pete.x+10;
pete.y5=pete.y+10;
for(int i=0;i<500;i++)
{
pete.x5=pete.x5-1;
pete.y4=pete.y4+1;
try
{
sleep(1); //线程休眠
}
catch(InterruptedException e){}
pete.repaint();
}
}
else if(pete.current==2)
{
pete.current5=2;
pete.x5=pete.x+10;
pete.y5=pete.y+10;
for(int i=0;i<500;i++)
{
pete.y5=pete.y5-1;
pete.y4=pete.y4+1;
try
{
sleep(1); //线程休眠
}
catch(InterruptedException e){}
pete.repaint();
}
}
else if(pete.current==3)
{
pete.current5=3;
pete.x5=pete.x+10;
pete.y5=pete.y+10;
for(int i=0;i<500;i++)
{
pete.y5=pete.y5+1;
pete.y4=pete.y4+1;
try
{
sleep(1); //线程休眠
}
catch(InterruptedException e){}
pete.repaint();
}
}
pete.x5=0-20;
pete.y5=0-20;
try
{
sleep(1000); //线程休眠
}
catch(InterruptedException e){}
}
}}
}
------解决方案--------------------
代码太多,懒得看,看你的描述,应该用监听键盘事件,然后坐处理。
文章评论
最后
以上就是无辜小笼包为你收集整理的java图形界面多线程,请高手帮帮忙,Java多线程与图形界面的有关问题(2)的全部内容,希望文章能够帮你解决java图形界面多线程,请高手帮帮忙,Java多线程与图形界面的有关问题(2)所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复