开发者

lwuit calendar with button event

开发者 https://www.devze.com 2023-03-24 20:48 出处:网络
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 .

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);
       c开发者_JS百科al.show();
    }

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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消