且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在lwuit TextField或comboBox中添加日历

更新时间:2023-01-25 19:15:57

您是说要在组合框值的末尾添加日历组件的选定日期还是在文本框中显示选定日期? 如果是这样,则下面的代码在文本框中显示日历组件的选定日期:

Do u mean that you want to add the selected date of calendar component at the end of combobox values or to show the selected date in textbox? If so, then below code shows the selected date of calendar component in textbox:

Button cal = new Button("Calendar");  // button for calendar
cal.addActionListener(new ActionListener() {  // define action for button

                //  action listener to show the calendar container
                public void actionPerformed(ActionEvent ae) {
                    final Form calFrame = new Form();
                    final Calendar cal = new Calendar();
                    calFrame.setScrollable(true);
                    calFrame.setSmoothScrolling(true);
                    calFrame.setIsScrollVisible(true);
                    cal.addActionListener(new ActionListener() {

                        public void actionPerformed(ActionEvent ae) {
                            txtDate.setText(cal.getDate());  // textfield in which date should be set
                            mainForm.showBack();  // main form to show back after calender disappears
                        }
                    });

                    calFrame.addComponent(cal);
                    calFrame.show();
                }
});
            mainForm.addComponent(calButton); // add calendar button to main form

此代码将在您的主窗体中添加一个日历按钮,并将在文本字段(此处称为txtDate)中显示所选日期. 如果要在组合值中添加日期,则可以在向量或组合组件向量的列表中添加选定的日期. 如果这不是您想要的,请简要说明您实际想要做的事情.

this code will add one calendar button to your main form and will display the selected date in textfield (here named txtDate). If you want to add date in combo values, you can add the selected date in the vector or list of the combo component's vector. If this is not what you want, kindly briefly explain what you want actually to do.