Question:
java I got a error on eclipse and it wasn't underlined with red?
2013-08-19 12:09:54 UTC
Here is my code:

main class:

package Window;

import java.awt.Canvas;
import java.awt.Graphics;

import javax.swing.JFrame;

public class Game extends Canvas implements Runnable {

private static final long serialVersionUID = 1L;
long milliseconds = System.currentTimeMillis();
long fpswait = milliseconds / 32;

boolean running;

InputHandler input = new InputHandler();

static int WIDTH = 1600;
static int HEIGHT = 800;
static String TITLE = "SandBox";

static int x = 800;
static int y = 400;

boolean starting;

public static void main(String[] args) {
Game game = new Game();
JFrame frame = new JFrame();

frame.add(game);
frame.pack();
frame.setTitle(TITLE);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(WIDTH, HEIGHT);
frame.setLocationRelativeTo(null);
frame.setResizable(false);
frame.setVisible(true);

game.start();

}

public void start() {

running = true;
startmaingameloop();

}

public void stop() {

running = false;
System.exit(0);
}

public void startmaingameloop() {

while (running) {

update();

}

}

public void update() {

try {
Thread.sleep(fpswait);
repaint();

} catch (Exception e) {
e.printStackTrace();
}

}

@Override
public void run() {

}

public void paint(Graphics g) {

g.fillRect(x, y, 10, 10);

}

}

Input Handler class:

package Window;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;

public class InputHandler extends Game implements ActionListener, KeyListener{
private static final long serialVersionUID = 1L;

public InputHandler() {

addKeyListener(this);
setFocusable(true);
setFocusTraversalKeysEnabled(false);

}


public void actionPerformed(ActionEvent e) {

}

public void keyPressed(KeyEvent e) {

int c = e.getKeyCode();

if (c == KeyEvent.VK_UP) { Game.y =+ 1; }
if (c == KeyEvent.VK_DOWN) { Game.y =- 1; }
if (c == KeyEvent.VK_RIGHT) { Game.x =+ 1; }
if (c == KeyEvent.VK_LEFT) { Game.x =- 1; }

}

public void keyReleased(KeyEvent e) {

}

public void keyTyped(KeyEvent e) {

}



}
Three answers:
?
2013-08-20 17:44:59 UTC
Here put a like to my forum where I have something that you can use,

Its basic but it will get things done.

It will be up dated when I get around to it
daSVgrouch
2013-08-19 13:51:07 UTC
long milliseconds = System.currentTimeMillis();

long fpswait = milliseconds / 32;

// do you realize how long this wait would be ?
Darnental
2013-08-19 12:15:32 UTC
Please give us the full text of the error.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...