javaMe自定义菜单
来源:技术人生 责任编辑:栏目编辑 发表时间:2013-07-01 09:20 点击:次
public interface IMenuItemListener {
public abstract void setTask();
public abstract void setTask();
}
z自定义的抽象事件,因为接口可以当成对象来使用,只不过自使用时需重写其中 的抽象方法。自定义的菜单响应事件接口。
import com.sun.lwuit.Button;
import com.sun.lwuit.Dialog;
import com.sun.lwuit.Image;
import com.sun.lwuit.events.ActionEvent;
import com.sun.lwuit.events.ActionListener;
public class IMenuItem extends Button{
private IMenuItemListener menuItemListener=null;
public IMenuItem(){
super();
run();
}
public IMenuItem(String title){
super(title);
run();
}
public IMenuItem(Image icon){
super(icon);
run();
}
public IMenuItem(String text, Image icon){
super(text,icon);
run();
}
private IMenuItemListener menuItemListener=null;
public IMenuItem(){
super();
run();
}
public IMenuItem(String title){
super(title);
run();
}
public IMenuItem(Image icon){
super(icon);
run();
}
public IMenuItem(String text, Image icon){
super(text,icon);
run();
}
private void run(){
this.getStyle().setBorder(null);
this.getPressedStyle().setBorder(null);
this.getSelectedStyle().setBorder(null);
this.getPressedStyle().setBgColor(0X53123);
this.getSelectedStyle().setBgColor(0Xbcbcbc);
this.getStyle().setMargin(0, 0, 0,0);
this.getSelectedStyle().setMargin(0, 0,0,0);
this.getPressedStyle().setMargin(0, 0,0,0);
this.setTextPosition(Button.LEFT);
this.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent evt) {
Dialog dialog=(Dialog)((Button)evt.getSource()).getComponentForm();
if(dialog!=null)
dialog.dispose(); //释放所在的资源
if(menuItemListener!=null)
menuItemListener.setTask();
}
});
}
public void addMenuItemListener(IMenuItemListener Itemlistener){
menuItemListener=Itemlistener;
}
}
this.getStyle().setBorder(null);
this.getPressedStyle().setBorder(null);
this.getSelectedStyle().setBorder(null);
this.getPressedStyle().setBgColor(0X53123);
this.getSelectedStyle().setBgColor(0Xbcbcbc);
this.getStyle().setMargin(0, 0, 0,0);
this.getSelectedStyle().setMargin(0, 0,0,0);
this.getPressedStyle().setMargin(0, 0,0,0);
this.setTextPosition(Button.LEFT);
this.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent evt) {
Dialog dialog=(Dialog)((Button)evt.getSource()).getComponentForm();
if(dialog!=null)
dialog.dispose(); //释放所在的资源
if(menuItemListener!=null)
menuItemListener.setTask();
}
});
}
public void addMenuItemListener(IMenuItemListener Itemlistener){
menuItemListener=Itemlistener;
}
}
/**********自定义的菜单项继承Button***********/
import java.util.Vector;
import com.peptalk.kaikai.client.ui.BaseUiData;
import com.sun.lwuit.Command;
import com.sun.lwuit.Component;
import com.sun.lwuit.Dialog;
import com.sun.lwuit.Display;
import com.sun.lwuit.Image;
import com.sun.lwuit.events.ActionEvent;
import com.sun.lwuit.events.ActionListener;
import com.sun.lwuit.layouts.BoxLayout;
import com.sun.lwuit.Command;
import com.sun.lwuit.Component;
import com.sun.lwuit.Dialog;
import com.sun.lwuit.Display;
import com.sun.lwuit.Image;
import com.sun.lwuit.events.ActionEvent;
import com.sun.lwuit.events.ActionListener;
import com.sun.lwuit.layouts.BoxLayout;
public class IMenu extends Command{
private int height=0;
private int width=0;
private Vector vec=new Vector();
private Dialog dialog=null;
private BoxLayout lay=new BoxLayout(BoxLayout.Y_AXIS);
private boolean orgion=RIGHT;
public static final boolean LEFT=false;
public static final boolean RIGHT=true;
public IMenu(String title){
super(title);
dialog=new Dialog(){
public void menuDisplose() { //重写按键释放方法
this.dispose();
}
};
dialog.setTransitionInAnimator(BaseUiData.getInstance().getSlideLeft());
d
private int height=0;
private int width=0;
private Vector vec=new Vector();
private Dialog dialog=null;
private BoxLayout lay=new BoxLayout(BoxLayout.Y_AXIS);
private boolean orgion=RIGHT;
public static final boolean LEFT=false;
public static final boolean RIGHT=true;
public IMenu(String title){
super(title);
dialog=new Dialog(){
public void menuDisplose() { //重写按键释放方法
this.dispose();
}
};
dialog.setTransitionInAnimator(BaseUiData.getInstance().getSlideLeft());
d
相关新闻>>
- 发表评论
-
- 最新评论 更多>>