How to add calendar in lwuit TextField or comboBox - java-me

I am creating an application using lwuit. And i want to add calendar in comboBox. please give me an idea as soon as possible..

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
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.

Related

How to display received data or value in Blazor webassembly?

I have this problem: I can send data or a value to a function from a page or an API but razer component doesn't show the value; actually, it doesn't render new values.
Here's my example function:
public string p="";
public void myMethod(string a)
{
p=a;
}
Here's my HTML tag:
<p>#p</p>
When I click the button from an other page, myMethod will be called like this:
private void buttonClick()
{
new NavMenu().myMethod("Test text");
}
The button click is in a page and NavMenu is a component. I debug this and the value of 'p' successfully changed but the page does not show new value.
Actually I tried this code but nothing happened:
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(p));
What should I do to display new values without refreshing the page?

How to wirte Public Dialog addClickListener write back Form TextField

I’m a beginner, I can’t pass this level, please help.
I have a lot of forms with TextField (cust_no, cust_name), each with a button on the right,
press the button
A dialog can be display custom record, after selecting the required customer,
Write the selected cust_no, cust_name back to the Text_Field of Form.
I hope to write dialog as a public class, so that many class Forms can use this function, and can also smoothly write cust_no and cust_name back to their respective Form TextField.
In addition to backfilling cust_no,cust_name TextField for some Forms, some also need to query the consumption amount and write back the specified cust_amt TextField.
My trouble is that form button.addClickListener open a dialog,
Dialog’s Button_OK.addClickListener cannot know how I want to write back Form TextField and some have special query mechanisms, how to customize
Without seeing exactly how your code is structured, I can only give a quite generic answer. What you need is typically that something associated with the button for opening the dialog can know what to do with the result from the dialog, and it can also configure the dialog's OK button to carry out that action.
public class HelloWorldView extends VerticalLayout {
public HelloWorldView() {
TextField customerNumberField = new TextField("Customer number");
TextField customerNameField = new TextField("Customer name");
Button nameDialogButton = new Button("Open dialog", dialogOpenClick -> {
showDialog(customer -> {
customerNumberField.setValue(customer.getNumber());
customerNameField.setValue(customer.getName());
});
});
add(customerNumberField, customerNameField, nameDialogButton);
}
private void showDialog(Consumer<Customer> selectionAction) {
Select<Customer> customerSelect = new Select<>(new Customer("1", "Customer 1"),
new Customer("2", "Customer 2"));
customerSelect.setTextRenderer(customer -> customer.getName());
Dialog dialog = new Dialog();
dialog.add(customerSelect);
dialog.add(new Button("Select customer", click -> {
Customer selectedCustomer = customerSelect.getValue();
if (selectedCustomer != null) {
selectionAction.accept(selectedCustomer);
}
dialog.close();
}));
dialog.open();
}
}

Primefaces Schedule Error, save event changes the hour automatically to 12am

I'm using a primefaces schedule component in my aplication and i've detected a strange behaviour. When I select an event and push the "save button" the hour is reset to 12am. After much time investigating, turned to the Primefaces Showcase page for more info.
In the Showcase, schedule behaviour is the same. In the Schedule Editable Example http://www.primefaces.org/showcase/ui/data/schedule.xhtml, for example, select the event with the title "Champions League Match", which date is 28/04/2015 and the hour is from 8:00 to 11:00 and push save button. It automatically changes the hour to 12am. Is it the normal behaviour?????
Thanks.
EDITED: I'll add the code that i have in my aplication, that is the same or very similar to the showcase.
Creation of the event:
eventModel.addEvent(new DefaultScheduleEvent("Champions League Match", previousDay8Pm(), previousDay11Pm()));
Methods to set time frame:
private Date previousDay8Pm() {
Calendar t = (Calendar) today().clone();
t.set(Calendar.AM_PM, Calendar.PM);
t.set(Calendar.DATE, t.get(Calendar.DATE) - 1);
t.set(Calendar.HOUR, 8);
return t.getTime();
}
private Date previousDay11Pm() {
Calendar t = (Calendar) today().clone();
t.set(Calendar.AM_PM, Calendar.PM);
t.set(Calendar.DATE, t.get(Calendar.DATE) - 1);
t.set(Calendar.HOUR, 11);
return t.getTime();
}
Add method which is invoked when push "Save" button (only i'm trying to change event background to red, with setStyleClass):
public void addEvent(ActionEvent actionEvent) {
event.setStyleClass("emp1");
eventModel.updateEvent(event);
event = new DefaultScheduleEvent();
}
Because its just an example.
Add input text with time selector and add event on specific, While creating an event specify time frame like:
eventModel.addEvent(new DefaultScheduleEvent("Birthday Party", today1Pm(),todat6Pm());
where
private Date today1Pm() {
Calendar t = (Calendar) today().clone();
t.set(Calendar.AM_PM, Calendar.PM);
t.set(Calendar.HOUR, 1);
return t.getTime();
}
private Date today6Pm() {
Calendar t = (Calendar) today().clone();
t.set(Calendar.AM_PM, Calendar.PM);
t.set(Calendar.HOUR, 6);
return t.getTime();
}
As for showcase yes you need some update to achieve it :)
Behavior of showcase, if you do not define any time frame and not set AllDay check event is added like eventModel.addEvent(event); which set default time to 12am and Yes it is normal!
Update
Use this method for add new event, startTime/endTime is your field which is set by form. I also paste the default constructor signature with snippet.
public void addEvent(ActionEvent actionEvent) {
if(event.getId() == null)
//DefaultScheduleEvent(String title, Date start, Date end, String styleClass) ;
eventModel.addEvent(new DefaultScheduleEvent(actionEvent.Title(), calculateTime(startTime), calculateTime(endTime),"emp1"));
else
eventModel.updateEvent(event);
}

How to get the selected Appointments in the Agenda components of JFXTRAS 2?

I'm having trouble on how can i get the selected appointments in the agenda component of JFXTRAS 2, any ideas on how can i get the selected appointments in the agenda component?
The agenda component of the JFXTRAS 2 provide a selectedAppointments property.
So you could get the selected appointements,
Collection<Appointment> selectedAppointments = agenda.selectedAppointments();
listen to the property modifications,
agenda.selectedAppointments().addListener(new ListChangeListener<Appointment>() {
#Override
public void onChanged(Change<? extends Appointment> c) {
}
});
bind the property to another one,
ObservableList<Appointment> observableList = FXCollections.observableArrayList();
Bindings.bindContent(observableList, agenda.selectedAppointments());
display the selected appointments in a ListView,
ListView<Appointment> listView = new ListView<Appointment>(agenda.selectedAppointments());

drop down list for country selection in j2me form

I want to make a form where then is login and password textfield.
Ans I want to add one dropdown list of country by which user can select the one of the country from that list.
How is it possible in j2me?
You can use ChoiceGroup for this. See this demo application,
public class ChoiceGroup extends MIDlet
{
Display display=Display.getDisplay(this);
public void startApp()
{
Form form = new Form("Choice Form");
//ChoiceGroup(label,type,elements,image)
ChoiceGroup CoursePOP = new ChoiceGroup ("Pop Up choice", Choice.POPUP,
new String[] {"India", "Usa","UK"}, null);
form.append(CoursePOP);
display.setCurrent(form);
}
}

Resources