我正在处理我的Codename一个日历项目,其中我包含了Calendar而不是Codename one API,但是自己创建了一个自定义日历因此,当我使用for循环向日历添加日期按钮时,它将成功添加,但是它将从星期日开始的第一天开始,但是实际的日历月不是从星期日开始的,所以如何从那个受人尊敬的实际日期添加它,而且我希望当下个月开始日期按钮将继续例如,从上个月到下个月的相应链,如果当前月份在周三结束,那么下个月的第一天将从星期四开始,依此类推。所以任何人都知道如何实现这种情况?
以下是我的应用程序屏幕截图及其尊重的代码:
public class PivDisplayCalendar extends Container {
PivEventCalendar EventObject = new PivEventCalendar();
PivCalendarModel ModelObject = new PivCalendarModel();
PivCalendarDatabase DatabaseObject = new PivCalendarDatabase();
int length =31;
private ComboBox year;
private static final String[] DAYS = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
private static final String[] LABELS = {"Su", "M", "Tu", "W", "Th", "F", "Sa"};
private static final String[] MONTHS = {"January","February","March","April","May","June","July","August","September","October","November","December"};
private static final int[] YEARS = {2017,2018,2019,2020,2021,2022,2023,2024,2025,2026,2027};
public int i = 1, j=0;
public Date value = new Date();
public Object metaData;
private ArrayList<Button> allButtons = new ArrayList<Button>();
//Button newButton = new Button("");
public PivDisplayCalendar(){
super(new BoxLayout(BoxLayout.Y_AXIS));
Log.p("Calendar invoked");
Container calendarTitle = new Container(new BorderLayout(BorderLayout.CENTER_BEHAVIOR_CENTER));
Container title = new Container(new GridLayout(1,7));
Container days = new Container(new GridLayout(6, 7));
Container calendarTitleCopy = new Container(new GridLayout(1, 1));
calendarTitleCopy.setUIID("CalendarTitleCopy");
this.addComponent(calendarTitleCopy);
this.addComponent(title);
this.addComponent(days);
Button prevMonth = new Button("<");
Button nextMonth = new Button(">");
Label month = new Label(MONTHS[0]);
Label yearLabel = new Label( "2017");
calendarTitle.add(BorderLayout.WEST, prevMonth);
Container TitleLabel = FlowLayout.encloseIn(month,yearLabel);
calendarTitle.add(BorderLayout.CENTER, TitleLabel);
calendarTitle.add(BorderLayout.EAST, nextMonth);
calendarTitleCopy.add(calendarTitle);
Button dayButton= new Button();
if(UIManager.getInstance().isThemeConstant("calTitleDayStyleBool", false)) {
title.setUIID("CalendarTitleArea");
days.setUIID("CalendarDayArea");
}
for (int iter = 0; iter < DAYS.length; iter++) {
title.addComponent(createDayTitle(iter));
}
for (int iter = 1; iter < length; iter++) {
dayButton = new Button(""+iter);
/* Log.p("Getting data from Model class");
Log.p(""+DatabaseObject.ModelObject.getEventData()); */
dayButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent evt) {
Log.p("Action event triggered");
Picker datePicker = new Picker();
try{
Display.getInstance().showNativePicker(Display.PICKER_TYPE_DATE,PivDisplayCalendar.this, value, metaData);
Storage.getInstance().writeObject("Date", value);
ModelObject.setEventDate(value);
}catch(Exception e){
e.printStackTrace();
}
//Button b1 = (Button)(evt.getActualComponent());
//Log.p( b1.getText() );
}
});
allButtons.add(dayButton);
days.addComponent(dayButton);
if (iter <= 7) {
dayButton.setNextFocusUp(year);
}
}
nextMonth.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent evt) {
month.setText(MONTHS[i]);
yearLabel.setText(""+YEARS[j]);
if((i<MONTHS.length-1)){
i++;
}
else{
i=0;
j++;
}
}
});
prevMonth.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent evt) {
month.setText(MONTHS[i]);
yearLabel.setText(""+YEARS[j]);
if((i<MONTHS.length+1)){
i--;
}
else{
i=0;
j--;
}
}
});
}
protected Label createDayTitle(int day) {
String value = getUIManager().localize("Calendar" + DAYS[day], LABELS[day]);
Label dayh = new Label(value, "Label");
dayh.setEndsWith3Points(false);
dayh.setTickerEnabled(false);
return dayh;
}
}