Prompt user to select a radio button - java

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

Related

Selenium WebDriver: Multiple Drivers - Getting a CSS property from one when focussing on it changes it in the other

This question is conceptual, and I am asking on this help forum in order to look for a lead to go off and research, and will not contain any code examples other than one to demo what I am using to grab the element value described below, here is some background:
The test I am writing involves signing in to the same application using two driver sessions each of which open a webdriver chrome window. Each one logs in to our app as a different user, and then from one, you can see the "online/offline" status of the other.
We use one class of methods for the first session, and another class of methods for the second session, and if a feature file title appears in a third class containing a LinkedList of strings, then the system knows to open the second session, and we then call methods in the relevant class to run jobs in the appropriate window.
In the current test case I am creating, the objective is to assert in a window we shall call "A", that the element being checked has a specific CSS property, namely its color property. It is grey when the other window that we shall call "B" does not have focus, and it is green, meaning online, when it does have focus, and is logged in.
The logged in side I can take care of, and manually I can see that it is working, but after this log in, when I use from the class that runs commands for window "A" the following line, directly after the last line that directs window "B" to have focus and do something, then it writes the value for "offline" in to the variable shown, as the window "B" has had to lose focus in order to check the element in window "A".
String color = seleniumClient.getWebDriver().findElement(By.xpath("//div[#id='user-content-button']/span/span")).getCssValue("background-color");
I am not able to influence the development of our app, as I am a QA, but I am asking if anyone knows how to maybe freeze the state of the chrome session for window A showing window B to be online before I run the above line, or any other way that I can get my test to see the correct state when the focus is not on the window "B"
Thanks.

How to get data from other JFrame to another JFrame?

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

Event time between two jsp windows

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.

Java Desktop app to pop up websites captcha

Hoping someone can point me in the right direction.
I'm quite new to Java and wanting to build a small app to practice etc.
Anyway I want to fill out a form on a site and grab the data. I have had a look at HtmlUnit and HtmlComponents and think I have most of the design covered.
Something I can't figure out is the site has a single captcha and I want my desktop app to popup a window where I would enter the captcha (manually, I'm not creating a bot).
Is this possible in Java?
It's possible and in fact JDownloader is doing it. It's open source, so you can take a look to its code.
As mentioned before JDownloader does this technique quite well. You mentioned the source is rather difficult to understand, so I'll explain the basics of what one would do.
First you would want to create your code that will fill in the form, once the form hits the captcha have it open up a frame that has a spot for an image (which will be the captcha image), a textfield, and a submit button. The submit button should have an action that will send the text from the textfield to the captcha text field in the form.
Summary:
1: Create you class that will fill in the form
2: Once it gets to the capthca make it open your 'captcha solving frame'
3: Fill in the text field and create an actionPerformed on the button that will send your string to the textfield in the form
4: Throw in some sort of catch in case you improperly fill in the captcha
On a side note, this would be easier and considerably less verbose if done with Groovy (or a scripting language) rather than Java.

OfficeBean won't display after moving containing Swing Panel from one Container to another

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?

Categories