This might sound like an odd one but I have a jsp form that has an event timer on the page to keep the page active before logging the user out. After selecting some options it opens up a popup window where the user has to complete the form with further options.
The problem is that the first form can time out while the user is active on the second and I would like to somehow reset the timer on the first form if there is activation on the 2nd form. It would actually be enough to determine general mouse or keyboard activity on the original form even though it has lost focus.
Can this be done?
We are using a proprietary framework called Nordic Edge so I don't have a lot of scope to rebuild how the search and popup are implemented.
Related
How do I get the same name after a successful login?
I have user class that set user.setName after verifying the user name and password from text file in login JFrame and user.getName in other frame to greet user in the main menu.
There's lots of different ways to do it, but basically it boils down to Passing Information to a Method or a Constructor.
One thing you should do is to try and decouple the process. Your "main menu" doesn't care where or how the user name is generated/gained, it only needs it. Equally, your login process doesn't care what happens after the user is validated.
To that end, you should take the time to understand the model-view-controller paradigm, you will see it a lot and will help you solve similar questions.
Basically, a "controller" will display the login view, the login view will gather the credentials and the this information will be feed back through the model for validation. When successful, the controller can pass control on to the next controller which will actually display the "main menu", providing the login model as part of the information.
Again the "how" depends a lot on the overall solution, but you want to get to the point where you have the ability to change either or both the main menu and login windows and it won't have any affect on the other
You can also have a look at:
Open JFrame, only after successfull login verification with database. Using Eclipse?
Java and GUI - Where do ActionListeners belong according to MVC pattern?
Open a JPanel after pressing a button in a JFrame
for more details and ideas
I'm currently making a Java Applet program that heavily depends on the radio buttons and a text field for it to compute the needed information. I want to know if there is a way to remind the user that he or she has forgotten to select a radio button like how catching does to an empty textfield.
Thanks in advance.
P.s. I am still a senior high student. Our professor and curriculum requires us to study Java Applet before moving on to a more advanced type of programming.
Java Applet actually defines a Server-side code, which coincidently creates an HTML page that will run on the user's browser. But it's important to remember that none of your Java code will run in the browser.
This means that when a client presses submit on your page, all the information will be sent to the server side (as is). At this point you can check for example, if specific value was not set, and present a page with error message to the client. In conclusion: cumbersome, and not pretty.
A much better solution, and what is usually done is: Create a Javascript function that will test if a radio button is selected, if not, it will show an error message (without leaving the page) and will prevent the submit code from running until it was fixed.
Here's an example of how it's done: Check if input radio ID is selected before form is submitted
I'm developing a Java 6 applet which allows users to view OO (v.3.2) documents (read only), and if they choose, click a button which launches a new JDialog window, with the document displayed in it which allows the user to and mark and redact it as they wish. Once they are done, they can close the JDialog, which saves the document to a server and redisplay the updated document (read-only again) in the original applet window
I guessed that I could do this with a single instance of an OfficeBean, embedded in a Swing Panel. However, I cannot seem to successfully move my Panel (containing the OfficeBean) from the applet to the JDialog when the "Redact" button is clicked. All I get is a blank area in the JDialog where the document should be. I get no errors.
I have currently managed to get round this by creating new instances of the OfficeBean every time I need to display the document (once when the applet is loaded, again when the user chooses to redact and it is opened in a JDialog, and finally when they click "Save" in the dialog and the redacted result is displayed in the applet again.) However this means three trips to and from the server where the documents originate. That seems mad to me.
I'm in no way a Swing expert and may well be making a silly mistake. However, I've done a lot of fiddling around, debugging and googling and can't seem to get this to work. Can anyone help me in this? Am I trying to do something which is fundamentally impossible? I hope not.
One rule in Swing is that a component can only be displayed / attached to one part of the gui "tree" at a time. When you "move" your component to the dialog, are you first removing it from the applet?
Wow, what a stupid question you might say. But is it possible? I have a mouse move event in a Jpanel and it works even when the application is not in focus, now can I have something like that for the clicking event or something similar. And most importantly I don't want other apps (even something like the main menu) to lose focus when i click on my app.
I thought of the system's event queue but i'm not sure where that would lead me to.
Thanks in advance.
[EDIT - the purpose]
I want to create an app that mimics the users interactions with the system in a later time. for example a user takes the mouse and clicks and writes and my app will mimic that in say 2 hours time. ofcourse i would need a system hook for the outer events but i wanted to avoid os-dependant code so i basically capture the screen, take it to my app,for example the user clicks on an icon in the captured picture and then for making that come to life, i translate the coordinates to the real icon and click it (with a Robot) and in this way i can capture the user's events in my own app. the problem occurs when the user clicks on the main menu or right clicks (he's doing that in my app, and my app does that to the system so my app is in between) and ofcourse the real main menu will lose focus when the user tries to click on one of it's items.
sorry for my english.
I'm still not sure I follow what you are trying to do. But the concept of an app getting focus when you click on it is fundamental to the GUI and I suspect rather difficult to get around.
I just found this:
Focusable Windows
To support palette windows and input methods, client code can prevent a Window from becoming the focused Window. By transitivity, this prevents the Window or any of its descendants from becoming the focus owner. Non-focusable Windows may still own Windows that are focusable. By default, every Frame and Dialog is focusable. Every Window which is not a Frame or Dialog, but whose nearest owning Frame or Dialog is showing on the screen, and which has at least one Component in its focus traversal cycle, is also focusable by default. To make a Window non-focusable, use Window.setFocusableWindowState(false).
In this doucment http://java.sun.com/j2se/1.5.0/docs/api/java/awt/doc-files/FocusSpec.html
That sounds like it might do what you want.
I am working on a project that is using a JTable to display, among other things, a column of dates. We needed validation for the user input for dates, so I have implemented a combination of masking for format validation and parsing for actual date validation. I have done this using a custom CellEditor for the date column.
Inside my MaskedCellEditor, I have a JFormattedTextField. I setup the masking for dates. Then I add an InputVerifier to allow for actual validation. My InputVerifier implements verify() to check: 1. textField.isEditValid() 2. DateValidator.ValidDate(). If either is invalid, verify returns false and the InputVerifier locks the focus into the text field (the cell editor) and a small message dialog is displayed reminding the user of the date format.
The error message is a small, undecorated, non-modal, non-focusable JDialog that pops up underneath the cell being edited. It disappears on a keypress or a successful date verification. It is working great except for a small edge case.
If the user selects a menu button on the top of the application while an invalid edit has popped up the dialog, it switches screens, destroying everything currently on the screen (including the table). However, since the dialog is being shown and a keypress/successful edit has not occurred, the dialog is never hidden. It remains visible in a completely unrelated context on a different screen. Once the user has switched off the screen with the table, there is no way for the user to get rid of the dialog.
I have debated throwing either a Timer and/or a MouseListener on the dialog itself that would cause it to disappear, but I feel that I am ignoring the actual problem. The dialog is never being disposed of and I am pretty sure its because it is still set to be visible and it is preventing the garbage collector from getting rid of it.
I have a Cleanup method on the panel holding the JTable, but I cannot find a good way to reference the dialog (a component of the InputVerifier) in order to get rid of it. The dialog is pretty far removed from the table's parent panel. (Panel -> JTable -> CellEditor -> JFormattedTextField -> InputVerifier -> JDialog)
Any ideas on how to force the dialog to be hidden when the table is destroyed? If you need more details, let me know. I'm trying not to get you guys bogged down in the details, but there is a lot going on.
As a first thought, can you not go down the listener approach. If you have a closeErrorDialog() type method that gets called when upon successful valdiation, then you can also call it when a menu action is selected.
As an alternative, perhaps you could control the transition from menu to menu in some way, and create a "cleanup" method which will close down any exisiting error dialogs. This would allow for any other actions that need to take place when changing menus, to happen in the same place.
Just a couple of quick ideas of the top of my head. Hope they are along the lines of what you meant
Many people will vote me down for saying this, but it sounds like your dialog should be modal so that users can't switch away from it without dismissing it first. Or at least disable the menus that allow people to switch away while this dialog is displayed.