Selecting a date on JCalendar to create a dialog box - windowbuilder

I am working on a project that uses an interactive calendar. I intended for the user to click a date on the JCalendar, and if an event took place on that day then a pop-up would display, telling the user what event took place. If there was no event on that day, a pop-up would display telling the user that there was no event that day. How would I register this interaction with the JCalendar, and turn this interaction into a dialog box on the screen?

Add a PropertyChangeListener to your JCalendar for "calendar". Check the resulting Date against your event and bring up a JOptionPane to show the result.
JCalendar jc = new JCalendar(c);
jc.addPropertyChangeListener("calendar", new PropertyChangeListener() {
#Override
public void propertyChange(PropertyChangeEvent e) {
System.out.println(e.getPropertyName() + ": "
+ ((GregorianCalendar)e.getNewValue()).getTime());
}
});

Related

(Maps) Avoid camera to comeback to prior position when I add a new Pin

I have an app that shows a Map and a Pin on the center of it(just like Uber and PedidosYa), I have a button that when I click it sends the location where the pin's on. And it makes to appear the closest stores around that pin.
My problem is that when the first time the map appears its centered in my location, I move the map around to locate the pin, and when I click the button I want the map to stay there, but its comeback to the prior location and THEN moves the camera to the location where I drop the pin. I want to avoid that moving.
The function I use when I click the button to drop the pin is something like this:
var CenterPos = customMap.GetMapCenterLocation();
var pinPersonal = new CustomPin()
{
Id = "000",
Position = new Position(CenterPos.Latitude, CenterPos.Longitude),
Label = "Mio",
Url = "Mío"
};
customMap.Pins.Add(pinPersonal);
This draws a pin where I click the button. If I keep it this way, it draws the pin, and the camera comesback to the prior location.
After I use something like this:
customMap.MoveToRegion(MapSpan.FromCenterAndRadius(
new Position(latitud, longitud), Distance.FromMiles(0.2)));
that makes the camera to move to the location I choose. But it comebacks always to the prior location and the moves to the new one.
Any idea? Im not sure from where this behavior comes.
Did you implement CustomMap according with Customizing a Map Pin - Xamarin?
Probably you should override OnMarkerClickListener.OnMarkerClick and return true in your custom renderer.
This means disable default behavior(centering map, open info-window) and you can implement your own behavior when pin clicked.
See this link.
Markers  |  Maps SDK for Android  |  Google Developers
/** Called when the user clicks a marker. */
#Override
public boolean onMarkerClick(final Marker marker) {
// Retrieve the data from the marker.
Integer clickCount = (Integer) marker.getTag();
// Check if a click count was set, then display the click count.
if (clickCount != null) {
clickCount = clickCount + 1;
marker.setTag(clickCount);
Toast.makeText(this,
marker.getTitle() +
" has been clicked " + clickCount + " times.",
Toast.LENGTH_SHORT).show();
}
// Return false to indicate that we have not consumed the event and that we wish
// for the default behavior to occur (which is for the camera to move such that the
// marker is centered and for the marker's info window to open, if it has one).
return false;
}

"Events type" in java

My program contain two classes, one represent the main program and the other one is a gui implemented using swing,
I'm trying to create an "event type", meaning I want my main program to wait until the UserInterface (GUI) will indicate some event, like pressing a button, and I would like to sends some information when my button is pressed.
General Code for the main program (this is the relevant section)
// Open window GUI with the requested BID and wait for confirmation or denial
HumanIFWindow nextWindowGUI = new HumanIFWindow();
nextWindowGUI.setVisible(true);
// ----------------- //
// - Wait on event - //
// ----------------- //
// Here is where I want to wait for the gui Indication
return returnedBid;
Code for the GUI (Again only relevant part)
JButton btnAprove = new JButton("Aprove");
btnAprove.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
// ----------------- //
// - Trigger event - //
// ----------------- //
// Here is where I want to trigger the event
}});
Preferably I would like to use some library, is there's one that match my needs?
(Maybe BusEvent?)
Edit to specify the question (Thanks Kishan Sarsecha Gajjar)
I want the first class (the general one) to enter a wait statement, I know how to wait using:
while( someBoolean...)
Thread.sleep(...)
and I can change someBoolean with a handle in the GUI class, Like:
FisrtClass.someBoolean == False
But I want something nicer and neater, like a library that Implements the sleep statement. and there's no additional code needed. Is there something like that?
I've looked at Google-BusEvent library but I'm not sure if that's compatible
EDIT, adding JDialog
updated code: Main program:
Bid returnedBid = requestBid;
// Open window GUI with the requested BID and wait for confirmation
DialogHumanConfirmManual nextWindowGUI = new DialogHumanConfirmManual(requestBid);
// Wait on event
if ( (returnedBid = nextWindowGUI.getAnswer()) != null ){
System.out.println("Got Bid " + returnedBid.print());
}
GUI - Dialog:
public DialogHumanConfirmManual(Bid requestedBid){
currentBid = requestedBid;
currentBid.approvedHuman = false;
Dialog mainFrame = new Dialog(new Frame());
myPanel = new JPanel();
getContentPane().add(myPanel);
myPanel.add(new JLabel("Confirmation Dialog"));
yesButton = new JButton("Confirm");
yesButton.addActionListener(this);
myPanel.add(yesButton);
noButton = new JButton("No");
noButton.addActionListener(this);
myPanel.add(noButton);
pack();
setVisible(true);
}
public void actionPerformed(ActionEvent e) {
if (yesButton == e.getSource()) {
currentBid.approvedHuman = true;
answeredBid = currentBid;
}
}
After opening the Dialog the if ( returnBid ) is called, which result in Null Pointer Exception later on in the code, So How can I delay the main program until the user can Confirm the request??
the other one is a gui implemented using swing,
Use a modal JDialog not a JFrame.
Once the dialog is made visible, the code after the setVisible(true) statement will NOT execute until the dialog is closed.
Read the section from the Swing tutorial on How to Make Dialogs for more information. The tutorial covers the JOptionPane class, but you can just use a JDialog, which is created exactly the same way a JFrame is. You can choose whether to use a JOptionPane or JDialog depending on your exact requirement.

