I've wrote a game. But when I compile, and run the main method, there is an error, saying:
No main methods found or something like that.
I have one class called Game.java, which is supposed to be the main one, and gameLoop.java.
For unknown reasons, gameLoop doesnt want to compile.
This is my Game.java class:
import java.applet.Applet;
import java.awt.Graphics;
public class Game extends gameLoop{
public void init(){
setSize(854,480);
Thread th = new Thread(this);
th.start();
offscreen = createImage(854,480);
d = offscreen.getGraphics();
addKeyListener(this);
}
public void paint(Graphics g){
d.clearRect(0,0,854,480);
d.drawOval(x,y,20,20);
g.drawImage(offscreen,0,0,this);
}
public void update(Graphics g){
paint(g);
}
}
And this is my gameLoop.java class:
import java.applet.Applet;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.event.KeyListener;
public class gameLoop extends Applet implements Runnable, KeyListener{
public int x, y;
public Image offscreen;
public Graphics d;
public boolean up, down, left, right;
public void run(){
x = 100;
y = 100;
while(true){
if (left == true){
x--;
}
if (right == true){
x++;
}
if (up == true){
y--;
}
if (down == true){
y++;
}
repaint();
try {
Tread.sleep(20);
}
catch (InterruptedException e) {
e.printStackTrace();
}
}
}
public void keyPressed(KeyEvent e){
if (e.getKeyCode() == 37){
left = true;
}
if (e.getKeyCode() == 38){
up = true;
}
if (e.getKeyCode() == 39){
right = true;
}
if (e.getKeyCode() == 40){
down = true;
}
public void keyReleased(KeyEvent e){
if (e.getKeyCode() == 37){
left = false;
}
if (e.getKeyCode() == 38){
up = false;
}
if (e.getKeyCode() == 39){
right = false;
}
if (e.getKeyCode() == 40){
down = false;
}
}
public void keyTyped(KeyEvent e) {}
}
If I could get any advice from proficient programmers, better than me, I would appreciate your help.