程序在Eclipse中立即终止

时间:2014-12-01 18:42:09

标签: java eclipse terminate

我正在eclipse中创建一个java程序但是每当我尝试运行它时它会立即终止请帮助。在它所说的java位置旁边的控制台中,它终止了

主要代码:

package com.revert.main;

import java.awt.Canvas;

public class Game extends Canvas implements Runnable {

    private static final long serialVersionUID = -2457117434114507933L;

    public static final int WIDTH = 640, HEIGHT = WIDTH /12 * 9;
    private Thread thread;
    private boolean running = false;

    public Game(){
        new Window(WIDTH, HEIGHT, "Death By Block", this);
    }


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

    public synchronized void stop(){
            try{
                thread.join();
                running = false;
            }catch(Exception e){

                e.printStackTrace();

            }
        }


    public void run(){
    long lastTime = System.nanoTime();
    double amountOfTicks = 60.0;
    double ns = 1000000000 / amountOfTicks;
    double delta = 0;
    long timer = System.currentTimeMillis();
    int frames = 0;
    while(running){
        long now = System.nanoTime();
        delta += (now - lastTime) / ns;
        lastTime = now;
        while(delta >= 1){
            tick();
            delta--;
        }
        if(running)
            render();
        frames++;

        if(System.currentTimeMillis() - timer > 1000){
            timer += 1000;
            System.out.println("FPS: " + frames);
            frames = 0;
        }
    }
    stop();


        }

    private void tick(){



}
 private void render(){

    }





    public static void main(String args[]){



}
}

窗口代码:     package com.revert.main;

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

import javax.swing.JFrame;

public class Window extends Canvas {

    private static final long serialVersionUID = 5224458545146664877L;
    public Window(int width, int height, String title, Game game){
        JFrame frame = new JFrame(title);

        frame.setPreferredSize(new Dimension(width, height));
        frame.setMinimumSize(new Dimension(width, height));
        frame.setMaximumSize(new Dimension(width, height));

        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setResizable(false);
        frame.setLocationRelativeTo(null);
        frame.add(game);
        frame.setVisible(true);
        game.start();


    }

}

1 个答案:

答案 0 :(得分:0)

试试这个

public static void main(String args[]) {
    new Game();
}