Modifying the main screen from different class on BlackBerry?
I'm trying to add text to the main screen from other class, I tried 开发者_开发百科to pass screen object from the class that extend MainScreen but when I try to add something to it, it gives me Permission denied exception. What is the right way to add for example text filed to the main screen from different class?
Edit:
public TheMainClass extends MainScreen {
public TheMainClass() { LabelField labelField = new LabelField("Hello"); add(labelField); } }
public OtherClass{
public OtherClass(){ // i want to add new LabelField here to say for example "World!" to the // TheMainClass screen } }
There are many ways to do this, one would be:
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);
Of course you will have to ensure that the call to addLabelTo is executed on the event thread.
精彩评论