hi i have a thread that paint and “does the mathematics” then it sleep for 40 ms!
now i have the problem that it doesn’T count any more!
it paints but doesn’t move the components!to little time?
i don’t know what to do!!heeelp!
here te code of the tread:
class CAlien extends Thread
{
Canvas anzeige;
int m_xPos,m_yPos;
int m_xGo,m_yGo;//Schrittweite
public CAlien(Canvas a,int x,int y){
anzeige=a;
m_xPos=x;
m_yPos=y;
m_xGo=7;
m_yGo=13;
}
public CAlien(Canvas a){
anzeige=a;
double xtmp=(Math.random()*780)+10;
double ytmp=(Math.random()*480)+10;
m_xPos=(int)xtmp;
m_yPos=(int)ytmp;
}
public void run(){
bewegen();
while(isInterrupted()==false){
anzeigen();
try
{
sleep(40);
}
catch(InterruptedException e){
return;
}
}
}
void anzeigen(){
Graphics g1=db.getGraphics();
Graphics g=anzeige.getGraphics();
g1.setFont(m_anzeiger);
//g1.drawImage(m_bild,m_xPos,m_yPos,null);
g1.setColor(Color.black);
g1.fillOval(m_xPos+5,m_yPos+5,30,30);
g1.setColor(Color.orange);
g1.fillOval(m_xPos, m_yPos,30,30);
g1.setColor(Color.black);
g1.fillOval(m_xPos+9,m_yPos+6,3,3);
g1.fillOval(m_xPos+17,m_yPos+6,3,3);
g1.drawRect(m_xPos+7,m_yPos+18,16,4);
g1.setColor(Color.black);
g1.drawString(m_tref,350,470);
g1.setColor(Color.black);
g1.fillRect(zt.xPos+5,zt.yPos+5,zt.breite,zt.hohe);
g1.setColor(Color.red);
g1.fillRect(zt.xPos,zt.yPos,zt.breite,zt.hohe);
g1.dispose();
g.drawImage(db,0,0,null);
g.dispose();
}
void bewegen(){
int xNeu,yNeu;
Graphics g=db.getGraphics();
Dimension m=anzeige.getSize();
xNeu=m_xPos+m_xGo;
yNeu=m_yPos+m_yGo;
if(xNeu<0){
xNeu=0;
double tmp=(Math.random()*15)+5;
m_xGo=(int)tmp;
m_treffer–;
}
if(xNeu+30 >=m.width){
xNeu=m.width-30;
double tmp=(Math.random()*15)+5;
m_xGo=(int)-tmp;
m_treffer–;
}
if(yNeu<0){
yNeu=0;
double tmp=(Math.random()*15)+5;
m_yGo=(int)tmp;
m_treffer–;
}
if(yNeu+30>=m.height){
yNeu=m.height-30;
double tmp=(Math.random()*15)+5;
m_yGo=(int)-tmp;
m_treffer–;
}
g.setColor(Color.gray);
g.fillRect(m_xPos-1,m_yPos-1,m_xPos+37,m_yPos+37);
g.fillRect(380,450,100,40);
m_xPos=xNeu;
m_yPos=yNeu;
anzeigen();
g.dispose();
}
}