Answered step by step
Verified Expert Solution
Question
1 Approved Answer
import java.io . * ;import java.net. * ;import java.util.Scanner;import javafx.application. * ;import javafx.geometry.Pos;import javafx.scene.Scene;import javafx.scene.chart.BarChart;import javafx.scene.chart.CategoryAxis;import javafx.scene.chart.NumberAxis;import javafx.scene.chart.XYChart;import javafx.scene.control. * ;import javafx.scene.layout.GridPane;import javafx.scene.paint.Color;import javafx.stage.Stage;import javax.net.ssl
import java.io;import java.net.;import java.util.Scanner;import javafx.application.;import javafx.geometry.Pos;import javafx.scene.Scene;import javafx.scene.chart.BarChart;import javafx.scene.chart.CategoryAxis;import javafx.scene.chart.NumberAxis;import javafx.scene.chart.XYChart;import javafx.scene.control.;import javafx.scene.layout.GridPane;import javafx.scene.paint.Color;import javafx.stage.Stage;import javax.net.sslHttpsURLConnection;public class Project extends Application @Override public void startStage primaryStage create a Label for the first URL with text Enter URL ; Label L new LabelEnter URL : ; create Label for the second URL with text Enter URL ; Label L new LabelEnter URL : ; create a Text field for entering the first URL TextField text new TextField; create Text field for entering the second URL TextField text new TextField; create a button for comparing. Button CompareButton new ButtonCompare; create a button for exit the system when the user finishes from getting the chart Button ExitButton new Button Exit System ; Attache an event handler to the ExitButton. so When clicked, it exits the system closes the application ExitButton.setOnActione System.exit; ; Attaches an event handler to the CompareButton. When clicked, it checks if both URL fields are not empty. If they are, it shows an error message using Alert CompareButton.setOnActione try if textgetTexttrimlength textgetTexttrimlength Alert alert new AlertAlertAlertType.ERROR, "Please be sure that
the First or the Second URL
are not Empty", ButtonType.OK; alert.showAndWait; return; else Calls the isValidURL method to check if the entered URLs are valid If not, it shows an error message stating that enter valid URLs if isValidURLtextgetTextisValidURLtextgetText Alert alert new AlertAlertAlertType.ERROR, "Please enter valid URLs", ButtonType.OK; alert.showAndWait; return; Handles the logic when the CompareButton is clicked. Create a connection with the first URL. HttpsURLConnection urlConnectionHttpsURLConnectionnew URLtextgetTextopenConnection; urlConnectionsetRequestMethodGET; Check the HTTP response code if urlConnectiongetResponseCode HttpsURLConnection.HTTPOK Read data from the First URL site try BufferedReader br new BufferedReader new InputStreamReaderurlConnectiongetInputStream; PrintWriter pw new PrintWriternew Fileftxt String str; while str brreadLine null pwprintlnstr; else Display an error message to the user Alert alert new AlertAlertAlertType.ERROR, HTTP response code: urlConnectiongetResponseCode for URL: textgetText ButtonType.OK; alert.showAndWait; return; Exit the method if an error occurs Create a connection with the second URL. HttpsURLConnection urlConnectionHttpsURLConnectionnew URLtextgetTextopenConnection; urlConnectionsetRequestMethodGET; Check the HTTP response code if urlConnectiongetResponseCode HttpsURLConnection.HTTPOK Read data from the Second URL site try BufferedReader br new BufferedReader new InputStreamReaderurlConnectiongetInputStream; PrintWriter pw new PrintWriternew Fileftxt String str; while str brreadLine null pwprintlnstr; else Display an error message to the user Alert alert new AlertAlertAlertType.ERROR, HTTP response code: urlConnectiongetResponseCode for URL: textgetText ButtonType.OK; alert.showAndWait; return; Exit the method if an error occurs catch MalformedURLException ex Display an alert to the user Alert alert new AlertAlertAlertType.ERROR, "Invalid URL entered: exgetMessage ButtonType.OK; alert.showAndWait; return; Exit the method if an error occurs catch IOException ex Display an alert to the user Alert alert new AlertAlertAlertType.ERROR, "IOException occurred: exgetMessage ButtonType.OK; alert.showAndWait; return; Exit the method if an error occurs
Provide the uml digram for this code
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started