2011-01-28 3 views
1

다른 클래스의 주 화면에 텍스트를 추가하려고하는데 MainScreen을 확장하는 클래스의 화면 개체를 전달하려고했지만 뭔가를 추가하려고 할 때 Permission denied 예외가 발생합니다. 다른 클래스의 메인 화면에 텍스트를 추가하는 올바른 방법은 무엇입니까?BlackBerry에서 다른 클래스의 기본 화면을 수정 하시겠습니까?

편집 :

공공 TheMainClass이 확장 MainScreen {

public TheMainClass() 
{ 
    LabelField labelField = new LabelField("Hello"); 
    add(labelField); 

} } 

공공 OtherClass {

public OtherClass(){ 

    // i want to add new LabelField here to say for example "World!" to the 
    // TheMainClass screen 
} 

} 
+1

몇 가지 코드를 보여줄 수 있습니까? 일반적으로 공개 메소드 또는 2 개를 메인 스크린에 노출 시키면 다른 클래스가 내용을 변경할 수 있지만 보지 않고 코드를 말하기는 어렵습니다. –

+0

확실히, 질문에 샘플 코드를 추가했습니다. – Jimmy

답변

2

이 작업을 수행하는 방법에는 여러 가지가 있습니다, 하나는 다음과 같습니다

public TheMainClass extends MainScreen { 
    public TheMainClass() { 
     LabelField labelField = new LabelField("Hello"); 
     add(labelField); 
    } 
} 

public OtherClass { 

    public addLabelTo(Screen aScreen) { 
     aScreen.add(new LabelField("World!")); 
    } 
} 

TheMainClass theMainClass = new TheMainClass(); 
OtherClass otherClass = new OtherClass; 

otherClass.addLabelTo(theMainClass); 

물론 addLabelTo에 대한 호출이 이벤트 스레드에서 실행되는지 확인해야합니다.

관련 문제