이 프로그램이 작동하지 않는 이유는 무엇입니까? 내가 스레드를 배우려고 노력하고있어스레드가 실행되지 않고 jframe setresizeable이 작동하지 않는 이유
package eu.inmensia.learn;
import java.awt.Canvas;
import java.awt.Dimension;
import javax.swing.JFrame;
public class Client extends Canvas implements Runnable {
private static final long serialVersionUID = 1L;
public static final int WIDTH = 300;
public static final int HEIGHT = WIDTH/16 * 9;
public static final short SCALE = 3;
private Thread thread;
private JFrame frame = new JFrame();
private boolean running = false;
public Client() {
Dimension size = new Dimension(WIDTH * SCALE, HEIGHT * SCALE);
setPreferredSize(size);
}
public synchronized void start() {
running = true;
thread = new Thread("display");
thread.start(); // start the thread
}
public synchronized void stop() {
running = false;
try{
thread.join(); // end the thread
}catch(InterruptedException e){ e.printStackTrace(); }
}
public void run() {
while(running){
System.out.println("Running...");
}
}
public static void main(String[] args) {
Client client = new Client();
client.frame.setResizeable(false);
client.frame.setTitle("Program test");
client.frame.add(client);
client.frame.pack();
client.frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
client.frame.setLocationRelativeTo(null);
client.frame.setVisible(true);
client.start();
}
}
(그것은 "실행 ..."인쇄되지 않습니다), 그리고 가장 열심히, 일이 내가 배운없는 경우는 하나입니다. OOP 난 그냥 당신이 무슨 일을하는지 알고 희망
new Thread(this)
이의 xD 때문에
new Thread("display");
변경 그것의
초 나를 이길이 도움말을 희망
을! 1 + –
고마워, 이제 알았어! 그냥 그것을 잊어 버렸습니다. (PS. 새로운 스레드 (이 "디스플레이")로 변경 했으므로 작동합니다. –