2012-06-14 2 views
-1

"Java에서 Killer Game Programming"이라는 책을 얻었습니다. J2SE 5.0을 설치하기로되어 있었지만 J2SE는 End of Life에 있습니다. StackOverflow 및 저자와의 토론 후 JSE 7u5 인 oracle.com에서 업데이트 된 버전을 설치했습니다. JRE가 포함 된 JDK를 다운로드했습니다. 이제 NetBeans 7.1.2를 JDK 1.7과 함께 사용하고 있지만 터미널에서는 1.7.0_05라고 부릅니다. 첫 번째 프로그램은 주요 방법 없이는 실행할 수 없다는 말입니다. 설치 한 업데이트 된 버전이이 설명서의 프로그램에서 작동하지 않을 수있는 이유가 있습니까? 시도해야하는 또 다른 권장 버전이 있습니까? 아래에 전체 코드를 게시했습니다. 수정 사항이 없습니다. 이 링크에서 바로 나타납니다 http://fivedots.coe.psu.ac.th/~ad/jg/ch1/ch1.pdf 모든 오류는 기울임 꼴이며 굵게 표시됩니다.사용할 Java 버전

public class GamePanel extends JPanel implements Runnable 
{ 
    private static final int PWIDTH = 500; // size of panel 
    private static final int PHEIGHT = 400; 
private Thread animator; 
private boolean running = false; 
private boolean gameOver = false; 
// more variables, explained later 
     : 
public GamePanel() 
// for the animation 
// stops the animation 
// for game termination 
{ 
    setBackground(***Color***.white); // white background 
    setPreferredSize(new ***Dimension***(PWIDTH, PHEIGHT)); 
    // create game components 

} // end of GamePanel() 
public void addNotify() 
/* Wait for the JPanel to be added to the 
    JFrame/JApplet before starting. */ 
{ 
    ***super.addNotify();*** // creates the peer 
    startGame();   // start the thread 
} 
private void startGame() 
// initialise and start the thread 
{ 
    if (animator == null || !running) { 
    ***animator = new Thread(this);*** 
    animator.start(); 
    } 
} // end of startGame() 
public void stopGame() 
// called by the user to stop execution 
{ running = false; } 
public void run() 
/* Repeatedly update, render, sleep */ 
{ 
    running = true; 
    while(running) { 
    gameUpdate(); 
    ***gameRender();*** 
    repaint(); 
try { 
// game state is updated 
// render to a buffer 
// paint with the buffer 
Thread.sleep(20); // sleep a bit 
     } 
     catch(InterruptedException ex){} 
    } 
    System.exit(0); // so enclosing JFrame/JApplet exits 
    } // end of run() 
    private void gameUpdate() 
    { if (!gameOver) 
     // update game state ... 
    } 
    // more methods, explained later... 
} // end of GamePanel class  
+4

"컴파일하지 않는다"는 것은 무엇을 의미합니까? 컴파일하지 않는 코드를 보여줄 수 있습니까? –

+1

그래, 7.x를 사용하면 괜찮을거야. 발생하는 코드 및 특정 오류에 대한 질문에 다시 집중하십시오. – Marvo

+2

코드 또는 오류 메시지없이 ... 도움이 어렵습니다. –

답변

1

일반적으로 최신 버전으로 작업해야합니다. 때때로 "오래된"코드가 현재 예약 된 키워드를 사용하기 때문에 문제가 발생할 수 있습니다. Java 7을 사용하는 경우에도 -source 1.5-target 1.5을 사용하여 Java 1.5 용 컴파일러를 사용하도록 컴파일러를 설정할 수 있습니다. 그러나 자바 컴파일러 버전과는 다른 문제가있을 가능성이 큽니다.

오류 메시지없이 설명이 실제 문제를 해결하기에는 너무 일반적입니다.

+0

오류는 단지 "주된 방법없이 컴파일 할 수 없다"는 말이다. 나는 저자 웹 사이트에서 바로 가져 갔기 때문에 이상하다. –

1

좋습니다. 알겠습니다. 전체 코드가 아니라 예제 또는 코드의 골격입니다. 도망 가야하지 않아. 그저 이해를 돕기로되어 있습니다.