我的java程序没有创建窗口但没有语法错误

时间:2016-03-06 20:13:48

标签: java

我在为游戏创建窗口时遇到了问题:

import java.awt.Canvas;

public class game extends Canvas implements Runnable {

    /**
     * 
     */
    private static final long serialVersionUID = -2865542191528057205L;

    public static final int WIDTH = 640, HEIGHT = WIDTH /12*9;

    public game(){
        new window(WIDTH, HEIGHT, "Lets Build a game!", this);
    }

    public synchronized void start(){


    }

    public void run(){

    }

    public static void main(String args[]){



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

import javax.swing.JFrame;

public class window extends Canvas{

    /**
     * 
     */
    private static final long serialVersionUID = 1523596471284190399L;

    public window(int width, int height, String title, game game){
        JFrame frame = new JFrame(title);

        frame.setPreferredSize(new Dimension(width, height));
        frame.setMaximumSize(new Dimension(width, height));
        frame.setMinimumSize(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)

您需要在main方法中添加一些内容。