java主类怎么取消_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);

this.addComponent("Center",centerContainer);

this.setTransitionInAnimator(BaseUiData.getInstance().getSlideDown());

this.setTransitionOutAnimator(BaseUiData.getInstance().getSlideDown());

}

private Button getButton(String title){

Button b=new Button(title);

b.getSelectedStyle().setBgColor(0x54321);

b.setAlignment(Button.CENTER);

return b;

}

public void setShow(){

int LeftSpace=(Display.getInstance().getDisplayWidth()-100)/2;

int TopSpace=(Display.getInstance().getDisplayHeight()-100)/2;

this.show(TopSpace,TopSpace,LeftSpace,LeftSpace, true);

}

}

这个很重要:  disp=this;

通过这种方法引用:   Main.disp.close();            非常巧妙!很佩服自己

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值