0

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.

Bear
  • 1
  • 3
  • 1
    Why not give one of the radio buttons a default status of selected? – jsheeran Oct 29 '17 at 08:29
  • You could simply verify the state of the fields. Check to see which ones are checked and verify that the expected values are available. Depending on how you're processing the information, this might be done as part of the submission process – MadProgrammer Oct 29 '17 at 09:18
  • Because I don't like throwing dialog boxes at users, especially for something which can be as complicated as your proposing, I prefer to simply highlight the fields which are invalid (maybe also adding an additional label to explain the reason), maybe something like [this for example](https://stackoverflow.com/questions/25274566/how-can-i-change-the-highlight-color-of-a-focused-jcombobox/25276658#25276658) – MadProgrammer Oct 29 '17 at 09:21
  • 2
    While we're at it, Applet's are deprecated; [The clock is ticking: The Java browser plugin will be deprecated soon](https://jaxenter.com/clock-ticking-java-browser-plugin-will-deprecated-soon-131546.html); [Why applets in JDK 9 are deprecated?](https://stackoverflow.com/questions/45535112/why-applets-in-jdk-9-are-deprecated); [Oracle's finally killing its terrible Java browser plugin](https://www.theverge.com/2016/1/28/10858250/oracle-java-plugin-deprecation-jdk-9); [Moving to a Plugin-Free Web](https://blogs.oracle.com/java-platform-group/moving-to-a-plugin-free-web) – MadProgrammer Oct 29 '17 at 09:23

1 Answers1

0

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

AlexM
  • 334
  • 2
  • 4
  • 16