Skip to main content
GameDev.net gamedev.net
🔒 Locked

Not looping

Started by Crusable77 Jan 8, 2013 at 9:40 PM 2 replies 1.3k views
Original Post
Crusable77
Crusable77

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

import java.util.Random;
import java.awt.*;
import javax.swing.JApplet;
public class Matrix extends JApplet{
public void paint(Graphics g){
Random rand = new Random();
int width = getWidth();
int height = getHeight();
int num ;
int posX;
int posY;
g.setColor(Color.black);
g.fillRect(0,0,width,height);
g.setColor(Color.GREEN);
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"};
for(;;){
num = rand.nextInt(36);
posX = rand.nextInt(width);
posY = rand.nextInt(height);
g.drawString(matrix[num], posX, posY);
}
}
}
BCullis
BCullis

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 (gathering dust, retained for... historical purposes)
DeviantArt :: Because right-brain needs love too (also pretty neglected these days)
FalconDragoon
FalconDragoon

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 Games -- My Music  Come join us for some friendly game dev discussions over in XNA Chat!
minibutmany
minibutmany

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.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.