javaMe如何在其他类中引用主类的非成员方法,且改类也不能被实例
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;
import com.sun.lwuit.Display;
public class Main extends MIDlet {
public static Main disp; // 引用MIDlet的Display 对象
public Main() {
Display.init(this);
disp=this;
}
protected void destroyApp(boolean arg0) throws MIDletStateChangeException {
}
protected void pauseApp() {
}
protected void startApp() throws MIDletStateChangeException {
ControlContainer.getInstance().getLoadForm().show();
}
public void close(){
try {
destroyApp(false);
notifyDestroyed();
}
catch (MIDletStateChangeException e) {
e.printStackTrace();
}
}
}
调用的类如下:
package com.peptalk.kaikai.client.ui;
import javax.microedition.midlet.MIDletStateChangeException;
import com.sun.lwuit.Button;
import com.sun.lwuit.Container;
import com.sun.lwuit.Dialog;
import com.sun.lwuit.Display;
import com.sun.lwuit.Label;
import com.sun.lwuit.events.ActionEvent;
import com.sun.lwuit.events.ActionListener;
import com.sun.lwuit.layouts.BorderLayout;
import com.sun.lwuit.layouts.GridLayout;
public class ExitMessageDialog extends Dialog{
public ExitMessageDialog(){
this.setLayout(new BorderLayout());
Label titleLabel=new Label("是否退出系统!");
titleLabel.setAlignment(Label.CENTER);
this.addComponent("North",titleLabel);
Container centerContainer=new Container(new GridLayout(2,1));
Button subButton=getButton("确定");
subButton.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent evt) {
Main.disp.close();
}
});
Button resetButton=getButton("取消");
resetButton.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent evt) {
ExitMessageDialog.this.dispose();
}
});
centerContainer.addComponent(subButton);
centerContainer.addComponent(resetButton);
相关新闻>>
- 发表评论
-
- 最新评论 更多>>