Basically, I am trying to make a program that moves a "platter" one pixel to the left when the left arrow key is pressed, and one to the right when the right arrow key is pressed. Currently, nothing is drawing on my output window when I compile and run, and I am not too sure what I am doing wrong here or where exactly the code isn't doing what I want. Any help is appreciated, thank you!
import java.awt.*;
import java.net.*;
import java.util.*;
import java.applet.Applet;
public class game extends Applet
{
Thread loopThread;
boolean left = false;
boolean right = false;
int platPos = 50;
public void run()
{
Graphics g = null;
int i, j;
long startTime;
Thread.currentThread().setPriority(Thread.MIN_PRIORITY);
startTime = System.currentTimeMillis();
while (Thread.currentThread() == loopThread)
{
updatePlatter(g);
}
}
public void updatePlatter(Graphics g)
{
if(left)
{
g.setColor(new Color(255,255,255));
g.fillRect(50+platPos, 200, 100, 20);
platPos--;
g.setColor(new Color(100,100,100));
g.fillRect(50+platPos,200, 100,20);
}
if(right)
{
g.setColor(new Color(255,255,255));
g.fillRect(50+platPos,200,100,20);
platPos++;
g.setColor(new Color(100,100,100));
g.fillRect(50+platPos,200,100,20);
}
}
public boolean keyDown(Event e, int key)
{
if (key == Event.LEFT)
left = true;
if (key == Event.RIGHT)
right = true;
return true;
}
}