Created
August 2, 2018 03:32
-
-
Save sogatanco/7dca6692ffbf9cc0d1ac6befeb1c3ac0 to your computer and use it in GitHub Desktop.
[Java Tutorial #9] - How to create java Aplication to compare 2 steemit account
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 compare; | |
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 Cmp extends javax.swing.JFrame { | |
/** | |
* Creates new form Cmp | |
*/ | |
public Cmp() { | |
initComponents(); | |
} | |
public void getData() throws Exception{ | |
String user1=account1.getText(); | |
String user2=account2.getText(); | |
String Data1 = getApi("https://uploadbeta.com/api/steemit/account/profile/?cached&id="+user1); | |
String Data2 = getApi("https://uploadbeta.com/api/steemit/account/profile/?cached&id="+user2); | |
JSONObject ObjData1=new JSONObject(Data1); | |
JSONObject ObjData2=new JSONObject(Data2); | |
usernrep1.setText("@"+ObjData1.getString("id")+" ("+ObjData1.getDouble("rep")+")"); | |
usernrep2.setText("@"+ObjData2.getString("id")+" ("+ObjData2.getDouble("rep")+")"); | |
created1.setText("Since "+ObjData1.getString("created")); | |
created2.setText("Since "+ObjData2.getString("created")); | |
steem1.setText(ObjData1.getDouble("steem")+" STEEM"); | |
steem2.setText(ObjData2.getDouble("steem")+" STEEM"); | |
sbd1.setText(ObjData1.getDouble("sbd")+" SBD"); | |
sbd2.setText(ObjData2.getDouble("sbd")+" SBD"); | |
} | |
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(); | |
account2 = new javax.swing.JTextField(); | |
compare = new javax.swing.JButton(); | |
usernrep2 = new javax.swing.JLabel(); | |
jLabel3 = new javax.swing.JLabel(); | |
account1 = new javax.swing.JTextField(); | |
jSeparator1 = new javax.swing.JSeparator(); | |
filler1 = new javax.swing.Box.Filler(new java.awt.Dimension(0, 0), new java.awt.Dimension(0, 0), new java.awt.Dimension(32767, 0)); | |
jSeparator3 = new javax.swing.JSeparator(); | |
usernrep1 = new javax.swing.JLabel(); | |
sbd1 = new javax.swing.JLabel(); | |
steem1 = new javax.swing.JLabel(); | |
created1 = new javax.swing.JLabel(); | |
created2 = new javax.swing.JLabel(); | |
steem2 = new javax.swing.JLabel(); | |
sbd2 = new javax.swing.JLabel(); | |
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); | |
jLabel1.setFont(new java.awt.Font("Papyrus", 0, 24)); // NOI18N | |
jLabel1.setText("Compare Account"); | |
jLabel1.setAutoscrolls(true); | |
account2.addActionListener(new java.awt.event.ActionListener() { | |
public void actionPerformed(java.awt.event.ActionEvent evt) { | |
account2ActionPerformed(evt); | |
} | |
}); | |
compare.setText("Compare"); | |
compare.addActionListener(new java.awt.event.ActionListener() { | |
public void actionPerformed(java.awt.event.ActionEvent evt) { | |
compareActionPerformed(evt); | |
} | |
}); | |
usernrep2.setFont(new java.awt.Font("Tempus Sans ITC", 0, 18)); // NOI18N | |
usernrep2.setText("Name(00)"); | |
jLabel3.setText("With"); | |
account1.addActionListener(new java.awt.event.ActionListener() { | |
public void actionPerformed(java.awt.event.ActionEvent evt) { | |
account1ActionPerformed(evt); | |
} | |
}); | |
jSeparator3.setOrientation(javax.swing.SwingConstants.VERTICAL); | |
usernrep1.setFont(new java.awt.Font("Tempus Sans ITC", 0, 18)); // NOI18N | |
usernrep1.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT); | |
usernrep1.setText("Name(00)"); | |
usernrep1.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT); | |
sbd1.setFont(new java.awt.Font("Orator Std", 1, 14)); // NOI18N | |
sbd1.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT); | |
sbd1.setText("00 SBD"); | |
sbd1.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT); | |
steem1.setFont(new java.awt.Font("Orator Std", 1, 14)); // NOI18N | |
steem1.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT); | |
steem1.setText("00 STEEM"); | |
steem1.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT); | |
created1.setFont(new java.awt.Font("Orator Std", 1, 14)); // NOI18N | |
created1.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT); | |
created1.setText("created"); | |
created1.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT); | |
created2.setFont(new java.awt.Font("Orator Std", 1, 14)); // NOI18N | |
created2.setHorizontalAlignment(javax.swing.SwingConstants.LEFT); | |
created2.setText("created"); | |
created2.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT); | |
steem2.setFont(new java.awt.Font("Orator Std", 1, 14)); // NOI18N | |
steem2.setHorizontalAlignment(javax.swing.SwingConstants.LEFT); | |
steem2.setText("00 STEEM"); | |
steem2.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT); | |
sbd2.setFont(new java.awt.Font("Orator Std", 1, 14)); // NOI18N | |
sbd2.setHorizontalAlignment(javax.swing.SwingConstants.LEFT); | |
sbd2.setText("00 SBD"); | |
sbd2.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT); | |
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1); | |
jPanel1.setLayout(jPanel1Layout); | |
jPanel1Layout.setHorizontalGroup( | |
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) | |
.addGroup(jPanel1Layout.createSequentialGroup() | |
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) | |
.addGroup(jPanel1Layout.createSequentialGroup() | |
.addGap(106, 106, 106) | |
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) | |
.addGroup(jPanel1Layout.createSequentialGroup() | |
.addComponent(account1, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE) | |
.addGap(18, 18, 18) | |
.addComponent(jLabel3) | |
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) | |
.addComponent(account2, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE)) | |
.addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 250, javax.swing.GroupLayout.PREFERRED_SIZE))) | |
.addGroup(jPanel1Layout.createSequentialGroup() | |
.addContainerGap() | |
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) | |
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false) | |
.addComponent(steem1, javax.swing.GroupLayout.DEFAULT_SIZE, 162, Short.MAX_VALUE) | |
.addComponent(sbd1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) | |
.addComponent(created1, javax.swing.GroupLayout.PREFERRED_SIZE, 229, javax.swing.GroupLayout.PREFERRED_SIZE) | |
.addComponent(usernrep1, javax.swing.GroupLayout.PREFERRED_SIZE, 204, javax.swing.GroupLayout.PREFERRED_SIZE)) | |
.addGap(18, 18, 18) | |
.addComponent(jSeparator3, javax.swing.GroupLayout.PREFERRED_SIZE, 11, javax.swing.GroupLayout.PREFERRED_SIZE) | |
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) | |
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) | |
.addComponent(steem2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) | |
.addComponent(sbd2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) | |
.addComponent(usernrep2, javax.swing.GroupLayout.DEFAULT_SIZE, 231, Short.MAX_VALUE) | |
.addComponent(created2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))) | |
.addGroup(jPanel1Layout.createSequentialGroup() | |
.addGap(211, 211, 211) | |
.addComponent(compare) | |
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) | |
.addComponent(filler1, javax.swing.GroupLayout.PREFERRED_SIZE, 56, javax.swing.GroupLayout.PREFERRED_SIZE))) | |
.addContainerGap()) | |
.addGroup(jPanel1Layout.createSequentialGroup() | |
.addGap(183, 183, 183) | |
.addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 146, javax.swing.GroupLayout.PREFERRED_SIZE) | |
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) | |
); | |
jPanel1Layout.setVerticalGroup( | |
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) | |
.addGroup(jPanel1Layout.createSequentialGroup() | |
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) | |
.addGroup(jPanel1Layout.createSequentialGroup() | |
.addGap(19, 19, 19) | |
.addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE) | |
.addGap(18, 18, 18) | |
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) | |
.addComponent(jLabel3, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) | |
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) | |
.addComponent(account2) | |
.addComponent(account1))) | |
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) | |
.addComponent(compare, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)) | |
.addGroup(jPanel1Layout.createSequentialGroup() | |
.addContainerGap() | |
.addComponent(filler1, javax.swing.GroupLayout.PREFERRED_SIZE, 87, javax.swing.GroupLayout.PREFERRED_SIZE) | |
.addGap(35, 35, 35))) | |
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) | |
.addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 15, javax.swing.GroupLayout.PREFERRED_SIZE) | |
.addGap(5, 5, 5) | |
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) | |
.addComponent(jSeparator3, javax.swing.GroupLayout.PREFERRED_SIZE, 117, javax.swing.GroupLayout.PREFERRED_SIZE) | |
.addGroup(jPanel1Layout.createSequentialGroup() | |
.addComponent(usernrep2, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE) | |
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) | |
.addComponent(created2) | |
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) | |
.addComponent(steem2) | |
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) | |
.addComponent(sbd2)) | |
.addGroup(jPanel1Layout.createSequentialGroup() | |
.addComponent(usernrep1, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE) | |
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) | |
.addComponent(created1) | |
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) | |
.addComponent(steem1) | |
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) | |
.addComponent(sbd1))) | |
.addGap(19, 19, 19)) | |
); | |
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 account2ActionPerformed(java.awt.event.ActionEvent evt) { | |
// TODO add your handling code here: | |
} | |
private void compareActionPerformed(java.awt.event.ActionEvent evt) { | |
try { | |
getData(); | |
} catch (Exception ex) { | |
Logger.getLogger(Cmp.class.getName()).log(Level.SEVERE, null, ex); | |
} | |
} | |
private void account1ActionPerformed(java.awt.event.ActionEvent evt) { | |
// TODO add your handling code here: | |
} | |
/** | |
* @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(Cmp.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); | |
} catch (InstantiationException ex) { | |
java.util.logging.Logger.getLogger(Cmp.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); | |
} catch (IllegalAccessException ex) { | |
java.util.logging.Logger.getLogger(Cmp.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); | |
} catch (javax.swing.UnsupportedLookAndFeelException ex) { | |
java.util.logging.Logger.getLogger(Cmp.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 Cmp().setVisible(true); | |
} | |
}); | |
} | |
// Variables declaration - do not modify | |
private javax.swing.JTextField account1; | |
private javax.swing.JTextField account2; | |
private javax.swing.JButton compare; | |
private javax.swing.JLabel created1; | |
private javax.swing.JLabel created2; | |
private javax.swing.Box.Filler filler1; | |
private javax.swing.JLabel jLabel1; | |
private javax.swing.JLabel jLabel3; | |
private javax.swing.JPanel jPanel1; | |
private javax.swing.JSeparator jSeparator1; | |
private javax.swing.JSeparator jSeparator3; | |
private javax.swing.JLabel sbd1; | |
private javax.swing.JLabel sbd2; | |
private javax.swing.JLabel steem1; | |
private javax.swing.JLabel steem2; | |
private javax.swing.JLabel usernrep1; | |
private javax.swing.JLabel usernrep2; | |
// End of variables declaration | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment