Jump to content

  • Log In with Google      Sign In   
  • Create Account


Not looping


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
3 replies to this topic

#1 Crusable   Members   -  Reputation: 590

Like
0Likes
Like

Posted 08 January 2013 - 03:40 PM

I am at school and i am just messing around and this loop will not loop:

 

 
</p><div>import java.util.Random;</div>
<div>import java.awt.*;</div>
<div>import javax.swing.JApplet;</div>
<div> </div>
<div>public class Matrix extends JApplet{</div>
<div> </div>
<div>   public void paint(Graphics g){</div>
<div>    </div>
<div>       Random rand = new Random();</div>
<div>  </div>
<div>       int width = getWidth();</div>
<div>       int height = getHeight();</div>
<div>        </div>
<div>       int num ;</div>
<div>       int posX;</div>
<div>       int posY;</div>
<div>       </div>
<div>       g.setColor(Color.black);</div>
<div>       g.fillRect(0,0,width,height);</div>
<div>        </div>
<div>       g.setColor(Color.GREEN);</div>
<div>        </div>
<div>       String matrix[] = {"a", "b", "c", "d","e","f","g","h","i","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","0","1","2","3","4","5","6","7","8","9"};</div>
<div>        </div>
<div>       </div>
<div>       for(;;){</div>
<div>           </div>
<div>           num = rand.nextInt(36);</div>
<div>           posX = rand.nextInt(width);</div>
<div>           posY = rand.nextInt(height);</div>
<div>           </div>
<div>           g.drawString(matrix[num], posX, posY);</div>
<div>        }</div>
<div>       </div>
<div>   }</div>
<div>}</div>
<div>

"C spilled his beer all over C++'s shirt. Outraged, C++ shouted, "Good god, man! Have you no class?"

"Your mother is so fat that the recursive function that was used to calculate her mass created a stack overflow"

 

 


Sponsor:

#2 BCullis   Crossbones+   -  Reputation: 1799

Like
3Likes
Like

Posted 08 January 2013 - 03:54 PM

Are you sure?

Try adding a printout to System.Out that prints the string you're trying to draw.  I'm willing to bet it's looping like mad, so much in fact that you never complete the paint method because you're stuck in the loop ;)


Hazard Pay :: FPS/RTS in SharpDX
DeviantArt :: Because right-brain needs love too

#3 Jutaris   Members   -  Reputation: 472

Like
0Likes
Like

Posted 08 January 2013 - 04:41 PM

I'm not versed in Java awt much, but I do believe you're supposed to call g.setFont before you can draw text.

 

Without seeing the context in which the paint method is called, it's hard to guess at what's going on. That for loop, however should run forever.


My Site -- My Music  -- My Ramblings -- My Game

 Basic Flying Rules:Try to stay in the middle of the air. Do not go near the edges of it. The edges of the air can be recognized by the appearance of ground, buildings, sea, trees and interstellar space. It is much more difficult to fly there.

Come join us for some friendly game dev discussions over in XNA Chat!


#4 minibutmany   Members   -  Reputation: 1303

Like
1Likes
Like

Posted 08 January 2013 - 06:32 PM

You should never put your game loop inside of your paint method, because it will never repaint the screen.

Make another method that calls the paint method ever time that loop loops using "repaint()".


Stay gold, Pony Boy.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS