[Java Tutorial #6] - How to create GUI java aplication for checking STEEM POWER DETAIL using Netbeans
Repository
https://github.com/dmlloyd/openjdk
What Will I Learn?
- You will learn How to create GUI form for this aplication
- You will learn API to get Estimated reward Data
- You will learn how to split data or take the important data from API
- You will learn how to dislay data to the form
Requirements
- Basic knowledges about java programing
- Basic Knowledges about API
- Need to Install Netbeans for easy pratice
Difficulty
- Basic
Tutorial Contents
In this tutorial, I will explain how to create an app from java to check the steam power detail of a steemit account. The application we will make will show details of how much steempower efective, the amount of steampower that is delegated, the amount of steempower received and the total amount of steempower owned by an account :
Let's start the tutorial :
Open Netbeans IDE software and create new project. Choose Java Aplication and click next. Then Rename the project and click finish.
Add new jFrameForm in your Source Package
Rename the form
Click on panel component and drag it to the form
Add Label, TextField and Button on Panel, just follow the components on picture bellow :
here the component detail:
We already have a form, Now open
source
and start to edit the code.Create The method to get Data from URL. This method in
java.net.*
method. So before your start use this method import the package first
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.logging.Level;
import java.util.logging.Logger;
- Then Create
getApi()
method.
public String getApi(String url) throws Exception{
URL oracle=new URL(url);
HttpURLConnection httpcon = (HttpURLConnection) oracle.openConnection();
httpcon.addRequestProperty("User-Agent", "Mozilla/5.0");
BufferedReader in = new BufferedReader(new InputStreamReader(httpcon.getInputStream()));
String inputLine;
while ((inputLine = in.readLine()) != null){
return inputLine;
}
in.close();
return null;
}
Code | Explanation |
---|---|
getApi() | Method Name |
String url | The Parameter |
throws Exception | Some method to catch error |
URL oracle=new URL(url); | Decrlarating new URL |
HttpURLConnection httpcon = (HttpURLConnection) oracle.openConnection(); | class initiation to get URL connection. |
httpcon.addRequestProperty("User-Agent", "Mozilla/5.0"); | Add browser property, Here I add Mozilla 5.-0 |
BufferedReader in = new BufferedReader(new InputStreamReader(httpcon.getInputStream())); | method Read input from http connection. |
return inputLine; | return the output |
in.close(); | closie input stream reader |
- Now create the method to get Data from url API. Here I rename with
getDeati()
method.
public void getDetail() throws Exception{
}
- Get The author name from user input.
String User=Author.getText();
- Call get Data method with parameter is the API URL. The API URL is from https://helloacm.com/tools/steemit/ , you can get more API there :
String Data = getApi("https://uploadbeta.com/api/steemit/account/steempower/?cached&id="+User);
- To get the important data from result we need split it. Here we need use java-json library. Dowload it here : http://www.java2s.com/Code/Jar/j/Downloadjavajsonjar.htm . Extract and add to project Libraries. Then import it to your file.
import org.json.JSONObject;
- Before spliting data we need convert it to JSONObject to easy in Spliting
JSONObject ObjData=new JSONObject(Data);
- Get Some important data in JSONObject and retrieve it in a variabel
Double Esp=ObjData.getDouble("esp");
Double Delegated=ObjData.getDouble("delegated_sp");
Double Received=ObjData.getDouble("received_sp");
Code | Explanation |
---|---|
Double Esp | Variable decleration with the name is Esp and the type is Double |
ObjData.getDouble("delegated_sp"); | ObjData is the Object Name, getDouble some method to get Double value from some element, And ("delegated_sp") the element name in object |
- The Api didn't provide total SP owned by some author. It just provide efectice, delegated and received SP. To get total SP owned by some autor we need to do arithmatic operation. Here the code :
Double Total=Esp-Received+Delegated;
- Display the data to the form
total.setText(""+Total);
delegated.setText(""+Delegated);
received.setText(""+Received);
esp.setText(""+Esp);
Code | Explanation |
---|---|
total | the name of textfield variabel |
setText() | a method to set Text in java component |
""+Total | The Variable that will be set as text in componen, because the variabel type is double we need combine with a string. So I use ""+ . |
- Call the
getDetail()
method in button. Open the aplication design form and double click on button. then add this code.
try {
getDetail();
} catch (Exception ex) {
Logger.getLogger(SpDetail.class.getName()).log(Level.SEVERE, null, ex);
}
Now try to run the aplication, and input some author name then press
CHECK IT
button
Finish, the aplication is running rightly. You can get the full code on my gist. The link is bellow
Curriculum
- [Java Tutorial] - How to create some java aplication to display Live SBD price from bittrex API using Netbeans
- [Java Tutorial #2] - How to create GUI aplication for displaying Live SBD price using Netbeans
- [Java Tutorial #3] - How to create GUI java aplication for displaying Steemit account data using Netbeans
- [Java Tutorial #4] - How to create Calculator java aplication to convert STEEM to IDR using Netbeans
- [Java Tutorial #5] - How to create GUI java aplication for checking The Estimated Reward in Last Week using Netbeans
Proof of Work Done
https://gist.github.com/team2dev/f056957dd36d735a888e829eb4de33d5
Thank you for your contribution.
While I liked the content of your contribution, I would still like to extend few advices for your upcoming contributions:
Looking forward to your upcoming tutorials.
Your contribution has been evaluated according to Utopian policies and guidelines, as well as a predefined set of questions pertaining to the category.
To view those questions and the relevant answers related to your post, click here.
Need help? Write a ticket on https://support.utopian.io/.
Chat with us on Discord.
[utopian-moderator]
Hey @team2dev
Thanks for contributing on Utopian.
We’re already looking forward to your next contribution!
Contributing on Utopian
Learn how to contribute on our website or by watching this tutorial on Youtube.
Want to chat? Join us on Discord https://discord.gg/h52nFrV.
Vote for Utopian Witness!