Codenameone-日历createDay()导航

Codenameone-日历createDay()导航,codenameone,Codenameone,我用CN1(基于CN1的标准表单模板)手工编写了我的应用程序。主要用于在约会应用程序中使用日历(我有理由不使用Picker) 这是我的主要课程 public class celebriesta { private Form current; private Resources theme; private Form home; public void init(Object context) { theme = UIManager.initFirstTheme("/theme");

我用CN1(基于CN1的标准表单模板)手工编写了我的应用程序。主要用于在约会应用程序中使用日历(我有理由不使用Picker)

这是我的主要课程

public class celebriesta {

private Form current;
private Resources theme;

private Form home;

public void init(Object context) {
    theme = UIManager.initFirstTheme("/theme");

    // Enable Toolbar on all Forms by default
    Toolbar.setGlobalToolbar(true);

    // Pro only feature
    Log.bindCrashProtection(true);
}

public void start() {
    if (current != null) {
        current.show();
        return;

    }
        home = new Form("Home", BoxLayout.y());
        mainCalendar Calendar = new mainCalendar();
        home.addComponent(Calendar);
        Calendar.setUIID("Calendar");


    //Create Form1 and Form2 and set a Back Command to navigate back to the home Form        
    Form form1 = new Form("Form1");
    setBackCommand(form1);
    Form form2 = new Form("Form2");
    setBackCommand(form2);
    Form form3 = new Form("Form3");
    setBackCommand(form3);


    //Add navigation commands to the home Form

    NavigationCommand cmd1 = new NavigationCommand("Form1");
    cmd1.setNextForm(form1);
    home.getToolbar().addCommandToSideMenu(cmd1);

    NavigationCommand cmd2 = new NavigationCommand("Form2");
    cmd2.setNextForm(form2);
    home.getToolbar().addCommandToSideMenu(cmd2);

    NavigationCommand cmd3 = new NavigationCommand("Form3");
    cmd3.setNextForm(form3);
    Calendar.createDay().pressed();
    Calendar.createDay().released();
    Calendar.createDay().setCommand(cmd3);

    //Add Edit commands to the home Form context Menu
    Image im = FontImage.createMaterial(FontImage.MATERIAL_MODE_EDIT, UIManager.getInstance().getComponentStyle("Command"));
    Command edit = new Command("", im) {

        @Override
        public void actionPerformed(ActionEvent evt) {
            System.out.println("Editing");
        }
    };
    home.getToolbar().addCommandToRightBar(edit);
    home.show();
}

protected void setBackCommand(Form f) {
    Command back = new Command("") {

        @Override
        public void actionPerformed(ActionEvent evt) {
            home.showBack();
        }

    };
    Image img = FontImage.createMaterial(FontImage.MATERIAL_ARROW_BACK, UIManager.getInstance().getComponentStyle("TitleCommand"));
    back.setIcon(img);
    f.getToolbar().addCommandToLeftBar(back);
    f.getToolbar().setTitleCentered(true);
    f.setBackCommand(back);
}

public void stop() {
    current = getCurrentForm();
}

public void destroy() {
}}
我已经相应地重写了Calendar类

public class mainCalendar extends Calendar { @Override
    protected Button createDay(){ Button day = new Button();
    Image im = FontImage.createMaterial(FontImage.MATERIAL_MODE_EDIT, UIManager.getInstance().getComponentStyle("Command"));
    day.setIcon(im);

    return day;

   }     
    @Override
protected void updateButtonDayDate(Button dayButton, int currentMonth, int day) {
    //Customize day values 
    dayButton.setText("" +day);
}}
主窗体设法进入窗体1和窗体2(侧菜单)。我知道表单3确实存在,但不确定为什么无法从createDay()访问表单3。我怀疑这段代码在主窗体中的某个地方出错了

Calendar.createDay().pressed();
Calendar.createDay().released();
Calendar.createDay().setCommand(cmd3);
需要建议和/或帮助。

查看创建自定义日历日组件的。您不需要以下代码:

Calendar.createDay().pressed();
Calendar.createDay().released();
Calendar.createDay().setCommand(cmd3);
日历日的按下和释放通过
actionListener
处理,如果使用自定义日组件,则可以通过覆盖
bindDayListener()
来实现;如果使用默认日按钮,则可以通过覆盖
addDayActionListener()
来实现。例如:

Calendar.addDayActionListener(evt -> {
    //show your next form here
});

除非您需要高级定制,否则我认为没有必要将Calendar类子类化。

您的问题是什么?谢谢。我再试试你的建议。代码是有效的。我的代码有错误&也是因为我没有相应地更新CN1库。愚蠢的我…@buzzin_hornets很高兴它起作用了…请给出答案顺便说一句,正确的Java编码标准是从变量名开始使用小写字母,从类名开始使用大写字母,从方法/函数名开始使用小写字母
mainCalendar
类应变为
mainCalendar
Calendar
变量应为
Calendar
cal
。常量应全部大写