Created
June 12, 2018 09:36
-
-
Save sogatanco/f056957dd36d735a888e829eb4de33d5 to your computer and use it in GitHub Desktop.
[Java Tutorial #6] - How to create GUI java aplication for checking STEEM POWER DETAIL using Netbeans
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* To change this license header, choose License Headers in Project Properties. | |
* To change this template file, choose Tools | Templates | |
* and open the template in the editor. | |
*/ | |
package spdetail; | |
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; | |
import org.json.JSONObject; | |
/** | |
* | |
* @author ACER | |
*/ | |
public class SpDetail extends javax.swing.JFrame { | |
/** | |
* Creates new form SpDetail | |
*/ | |
public SpDetail() { | |
initComponents(); | |
} | |
public void getDetail() throws Exception{ | |
String User=Author.getText(); | |
String Data = getApi("https://uploadbeta.com/api/steemit/account/steempower/?cached&id="+User); | |
JSONObject ObjData=new JSONObject(Data); | |
Double Esp=ObjData.getDouble("esp"); | |
Double Delegated=ObjData.getDouble("delegated_sp"); | |
Double Received=ObjData.getDouble("received_sp"); | |
Double Total=Esp-Received+Delegated; | |
total.setText(""+Total); | |
delegated.setText(""+Delegated); | |
received.setText(""+Received); | |
esp.setText(""+Esp); | |
} | |
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; | |
} | |
/** | |
* This method is called from within the constructor to initialize the form. | |
* WARNING: Do NOT modify this code. The content of this method is always | |
* regenerated by the Form Editor. | |
*/ | |
@SuppressWarnings("unchecked") | |
// <editor-fold defaultstate="collapsed" desc="Generated Code"> | |
private void initComponents() { | |
jPanel1 = new javax.swing.JPanel(); | |
jLabel1 = new javax.swing.JLabel(); | |
jSeparator1 = new javax.swing.JSeparator(); | |
jSeparator2 = new javax.swing.JSeparator(); | |
Author = new javax.swing.JTextField(); | |
jButton1 = new javax.swing.JButton(); | |
jLabel2 = new javax.swing.JLabel(); | |
jLabel3 = new javax.swing.JLabel(); | |
jLabel4 = new javax.swing.JLabel(); | |
jLabel5 = new javax.swing.JLabel(); | |
jLabel6 = new javax.swing.JLabel(); | |
jLabel7 = new javax.swing.JLabel(); | |
jLabel8 = new javax.swing.JLabel(); | |
jLabel9 = new javax.swing.JLabel(); | |
total = new javax.swing.JLabel(); | |
delegated = new javax.swing.JLabel(); | |
esp = new javax.swing.JLabel(); | |
received = new javax.swing.JLabel(); | |
jLabel14 = new javax.swing.JLabel(); | |
jLabel15 = new javax.swing.JLabel(); | |
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); | |
jLabel1.setFont(new java.awt.Font("Trajan Pro", 0, 18)); // NOI18N | |
jLabel1.setText("See your SP Detail Here !"); | |
Author.addActionListener(new java.awt.event.ActionListener() { | |
public void actionPerformed(java.awt.event.ActionEvent evt) { | |
AuthorActionPerformed(evt); | |
} | |
}); | |
jButton1.setText("CHECK IT"); | |
jButton1.addActionListener(new java.awt.event.ActionListener() { | |
public void actionPerformed(java.awt.event.ActionEvent evt) { | |
jButton1ActionPerformed(evt); | |
} | |
}); | |
jLabel2.setFont(new java.awt.Font("Orator Std", 0, 14)); // NOI18N | |
jLabel2.setText("TOTAL EFECTIVE SP"); | |
jLabel3.setFont(new java.awt.Font("Orator Std", 0, 14)); // NOI18N | |
jLabel3.setText("DELEGATED SP"); | |
jLabel4.setFont(new java.awt.Font("Orator Std", 0, 14)); // NOI18N | |
jLabel4.setText("RECEIVED SP"); | |
jLabel5.setFont(new java.awt.Font("Orator Std", 0, 14)); // NOI18N | |
jLabel5.setText("TOTAL YOUR OWN SP"); | |
jLabel6.setFont(new java.awt.Font("Orator Std", 0, 14)); // NOI18N | |
jLabel6.setText(":"); | |
jLabel7.setFont(new java.awt.Font("Orator Std", 0, 14)); // NOI18N | |
jLabel7.setText(":"); | |
jLabel8.setFont(new java.awt.Font("Orator Std", 0, 14)); // NOI18N | |
jLabel8.setText(":"); | |
jLabel9.setFont(new java.awt.Font("Orator Std", 0, 14)); // NOI18N | |
jLabel9.setText(":"); | |
total.setFont(new java.awt.Font("Orator Std", 0, 14)); // NOI18N | |
total.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT); | |
total.setText("00.00"); | |
delegated.setFont(new java.awt.Font("Orator Std", 0, 14)); // NOI18N | |
delegated.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT); | |
delegated.setText("00.00"); | |
esp.setFont(new java.awt.Font("Orator Std", 0, 14)); // NOI18N | |
esp.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT); | |
esp.setText("00.00"); | |
received.setFont(new java.awt.Font("Orator Std", 0, 14)); // NOI18N | |
received.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT); | |
received.setText("00.00"); | |
jLabel14.setFont(new java.awt.Font("Viner Hand ITC", 0, 14)); // NOI18N | |
jLabel14.setText("Kind Regards"); | |
jLabel15.setFont(new java.awt.Font("Viner Hand ITC", 0, 14)); // NOI18N | |
jLabel15.setText("@TEAM2DEV"); | |
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1); | |
jPanel1.setLayout(jPanel1Layout); | |
jPanel1Layout.setHorizontalGroup( | |
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) | |
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup() | |
.addGap(0, 0, Short.MAX_VALUE) | |
.addComponent(jButton1) | |
.addGap(171, 171, 171)) | |
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup() | |
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) | |
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup() | |
.addGap(57, 57, 57) | |
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) | |
.addGroup(jPanel1Layout.createSequentialGroup() | |
.addComponent(jLabel2) | |
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) | |
.addComponent(jLabel9) | |
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) | |
.addComponent(esp)) | |
.addGroup(jPanel1Layout.createSequentialGroup() | |
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) | |
.addComponent(jLabel5) | |
.addComponent(jLabel3) | |
.addComponent(jLabel4)) | |
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) | |
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) | |
.addGroup(jPanel1Layout.createSequentialGroup() | |
.addComponent(jLabel8) | |
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) | |
.addComponent(received)) | |
.addGroup(jPanel1Layout.createSequentialGroup() | |
.addComponent(jLabel7) | |
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) | |
.addComponent(delegated)) | |
.addGroup(jPanel1Layout.createSequentialGroup() | |
.addComponent(jLabel6) | |
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) | |
.addComponent(total)))))) | |
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup() | |
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) | |
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup() | |
.addGap(83, 83, 83) | |
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) | |
.addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) | |
.addComponent(jSeparator1))) | |
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup() | |
.addGap(135, 135, 135) | |
.addComponent(Author, javax.swing.GroupLayout.PREFERRED_SIZE, 152, javax.swing.GroupLayout.PREFERRED_SIZE))) | |
.addGap(0, 36, Short.MAX_VALUE)) | |
.addGroup(jPanel1Layout.createSequentialGroup() | |
.addGap(0, 0, Short.MAX_VALUE) | |
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) | |
.addComponent(jLabel15) | |
.addComponent(jLabel14)))) | |
.addGap(47, 47, 47)) | |
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) | |
.addGroup(jPanel1Layout.createSequentialGroup() | |
.addGap(136, 136, 136) | |
.addComponent(jSeparator2, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE) | |
.addContainerGap(131, Short.MAX_VALUE))) | |
); | |
jPanel1Layout.setVerticalGroup( | |
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) | |
.addGroup(jPanel1Layout.createSequentialGroup() | |
.addGap(19, 19, 19) | |
.addComponent(jLabel1) | |
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) | |
.addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE) | |
.addGap(43, 43, 43) | |
.addComponent(Author, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) | |
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) | |
.addComponent(jButton1) | |
.addGap(43, 43, 43) | |
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) | |
.addComponent(jLabel5) | |
.addComponent(jLabel6) | |
.addComponent(total)) | |
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) | |
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) | |
.addComponent(jLabel3) | |
.addComponent(jLabel7) | |
.addComponent(delegated)) | |
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) | |
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) | |
.addComponent(jLabel4) | |
.addComponent(jLabel8) | |
.addComponent(received)) | |
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) | |
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) | |
.addComponent(jLabel2) | |
.addComponent(jLabel9) | |
.addComponent(esp)) | |
.addGap(18, 18, 18) | |
.addComponent(jLabel14) | |
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 23, Short.MAX_VALUE) | |
.addComponent(jLabel15)) | |
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) | |
.addGroup(jPanel1Layout.createSequentialGroup() | |
.addGap(54, 54, 54) | |
.addComponent(jSeparator2, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE) | |
.addContainerGap(290, Short.MAX_VALUE))) | |
); | |
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); | |
getContentPane().setLayout(layout); | |
layout.setHorizontalGroup( | |
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) | |
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) | |
); | |
layout.setVerticalGroup( | |
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) | |
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) | |
); | |
pack(); | |
}// </editor-fold> | |
private void AuthorActionPerformed(java.awt.event.ActionEvent evt) { | |
// TODO add your handling code here: | |
} | |
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) { | |
try { | |
getDetail(); | |
} catch (Exception ex) { | |
Logger.getLogger(SpDetail.class.getName()).log(Level.SEVERE, null, ex); | |
} | |
} | |
/** | |
* @param args the command line arguments | |
*/ | |
public static void main(String args[]) { | |
/* Set the Nimbus look and feel */ | |
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) "> | |
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel. | |
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html | |
*/ | |
try { | |
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) { | |
if ("Nimbus".equals(info.getName())) { | |
javax.swing.UIManager.setLookAndFeel(info.getClassName()); | |
break; | |
} | |
} | |
} catch (ClassNotFoundException ex) { | |
java.util.logging.Logger.getLogger(SpDetail.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); | |
} catch (InstantiationException ex) { | |
java.util.logging.Logger.getLogger(SpDetail.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); | |
} catch (IllegalAccessException ex) { | |
java.util.logging.Logger.getLogger(SpDetail.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); | |
} catch (javax.swing.UnsupportedLookAndFeelException ex) { | |
java.util.logging.Logger.getLogger(SpDetail.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); | |
} | |
//</editor-fold> | |
/* Create and display the form */ | |
java.awt.EventQueue.invokeLater(new Runnable() { | |
public void run() { | |
new SpDetail().setVisible(true); | |
} | |
}); | |
} | |
// Variables declaration - do not modify | |
private javax.swing.JTextField Author; | |
private javax.swing.JLabel delegated; | |
private javax.swing.JLabel esp; | |
private javax.swing.JButton jButton1; | |
private javax.swing.JLabel jLabel1; | |
private javax.swing.JLabel jLabel14; | |
private javax.swing.JLabel jLabel15; | |
private javax.swing.JLabel jLabel2; | |
private javax.swing.JLabel jLabel3; | |
private javax.swing.JLabel jLabel4; | |
private javax.swing.JLabel jLabel5; | |
private javax.swing.JLabel jLabel6; | |
private javax.swing.JLabel jLabel7; | |
private javax.swing.JLabel jLabel8; | |
private javax.swing.JLabel jLabel9; | |
private javax.swing.JPanel jPanel1; | |
private javax.swing.JSeparator jSeparator1; | |
private javax.swing.JSeparator jSeparator2; | |
private javax.swing.JLabel received; | |
private javax.swing.JLabel total; | |
// End of variables declaration | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment