https://github.com/dmlloyd/openjdk
On this occasion we will create a desktop application to display the actual location as well as google maps. In accordance with the title of this contribution, we will make this application using java programming language.
The application that we will create consists of a form which contains a textfield and a button. When the user inputs a location in the textfield and presses the search button, this application will display a map of that location.
Where do we take the location data? whether from ourselves or we take it from another platform. We retrieve location data from Google Map, because for now Google Map is one of the best map applications. How do we do it? let's look at the following tutorial.
open Netbeans IDE software then creat new project
Add new JFrame form
Design the form that must contain a textfield and a button like following screenshot
Rename the variable of the components
add the some method. here I rename the locate() method
Left Click on hint simbol then double click on create method
Scroll the code page to bottom until you get like this
Create a string variable to accommodate the Text that input by user.
String a=location.getText().replace(" ","+");
replace() method we use to replace the space that input by user with the + sign. Why ? because we will get map from google map link, and no space in link but usually used + sign to replace the space
final JFrame frame=new JFrame();
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
frame.setSize(1280,720);
frame the variable name for new JFrame. setDefaultCloseOperation method to set the the exit button on right-top corner. setSize() is method to set the width and height of the new frame
Note : before adding the above code you need to import package import javax.swing.JFrame;
final JFXPanel fxpanel=new JFXPanel();
frame.add(fxpanel);
Platform.runLater(new Runnable(){
@Override
public void run() {
WebEngine engine;
WebView wv =new WebView();
engine=wv.getEngine();
fxpanel.setScene(new Scene(wv));
engine.load("https://www.google.com/maps/place/"+a);
}
});
Platform.runLater method to run some task on JFXpanel
@Override to implement all abstract method
public void run() is run method.
WebEngine engine; Inisialize web engine
WebView wv =new WebView(); inssialize web view
engine=wv.getEngine();get view from web engine
fxpanel.setScene(new Scene(wv));set scene on JFXpanel
engine.load("https://www.google.com/maps/place/"+a); load the url
Here I will explain how to create a url to display the location of google map.
Try to open google map on your browser and type some location on search field then press enter
you can see the string las Vegas in url
So the default url is https://www.google.com/maps/place/. To get some location we need just add string after default url.
You can see engine.load("https://www.google.com/maps/place/"+a);. I set the default url and combine with some variable that contain the location input by user.
Click the play button to run the project. Then type some location to try it
Press the search button to see location
https://gist.github.com/team2dev/78f3a864dbbe9c29b7c7c615b584ddff