lwuit日历与按钮事件 [英] lwuit calendar with button event

查看:143
本文介绍了lwuit日历与按钮事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在按钮点击时使用表单显示日历,但我无法更改日期,非常难以找到焦点

i tried to show the calendar on button click using form but i'm unable to change the date and very much struggled to find where the focus .

    ...
    Button mdate=new Button("change date");
    mdate.addActionListener(this);
    ...
    public void actionPerformed(ActionEvent ae) {
       Form cal= new Form();
       com.sun.lwuit.Calendar c =new com.sun.lwuit.Calendar();
       c.setFocus(true);
       c.addActionListener(this);
       cal.addComponent(c);
       cal.show();
    }

如何以更好的方式显示和隐藏按钮上的日历

how to show and hide calendar on button click in a better way

推荐答案

更好地使用 Dialog 您可以在表单中轻松处理。无需显示其他表单。请参阅下面的示例代码

Better you can use Dialog (like pop up) instead of Form. You can easily dispose within a Form. No need to show another form. See the below sample code,

Button button = new Button("Click me");
form.addComponent(button);
button.addActionListener(new ActionListener() {

    public void actionPerformed(ActionEvent ae) {
        final Dialog cal = new Dialog();
        final com.sun.lwuit.Calendar c = new com.sun.lwuit.Calendar();
        c.setFocus(true);
        c.addActionListener(this);
        cal.addComponent(c);
        cal.addCommand(new Command("Cancel") {

         public void actionPerformed(ActionEvent evt) {
              cal.dispose();
            }
        });
      c.addActionListener(new ActionListener() {
         public void actionPerformed(ActionEvent evt) {
            System.out.println("Selected date :: " + c.getDate().toString())
        }
     });
    cal.show(20, 20, 20, 20, true, false);
    }
});

并为 Calendar 喜欢 CalendarSelectedDay CalendarDate 。同时为添加已选定和未选择的样式, ComboBox

And add the selected and unselected style for Calendar like CalendarSelectedDay, CalendarDate. Also add the selected and unselected style for ComboBox.

这篇关于lwuit日历与按钮事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