lwuit calendar with button event

浪尽此生 提交于 2019-12-24 18:13:18

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/6895548/lwuit-calendar-with-button-event

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!