Get all the events occurred till now in an Application - java

I need to know the events occurred in my web app, from the time it was loaded. Is there any way to get the events, The reason is I need to store those events is when ever user wants to go directly to result which he got after performing few actions, I can do PostEvent on series of events to reach that particular result, or is there any other way to do the same with out storing events?
Example:
User clicks on button1 -button1 is disabled,
User Click on button2 - button2 is disabled,
User clicks on button3 -button3 is disabled,
User Click on button4 - button4 is disabled,
Now user has performed 4 actions to get all the four button disable.
If user wants to reach the state when 1st 3 buttons I will do PostEvent of clicking 3 buttons for him.
Note Example is not exactly what I need. It's just for explanation purpose.

There's no support for this in GWT, you have to do it yourself. Record every action/event you're interested in, possibly using the command pattern, and log all of them for later replay.

In ZK , you could use Event Interceptor to log all event you need.
http://books.zkoss.org/wiki/ZK_Configuration_Reference/zk.xml/The_listener_Element/The_org.zkoss.zk.ui.util.EventInterceptor_interface

Related

How can I create a popup menu that allows user to choose a certain elements from a list on Java?

I am writing a Java program to record some events and their status, i.e., done or not. I have implemented the recording and calculations, but I also want to have a button that will open another window that will list the events with a checkbox corresponding to each of them, so I can pick which ones' statuses I will change to done. I have only used Swing libraries so far.
I want this window to contain one event per line, with a checkbox next to the event. Each checkbox should determine whether the status of the even should be changed or not. I had trouble even making such a window open and list the items, let alone put the checkbox.
Note: The design is not too important. This won't be a published project, I will mostly use it for personal work. I can do with buttons instead of checkboxes, where any click changes the status of the event next to it.
Thank you in advance for your valuable responses.

Restrict user to only 2 JButtons

I am making a matching game and want to only allow the user to select two cards (JButtons with images). I have 16 jButtons and was wondering on how I would restrict the user to only select 2 of those JButtons.
How the user plays:
They press the play button.
Select 2 cards and then press the guess button to check if they are the same. (This is where i want to only allow the user to select 2 cards)
You can disable buttons like this
jButton.setEnabled(false);
So disable the ones you don't want the user to select, or disable all of them and then enable the ones the user can select.
I'm a beginner with events in java, but I would try this based on the explanation you gave:
In your event listener for the JButton create a counter that starts at zero and counts up one each time the event listener is executed. As long as the counter is less than two, the rest of your event listener code should run (i.e. registering a card as selected). Once the counter reaches two, use Jim W's code jButton.setEnabled(false); on the rest of the buttons until the user clicks guess.

Swing Events Trouble

I am new to Java and am developing a java swing application.
The main frame (JFrame) has a text box and an OK button. There is some long processing to be done when the focus from the text box is lost as well as different long processing when the OK button is clicked. Now if the user enters a value in the text box and clicks the OK button directly, ideally, first the focus lost event is fired and then the event on the OK button. The problem is that while the focus lost event is running a joption frame comes up asking the user for some input, but even before user enters the input here, the OK button event starts executing leading to problems in the application. How can I serialize the event calls.
Any help will be appreciated.
Your problem lies within the concept of the Event Dispatch Thread. For long running work loads, check out the SwingWorker class.

Disable JFace Wizard 'Cancel' button on last page of wizard

When the user reaches the very last page of my JFace Wizard, I want to disable the cancel button (since at that time you cannot really 'cancel').
How can that be done?
Update:
This does not relate to my previous question about the cancel button which was related to disabling the wizard dialog entirely while running an async operation and involved a different api.
What you are trying to do isn't good for the users :-) A user should be able to cancel the wizard at any given point of time.
There isn't a direct API. You need to extend WizardDialog for this. Use getButton(IDialogConstants.CANCEL_ID) to get the cancel button. You can do enable/disable on that button.

How are multi-button presses handled in swing?

I'm experiencing some strange behaviour when using a stylus with swing.
I am interpreting pressing the button on the side of the stylus(RIGHT) and pressing the stylus down(LEFT) as a "Grab" event, but occasionally (more often than 0), events are just being dropped.
The JavaDocs for MouseEvent are pretty explicit about how multibutton presses are handled if executed one at a time (left down, right down, right up, left up) but say nothing about simultaneous button presses.
I'm left to wonder, would they be emitted as two mousePressed events, or as one with the button mask set for both buttons, or something else entirely?
Thanks.
I'd interpret the API doc as simultaneous button presses being simply not possible:
When multiple mouse buttons are pressed, each press, release, and click results in a separate event.
So there should be separate events. The problems you observe could be due to errors in your code, the stylus' driver, the hardware, or Swing (this is in decreasing order of likelihood as I see it :)
I'd try to diagnose the problem by logging events at different levels, if possible.
Simultaneous button presses are processed as two separate mousePressed events. Run the Mouse Events Demo to see them processed separately.
As I recall, there's no way to handle simultaneous button presses. What I used to do to ensure that multiple buttons being pressed at once were treated as such was I would have a boolean variable for each button and when it was pressed, I would set it to true and when it was released, I would set the boolean to false. Then when it came time to perform an action, I would check for the boolean variables (sometimes I would have the actionlistener redirect to the method call for determining what action was to happen next after setting the booleans). This doesn't work if the only thing you want to do is them being pressed at the exact same time, but if you're just trying to get combinations to work, then that's how I did it. This was about 4 years ago, before Java 5, so I may be wrong about that.

Categories

Resources