Java-Gaming.org Java4K winners: [ by our judges | by the community ]         
Featured games (67)
games approved by the League of Dukes
Games in Showcase (∞)
games submitted by our members



News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  Print  
  not enough time?  (Read 1210 times)
0 Members and 2 Guests are viewing this topic.
Offline Ruflinger14

JGO n00b
*

Posts: 7


Java games rock!


« on: 2002-12-24 16:22:02 »

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();
   }
}
Offline Themroc

Jr. Member
**

Posts: 70



« Reply #1 on: 2002-12-28 06:51:09 »

Quote

   public void run(){
       bewegen();
       while(isInterrupted()==false){
       anzeigen();
       try
       {
           sleep(40);
       }
       catch(InterruptedException e){
       return;
       }
       }
   }



bewegen() is only executed once, after that the code stays in the while-loop. Or is your thread interrupted and restarted from somewhere else?
Pages: [1]
  Print  
 
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.16 | SMF © 2011, Simple Machines Valid XHTML 1.0! Valid CSS!
Page created in 0.084 seconds with 19 queries.