Java Reference
In-Depth Information
You want to manipulate HTML5 content with Java code.
Solution
You'll add a Panic button to your weather application that will simulate an e-mail noti-
fication. You'll also add a Calm Down button to retract the warning message.
The following code implements the weather application with additional buttons to
warn about and then disregard impending stormy weather:
@Override public void start(Stage stage) {
... // template building
This code adds HTML buttons with their onclick attributes set to invoke the
JavaScript alert function via buttons:
template.append("<body id='weather_background'>");
template.append("<form>\n");
template.append(" <input type=\"button\"
onclick=\"alert('warning')\" value=\"Panic Button\"
/>\n");
template.append(" <input type=\"button\"
onclick=\"alert('unwarning')\" value=\"Calm down\" />\n");
template.append("</form>\n");
The following code is added to the start() method to create the warning mes-
sage. The opacity is set to zero to be invisible:
// calls the createMessage() method to build warning
message
final Text warningMessage = createMessage(Color.RED,
"warning: ");
warningMessage.setOpacity(0);
... // Countdown code
Continuing inside the start() method, this code section is added to update the
warning message after the weather information is retrieved successfully:
Search WWH ::




Custom Search