带按钮事件的 lwuit 日历

发布于 2024-11-27 04:17:34 字数 466 浏览 1 评论 0原文

我尝试使用表单在按钮单击时显示日历,但我无法更改日期,并且很难找到焦点

    ...
    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();
    }

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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

巾帼英雄 2024-12-04 04:17:34

更好的是,您可以使用Dialog(如弹出窗口)而不是表单。您可以轻松地在 Form 中进行处理。无需显示另一种形式。请参阅下面的示例代码,

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 添加选中和未选中的样式,例如 CalendarSelectedDayCalendarDate。还为 ComboBox选中和未选中 样式代码>.

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);
    }
});

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文