#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    1
    Rep Power
    0

    Help with a few errors( New to Java)


    Im attempting to code a game in java but i keep getting these errors, could someone assist me?

    Code:

    package game;

    import java.awt.Canvas;
    import java.awt.Dimension;

    import javax.swing.JFrame;

    public class game extends Canvas implements Runnable{

    private static final long serialVersionUID = 1L;

    public static final int WIDTH = 160;
    public static final int HEIGHT = WIDTH/ 2*9;
    public static final int SCALE = 3;
    public static final String NAME = "Game";

    private JFrame frame;

    public boolean running = false;

    public game(){
    setMinimumSize(new Dimension(WIDTH*SCALE, HEIGHT*SCALE));
    setMaximumSize(new Dimension(WIDTH*SCALE, HEIGHT*SCALE));
    setPreferredSize(new Dimension(WIDTH*SCALE, HEIGHT*SCALE));
    frame = new JFrame(NAME);

    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setLayout(new BorderLayout());

    frame.add(this, BorderLayout.CENTER);
    frame.pack();

    frame.setResizable(false);
    frame.setLocationRelativeTo(null);
    frame.setVisable(true);
    }

    public synchronized void start(){
    new Thread(this).start();
    running = true;
    }

    public synchronized void stop(){
    running = false;
    }

    public void run() {
    long lastTime = System.nanoTime();
    double nsPerTick = 1000000000D/60D;

    int frame = 0;
    int ticks = 0;

    long lastTimer = System.currentTimeMillis();
    double delta = 0;

    while (running){
    long now = system.nanoTime();
    delta += (now - lastTime)/nsPerTick;
    lastTime = now;
    boolean shouldRender = true;

    while (delta >= 1) {
    tick++;
    tick();
    delta -= 1;
    shouldRender = true;
    }
    Thread.sleep(2);
    if(shouldRender){
    frames++;
    render();

    }


    if (System.currentTimeMillis() - lastTimer >= 1000) {
    lastTimer += 1000;
    System.out.printIn(frames +*,* + ticks);
    frames = 0;
    ticks = 0;

    }

    }

    }

    public void tick(){

    }

    public void render(){

    }

    public static void main(String[] args){
    new game().start();

    }


    }

    Error:
    Exception in thread "main" java.lang.Error: Unresolved compilation problems:
    BorderLayout cannot be resolved to a type
    BorderLayout cannot be resolved to a variable
    The method setVisable(boolean) is undefined for the type JFrame
    system cannot be resolved
    tick cannot be resolved to a variable
    Syntax error, insert ";" to complete Statement
    frames cannot be resolved to a variable
    Syntax error on tokens, Expression expected instead

    at game.game.<init>(game.java:28)
    at game.game.main(game.java:98)
  2. #2
  3. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,711
    Rep Power
    347
    Please edit your post and wrap the code in code tags.

    Can you post the full text of the error messages that show where the errors are located in the source and better text for the error messages? The error messages summary you posted doesn't give enough information.


    The message should show the source with a ^ under the location of the error.
    Here is a sample from the javac compiler:
    Code:
    TestSorts.java:138: cannot find symbol
    symbol  : variable var
    location: class TestSorts
             var = 2;
             ^
  4. #3
  5. Lord of the Dance
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Oct 2003
    Posts
    3,632
    Rep Power
    1945
    Regarding BorderLayout: import the class similar to what had been done with JFrame.

    Regarding setVisable(): look up the correct spelling in the Java JFrame documentation.

IMN logo majestic logo threadwatch logo seochat tools logo