3

当我尝试运行/调试此代码时:

package ca.kianyarand.game;

import java.awt.BorderLayout;
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 / 12*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.setVisible(true);     
}

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

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

public void run(){
    while(running){
    }
}

public static void name(String []args){
    new Game().start();
}       
}

当尝试在 Java Applet 上运行/调试它时,它会出现“选择不包含小程序”,并且在与 Java 应用程序一起运行时也会出现“选择不包含主类型”。

4

0 回答 0