【问题标题】:lwuit calendar with button eventlwuit 带有按钮事件的日历
【发布时间】:2011-08-01 07:49:17
【问题描述】:

我尝试使用表单在按钮单击时显示日历,但我无法更改日期,并且非常难以找到 焦点 的位置。

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

如何更好地在按钮点击时显示和隐藏日历

【问题讨论】:

    标签: java-me calendar popup lwuit


    【解决方案1】:

    你可以使用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 添加selected and unselected 样式。

    【讨论】:

    • 我怎样才能将事件添加到日历到选定的特定日期.. 请帮助
    猜你喜欢
    • 2021-08-12
    • 1970-01-01
    • 1970-01-01
    • 2012-10-29
    • 1970-01-01
    • 2018-03-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多