gpt4 book ai didi

java - Codename 一个日期选择器问题

转载 作者:行者123 更新时间:2023-11-30 02:34:56 32 4
gpt4 key购买 nike

我创建了一个自定义日历,每当我单击日历按钮时,我都会尝试调用选择器,但它对我不起作用,以下是我的应用程序代码,该代码无法正常工作。那么我如何修改此代码以便能够从 ActionEvent 调用选取器?

    public class PivDisplayCalendar extends Container {


int length =37;
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 ArrayList<Button> allButtons = new ArrayList<Button>();
//Button newButton = new Button("");

public PivDisplayCalendar(){

super(new BoxLayout(BoxLayout.Y_AXIS));
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(">");
SpanLabel monthYear = new SpanLabel("Month " + " Year");
calendarTitle.add(BorderLayout.WEST, prevMonth);
calendarTitle.add(BorderLayout.CENTER, monthYear);
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);

dayButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent evt) {
Log.p("Action event triggered");
Picker datePicker = new Picker();
datePicker.setType(Display.PICKER_TYPE_DATE);

//Button b1 = (Button)(evt.getActualComponent());
//Log.p( b1.getText() );
}
});

allButtons.add(dayButton);
days.addComponent(dayButton);
if (iter <= 7) {
dayButton.setNextFocusUp(year);
}
}
}


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;
}
}

这是我的应用程序屏幕截图:-

enter image description here

以下方法用于事件处理:-

for (int iter = 1; iter < length; iter++) {
dayButton = new Button(""+iter);

dayButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent evt) {
Log.p("Action event triggered");
Picker datePicker = new Picker();
datePicker.setType(Display.PICKER_TYPE_DATE);

//Button b1 = (Button)(evt.getActualComponent());
//Log.p( b1.getText() );
}
});

allButtons.add(dayButton);
days.addComponent(dayButton);
if (iter <= 7) {
dayButton.setNextFocusUp(year);
}
}

最佳答案

您的代码创建一个 Picker 组件,但不会将其添加到任何表单或显示它。也许您正在寻找的是 Display.showNativePicker() ,因为这只会弹出一个 native 选择器对话框。

您应该首先检查平台是否支持 native 选择器(只有 iOS 和 Android 有 native 选择器),然后使用 DateSpinner 组件创建您自己的对话框。查看source for the Picker class查看它如何执行此操作的示例。

关于java - Codename 一个日期选择器问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43340469/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com