- No Greenfoot -
Hello dear programmers,
I have a bug in my program and it'S hard for me to solve it. If I start my application the frame opens itself, but then the program doesn't update anymore. THis is the code of the main class:
As you can see, there are two System.out.println invokings commented. If I uncomment them everything works perfectly. I can move my character and so on. But if the System.out.println invokings aren't there the program doesn't move! What's the fault? Why does the program only realizes, that it should do something if I have the out.printlns there?
import javax.swing.JFrame;
/**
* @author: Paul Maximilian Bittner
*
* This class controls the speed and performance of the program.
*/
public class Control implements Runnable
{
/**Fields**/
public final static int SPEEDMAX = 1000;
public final static String name = "Spiel";
/**variables**/
private static Control me;
private static Frame frame;
private static Thread mainThread;
private boolean running, acting;
private int speed = 1;
private Control(){
running = true;
acting = true;
}
public void run() {
while(running){
//System.out.println("running");
if(acting){
//System.out.println("acting");
frame.refresh();
frame.repaint();
try{
mainThread.sleep(SPEEDMAX - speed);
}catch(Exception e){}
}
}
}
public static void main(String args[]) {
me = new Control();
me.frame = new Frame(name);
me.frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
me.frame.setResizable(false);
me.frame.setSize(800, 600);
me.frame.setVisible(true);
mainThread = new Thread(me);
mainThread.start();
}
}



