Codenameone - 日历createDay()导航

时间:2017-09-21 07:17:46

标签: codenameone

我使用CN1手动编码我的应用程序(基于CN1的标准表单模板)。主要用于使用日历预约应用程序(我有理由不使用Picker)。

这是我的主要Form类

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(sidemenu)。我知道Form 3确实存在但不确定为什么它没有设法从createDay()中“到达”。我怀疑在主窗体

中围绕此代码存在问题
Calendar.createDay().pressed();
Calendar.createDay().released();
Calendar.createDay().setCommand(cmd3);

需要建议和/或帮助。

1 个答案:

答案 0 :(得分:1)

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

Calendar.createDay().pressed();
Calendar.createDay().released();
Calendar.createDay().setCommand(cmd3);

日历日按下和发布是通过actionListener来处理的,如果您使用自定义日组件,则可以通过覆盖bindDayListener()来实施,如果您使用的是addDayActionListener()默认日期按钮。一个例子是:

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

除非你需要高级别的自定义,否则我没有看到一个继承Calendar类的点。