Question: Create a java program that performs a database lookup. Edit it so the four octets taken in the GUI are converted to a single number.
Create a java program that performs a database lookup. Edit it so the four octets taken in the GUI are converted to a single number. The program is supposed to take this number then search for it the database record and return the geolocation of itcountry region, and city if they are there if not it leaves it blank or if the number doesnt exist display a message saying it cantThe code I connected a mysql connector vFirst code is starter dont touch it second is what to edit.
import java.ioIOException;
import java.sqlSQLException;
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TextArea;
import javafx.scene.control.TextField;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import javafx.stage.Stage;
public class GeoLocApp extends Application
private TextField txtA, txtB txtC txtD;
private TextArea taLocation;
public void startStage primaryStage throws IOException
Scene scene new ScenebuildStagePane;
primaryStage.setScenescene;
primaryStage.setTitleIP Address Locator";
primaryStage.setResizablefalse;
primaryStage.show;
private BorderPane buildStagePane
final String PANESTYLE fxfontweight: bold; fxfontsize: pt;
BorderPane bp new BorderPane;
bpsetStylePANESTYLE;
bpsetTopbuildInputBox;
bpsetCenterbuildOutputBox;
return bp;
private HBox buildInputBox
HBox inputBox new HBox;
inputBox.setPaddingnew Insets;
inputBox.setSpacing;
inputBox.setAlignmentPosCENTER;
inputBox.setPrefWidth;
txtA new TextField;
txtA.setPrefColumnCount;
txtB new TextField;
txtBsetPrefColumnCount;
txtC new TextField;
txtCsetPrefColumnCount;
txtD new TextField;
txtDsetPrefColumnCount;
Label lblEnter new LabelIP Address:";
Label lblDot new Label;
lblDot.setTranslateY;
Label lblDot new Label;
lblDotsetTranslateY;
Label lblDot new Label;
lblDotsetTranslateY;
var btnLocate generateButtonLocate e locate;
var btnClear generateButtonClear e clear;
inputBox.getChildrenaddAlllblEnter txtA, lblDot, txtB lblDot txtC lblDot txtD
btnLocate, btnClear;
return inputBox;
private HBox buildOutputBox
HBox outputBox new HBox;
taLocation new TextArea;
taLocation.setPrefWidth;
taLocation.setEditablefalse;
outputBox.setAlignmentPosTOPCENTER;
outputBox.setPaddingnew Insets;
outputBox.setSpacing;
outputBox.getChildrenaddtaLocation;
return outputBox;
private Button generateButtonString caption, EventHandler e
var btn new Button;
btnsetTextcaption;
btnsetOnActione;
return btn;
private void locate
var displayIP String.formatssss txtA.getText txtBgetText txtCgetText txtDgetText;
String location;
try
location GeoIPClient.lookupIptxtA txtB txtC txtD;
catch SQLException ex
location SQL Exception: ex;
taLocation.appendTextdisplayIP : location;
private void clear
txtA.clear;
txtBclear;
txtCclear;
txtDclear;
taLocation.clear;
txtA.requestFocus;
public static void mainString args
launchargs;
import java.sql;
import javafx.scene.control.TextField;
public class GeoIPClient
private static final String DATABASE "change";
private static final String USERNAME "change";
private static final String PASSWORD "change";
private static String driver "com.mysqljdbcDriver";
private static String url jdbc:mysql:change DATABASE;
private static String driverState ;
static
try
Class.forNamedriver;
catch Exception ex
driverState "Cannot load SQL Driver: ex;
;
public static String lookupIpTextField octet TextField octet TextField octet TextField octet throws SQLException
if driverState.isEmpty
return driverState;
var location "Somewhere";
return location;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
