Java-Gaming.org
Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
Featured games (78)
games approved by the League of Dukes
Games in Showcase (406)
games submitted by our members
Games in WIP (293)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  not enough time?  (Read 1351 times)
0 Members and 1 Guest are viewing this topic.
Offline Ruflinger14

Junior Newbie




Java games rock!


« Posted 2002-12-24 22: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

Junior Member





« Reply #1 - Posted 2002-12-28 12: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]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
 
Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars and Titan!

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

The invasion has landed! On Mars! And you're there to beat 'em!
cubemaster21 (84 views)
2013-05-17 21:29:12

alaslipknot (92 views)
2013-05-16 21:24:48

gouessej (123 views)
2013-05-16 00:53:38

gouessej (115 views)
2013-05-16 00:17:58

theagentd (127 views)
2013-05-15 15:01:13

theagentd (114 views)
2013-05-15 15:00:54

StreetDoggy (158 views)
2013-05-14 15:56:26

kutucuk (180 views)
2013-05-12 17:10:36

kutucuk (180 views)
2013-05-12 15:36:09

UnluckyDevil (187 views)
2013-05-12 05:09:57
Complex number cookbook
by Roquen
2013-04-24 12:47:31

2D Dynamic Lighting
by Oskuro
2013-04-17 16:46:12

2D Dynamic Lighting
by Oskuro
2013-04-17 16:45:57

2D Dynamic Lighting
by Oskuro
2013-04-17 16:23:20

Noise (bandpassed white)
by Roquen
2013-04-05 17:36:01

Noise (bandpassed white)
by Roquen
2013-04-03 16:17:38

Java Data structures
by Roquen
2013-03-29 13:21:12

Topic Request
by kutucuk
2013-03-22 21:42:01
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!
Page created in 0.069 seconds with 20 queries.