Password field color

I want to change the color of my JPasswordField with key Listener. I'm making a registration form and the user should fill the passwordfield at least with 8 characters that include digits and letters. Can anybody help me?
my code :
enter code here
public void keyPressed(KeyEvent e) {
if(e.getSource()==passwordField){
if(passwordField.toString().length()>=8)
passwordField.setBackground(Color.GREEN);
else
passwordField.setBackground(Color.RED);
}
}
When the keyPressed() event is fired the Document of the password field has not yet been updated, so the length will be 1 less than you think it should be.
Instead try using the keyTyped() method:
public void keyTyped(KeyEvent e)
{
JPasswordField password = (JPasswordField)e.getSource();
if(passwordField.getPassword().length >= 8)
passwordField.setBackground(Color.GREEN);
else
passwordField.setBackground(Color.RED);
}
Also, when writing a listener you should get the source of the event from the event object instead of trying to access an instance variable.
You may also want to consider using an InputVerifier on this field. The input verifier will prevent the user from tab away from this field unless at least 8 digits have been entered.
Note: even using the keyTyped() event you can still have problems because if the user uses the "BackSpace" key no event is generated. So maybe you should be using the keyRelased() event. Even this can cause a problem because if the users holds down a key multiple characters will be entered into the field before a keyReleased event is fired.
The best solution is to use a Document Listener. Read the section from the Swing tutorial on How to Write a Document Listener for more information.
you're doing it wrong
change to this
public void keyPressed(KeyEvent e) {
if(e.getSource()==passwordField){
if(passwordField.getPassword().length()>=8)
passwordField.setBackground(Color.GREEN);
else
passwordField.setBackground(Color.RED);
}
}
you should use getPassword()

html body gwt click event

html file has two textbox and one button.
but i need to generate click event when i only click outside of the two textboxes and button
element.how can i do that.
RootPanel.get().addEventListener or something like that?? help.
Typing anywhere in the browser window will trigger alert pop-up:
Event.addNativePreviewHandler(new Event.NativePreviewHandler() {
#Override
public void onPreviewNativeEvent(NativePreviewEvent event) {
NativeEvent ne = event.getNativeEvent();
if (KeyDownEvent.getType().getName().equals(ne.getType())) {
Window.alert("who fired me last?"
+ event.getNativeEvent().getCurrentEventTarget()
+ "\nevent target:" + event.getNativeEvent().getEventTarget());
}
}
});
I don't know, if RootPanel.get().addEventListener works, but you can add another panel, which contains the three elements. To the new panel you can add an listener.

ComboBox Bug in ActionScript

I was trying to filter a combo box dataprovider based on the values in the text boxes . When the contents of the dataprovider changes Combo box automatically calls change event method . Please find the sample code below.
Filter Utility Function:
private function filterLocations(event:FocusEvent):void {
locationsList1.filterFunction = filterUtility;
locationsList1.refresh();
}
public function filterUtility(item:Object):Boolean {
// pass back whether the location square foot is with in the range specified
if((item.SQUARE_FOOTAGE >= rangeText1.text) && (item.SQUARE_FOOTAGE rangeText2.text))
return item.SQUARE_FOOTAGE;
}
// THIS WOULD BE CALLED WHEN COMBO BOX SELECTION IS DONE
private function selectLocationsReports(event:ListEvent):void {
selectedItem =(event.currentTarget as ComboBox).selectedItem.LOCATION_ID;
}
When the DataProvider gets refreshed its automatically calls change method and was throwing Null Pointer function because its prematurely calling the above selectLocationsReports method and its throwing error.
Can somebody let me know how to stop the CHANGE event from propogation when the dataprovider is refreshed.
You can't stop a CHANGE event, just don't add an event listener unless you are prepared to get the event. I don't see where your event listener for Event.CHANGE is in the code above.
Just be sure that you don't addEventListener(Event.CHANGE, selectLocationsReports) until your ComboBox is ready for it.
The other thing to do (on top of Kekoa's response) is put an if statement in the event handler, and check to make sure the data is there before you begin working with it.
A handy syntax I use frequently for this is
if(dataprovidername) {
}