标题栏只显示我点击运行后,框架不工作.... 这是我的代码 我不知道发生了什么事情! 有人可以帮我吗?只有标题栏显示,JFrame没有显示
import java.awt.Canvas;
import javax.swing.JFrame;
public class Display extends Canvas implements Runnable {
private static final long serialVersionUID = 1L;
public static final int WIDTH = 800;
public static final int HEIGH = 600;
public static String TITLE = "3D Game";
private Thread thread;
private boolean running = false;
private void start(){
if(running) return;
running = true;
thread = new Thread();
thread.start();
System.out.println("Working");
}
private void stop(){
if(!running)
return;
running = false;
try{
thread.join();
}catch (Exception e){
e.printStackTrace();
System.exit(0);
}
}
public void run(){
while(running){
}
}
public static void main(String[] args){
Display game = new Display();
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();
}
}
您loop'同时,运行免费的,这意味着它会消耗所有的CPU周期,把你的UI停顿(如在UI线程没有' t得到一个机会跑) – MadProgrammer