Hello!
I am a beginner java programmer and a couple of days ago i started programming again(i had kinda like a break for a while). So yesterday when i got bored i just started making a random game. It is supposed to be a square that moves to random locations but i *ed up somewhere. The square wont move and im not sure if it is because the updating of the screen if weird or just my other code. Im really new to making games and i have just started learning so the code will be bad. If there is any like really weird code in there it might be because i changed and tried alot of things when trying to fix it. So have i just made a small mistake or is it a big failure that i should delete and work on when i get better? This is just a thing i started making when i was bored so I dont really care about it and its mostly a test. Here is the code:
First class:

Also tell me if i should do something wrong!(Remember im really new to making games)

February 14th, 2013, 12:47 PM

Norm

Re: Java game problem! Square wont move

Have you tried debugging the code by adding some printlns to show when and where the location of the square is changed?

February 14th, 2013, 12:55 PM

albin1228

Re: Java game problem! Square wont move

Quote:

Originally Posted by Norm

Have you tried debugging the code by adding some printlns to show when and where the location of the square is changed?

I think I know what you mean and no i have not tried that. I will try it now but if someone got a quicker answer please tell me!

February 14th, 2013, 01:03 PM

Norm

Re: Java game problem! Square wont move

There are several things you need to find out about what the code is doing. One way of debugging is by adding println statements. Another is to use an interactive debugger. I have to use the println method with my simple IDE

February 14th, 2013, 01:13 PM

albin1228

Re: Java game problem! Square wont move

Well I am getting closer to solving my problem! First of all i was stupid enough to not give the Thread object the location of the method run. So i wrote:
t1 = new Thread();
Instead of:
t1 = new Thread(this);

--- Update ---

Now when i start the program the square is just in a random position. Wow this code is bad!

February 14th, 2013, 01:19 PM

Norm

Re: Java game problem! Square wont move

You need to tell the jvm to call the paint() method when the shape's position has changed so it will be drawn at the new location. The repaint() method does that.

February 14th, 2013, 01:22 PM

albin1228

Re: Java game problem! Square wont move

Was trying stuff without it... -.- Thank you for the respons!

--- Update ---

And btw i know that it will only move on the x axis and will fix that! Thank you guys for replying!