2015-01-19 2 views
-4

그래서 우리는 게임에 대해 아바타를 만들고 있으며 우리는 이미 Avatar 클래스 파일로 아바타를 만들었습니다. 문제는 클래스 파일 Game에서 Avatar를 인스턴스 변수로 선언하는 데 어려움이 있습니다. 다음과 같이 코드는 다음과 같습니다개체 변수를 선언하여 개체를 참조하십시오.

public class Game extends JApplet { 
    private static final long serialVersionUID = 1L; 
    public static final long WIDTH = 800; 
    public static final long HEIGHT = 600; 

    // Declare an instance variable to reference your Avatar object 

    public @Override void init() { 
     // Store an instantiated Avatar into the instance variable 
     setSize(new Dimension(WIDTH, HEIGHT)); 
     getContentPane().setBackground(Color.BLUE); 
    } 

    public @Override void paint(Graphics g) { 
     super.paint(g); // Call the JAplet paint method (inheritance) 
     // Call the draw method in your Avatar class 
    } 
} 
+1

당신은 오라클의 사이트에 튜토리얼 경로를 따라 적이 있습니까? –

+3

귀하의 질문은 무엇입니까? – immibis

+2

아바타의 인스턴스 변수를 선언하는 것을 막는 것은 무엇입니까? 미안, 네가 묻는 걸 정말로 볼 수 없어. –

답변

0

당신은 시도 할 수 : 이것처럼

:

public class Game extends JApplet { 
private static final long serialVersionUID = 1L; 
public static final long WIDTH = 800; 
public static final long HEIGHT = 600; 

// Declare an instance variable to reference your Avatar object 
private Avatar avatar; 


public @Override void init() { 
    // Store an instantiated Avatar into the instance variable 
    avatar = new Avatar(); 

    setSize(new Dimension(WIDTH, HEIGHT)); 
    getContentPane().setBackground(Color.BLUE); 
} 

public @Override void paint(Graphics g) { 
    super.paint(g); // Call the JAplet paint method (inheritance) 
    // Call the draw method in your Avatar class 

    avatar.draw(); //replace "draw" with method you want to invoke :) 
    } 
} 
관련 문제