Created
June 13, 2018 18:55
-
-
Save sogatanco/fa52954601a372eb6a8f6f1ebe8f2fe2 to your computer and use it in GitHub Desktop.
[Java Tutorial #7] - How to create Converter Calculator Aplication for STEEM and SBD 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 convertercalculator; | |
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 converter extends javax.swing.JFrame { | |
/** | |
* Creates new form converter | |
*/ | |
public converter() { | |
initComponents(); | |
} | |
public void sbdToSteem() throws Exception{ | |
String Data = getApi("https://uploadbeta.com/api/steemit/converter/?cached"); | |
JSONObject ObjData=new JSONObject(Data); | |
steemResult.setText(""+Double.parseDouble(sbdInput.getText())*ObjData.getDouble("sbd_to_steem")); | |
} | |
public void steemToSbd() throws Exception{ | |
String Data = getApi("https://uploadbeta.com/api/steemit/converter/?cached"); | |
JSONObject ObjData=new JSONObject(Data); | |
sbdResult.setText(""+Double.parseDouble(steemInput.getText())*ObjData.getDouble("steem_to_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(); | |
jLabel2 = new javax.swing.JLabel(); | |
sbdInput = new javax.swing.JTextField(); | |
steemResult = new javax.swing.JTextField(); | |
sbdtosteem = new javax.swing.JButton(); | |
jSeparator1 = new javax.swing.JSeparator(); | |
jSeparator2 = new javax.swing.JSeparator(); | |
steemInput = new javax.swing.JTextField(); | |
sbdResult = new javax.swing.JTextField(); | |
steemtosbd = new javax.swing.JButton(); | |
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); | |
jLabel1.setFont(new java.awt.Font("Papyrus", 0, 18)); // NOI18N | |
jLabel1.setText("SBD to STEEM"); | |
jLabel2.setFont(new java.awt.Font("Papyrus", 0, 18)); // NOI18N | |
jLabel2.setText("STEEM to SBD"); | |
steemResult.addActionListener(new java.awt.event.ActionListener() { | |
public void actionPerformed(java.awt.event.ActionEvent evt) { | |
steemResultActionPerformed(evt); | |
} | |
}); | |
sbdtosteem.setText("convert"); | |
sbdtosteem.addActionListener(new java.awt.event.ActionListener() { | |
public void actionPerformed(java.awt.event.ActionEvent evt) { | |
sbdtosteemActionPerformed(evt); | |
} | |
}); | |
steemtosbd.setText("convert"); | |
steemtosbd.addActionListener(new java.awt.event.ActionListener() { | |
public void actionPerformed(java.awt.event.ActionEvent evt) { | |
steemtosbdActionPerformed(evt); | |
} | |
}); | |
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(116, 116, 116) | |
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false) | |
.addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) | |
.addComponent(jSeparator1))) | |
.addGroup(jPanel1Layout.createSequentialGroup() | |
.addGap(115, 115, 115) | |
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) | |
.addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) | |
.addComponent(jSeparator2))) | |
.addGroup(jPanel1Layout.createSequentialGroup() | |
.addGap(48, 48, 48) | |
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) | |
.addGroup(jPanel1Layout.createSequentialGroup() | |
.addComponent(steemInput, javax.swing.GroupLayout.PREFERRED_SIZE, 101, javax.swing.GroupLayout.PREFERRED_SIZE) | |
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) | |
.addComponent(steemtosbd) | |
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) | |
.addComponent(sbdResult, javax.swing.GroupLayout.PREFERRED_SIZE, 101, javax.swing.GroupLayout.PREFERRED_SIZE)) | |
.addGroup(jPanel1Layout.createSequentialGroup() | |
.addComponent(sbdInput, javax.swing.GroupLayout.PREFERRED_SIZE, 101, javax.swing.GroupLayout.PREFERRED_SIZE) | |
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) | |
.addComponent(sbdtosteem) | |
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) | |
.addComponent(steemResult, javax.swing.GroupLayout.PREFERRED_SIZE, 101, javax.swing.GroupLayout.PREFERRED_SIZE))))) | |
.addContainerGap(61, Short.MAX_VALUE)) | |
); | |
jPanel1Layout.setVerticalGroup( | |
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) | |
.addGroup(jPanel1Layout.createSequentialGroup() | |
.addGap(19, 19, 19) | |
.addComponent(jLabel1) | |
.addGap(1, 1, 1) | |
.addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE) | |
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) | |
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) | |
.addComponent(sbdtosteem) | |
.addComponent(steemResult, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) | |
.addComponent(sbdInput, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) | |
.addGap(51, 51, 51) | |
.addComponent(jLabel2) | |
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) | |
.addComponent(jSeparator2, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE) | |
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) | |
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) | |
.addComponent(steemInput, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) | |
.addComponent(sbdResult, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) | |
.addComponent(steemtosbd)) | |
.addContainerGap(77, 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 steemResultActionPerformed(java.awt.event.ActionEvent evt) { | |
// TODO add your handling code here: | |
} | |
private void sbdtosteemActionPerformed(java.awt.event.ActionEvent evt) { | |
try { | |
sbdToSteem(); | |
} catch (Exception ex) { | |
Logger.getLogger(converter.class.getName()).log(Level.SEVERE, null, ex); | |
} | |
} | |
private void steemtosbdActionPerformed(java.awt.event.ActionEvent evt) { | |
try { | |
steemToSbd(); | |
} catch (Exception ex) { | |
Logger.getLogger(converter.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(converter.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); | |
} catch (InstantiationException ex) { | |
java.util.logging.Logger.getLogger(converter.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); | |
} catch (IllegalAccessException ex) { | |
java.util.logging.Logger.getLogger(converter.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); | |
} catch (javax.swing.UnsupportedLookAndFeelException ex) { | |
java.util.logging.Logger.getLogger(converter.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 converter().setVisible(true); | |
} | |
}); | |
} | |
// Variables declaration - do not modify | |
private javax.swing.JLabel jLabel1; | |
private javax.swing.JLabel jLabel2; | |
private javax.swing.JPanel jPanel1; | |
private javax.swing.JSeparator jSeparator1; | |
private javax.swing.JSeparator jSeparator2; | |
private javax.swing.JTextField sbdInput; | |
private javax.swing.JTextField sbdResult; | |
private javax.swing.JButton sbdtosteem; | |
private javax.swing.JTextField steemInput; | |
private javax.swing.JTextField steemResult; | |
private javax.swing.JButton steemtosbd; | |
// End of variables declaration | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment