Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
- /*
- * NewJFrame2.java
- *
- * Created on Sep 13, 2014, 11:45:53 PM
- */
- package aplikasi.yaya.frame;
- import aplikasi.yaya.koneksi.koneksi;
- import java.sql.SQLException;
- import javax.swing.JOptionPane;
- /**
- *
- * @author AINUNJARIAH
- */
- public class NewJFrame2 extends javax.swing.JFrame {
- aplikasi.yaya.koneksi.koneksi konek = new koneksi();
- /** Creates new form NewJFrame2 */
- public NewJFrame2() {
- initComponents();
- konek.koneksi();
- }
- /** 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() {
- jButton1 = new javax.swing.JButton();
- setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
- jButton1.setText("jButton1");
- jButton1.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jButton1ActionPerformed(evt);
- }
- });
- javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
- getContentPane().setLayout(layout);
- layout.setHorizontalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addGap(105, 105, 105)
- .addComponent(jButton1)
- .addContainerGap(222, Short.MAX_VALUE))
- );
- layout.setVerticalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addGap(88, 88, 88)
- .addComponent(jButton1)
- .addContainerGap(189, Short.MAX_VALUE))
- );
- pack();
- }// </editor-fold>
- private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
- try {
- // query untuk membaca SMS yang belum diproses
- String query = "SELECT * FROM inbox WHERE Processed ='false'";
- konek.res=konek.stat.executeQuery(query);
- while (konek.res.next())
- {
- // membaca ID SMS
- String id2 = konek.res.getString("ID");
- // membaca no pengirim
- String noPengirim = konek.res.getString("SenderNumber");
- // membaca pesan SMS dan mengubahnya menjadi kapital
- String msg = konek.res.getString("TextDecoded");
- // proses parsing
- // memecah pesan berdasarkan karakter <spasi>
- String []pecah = msg.split(" ");
- // jika kata terdepan dari SMS adalah 'saldo' maka cari saldo
- if ("saldo".equals(pecah[0]))
- {
- // baca idmasjid dari pesan SMS
- String idmasjid = pecah[1];
- // cari saldo berdasar idmasjid
- String query2 = "SELECT saldo FROM saldomasjid WHERE idmasjid ='"+idmasjid+"'";
- int hasil2=konek.stat.executeUpdate(query2);
- // cek bila data saldo tidak ditemukan
- if (hasil2==0) {
- String reply = "id masjid tidak ditemukan";
- }else{
- konek.res=konek.stat.executeQuery(query2);
- String saldo = konek.res.getString("saldo");
- String reply = "saldo Masjid Anda: "+saldo+"";
- }
- }
- else {
- String reply = "Maaf perintah salah, Cek FORMAT SMS ANDA : SALDO<spasi>ID MASJID";
- // membuat SMS balasan
- String query3 = "INSERT INTO outbox(DestinationNumber, TextDecoded,CreatorID) VALUES ('"+noPengirim+"', '"+reply+"','Gammu')";
- int hasil3 = konek.stat.executeUpdate(query3);
- // ubah saldo 'processed' menjadi 'true' untuk setiap SMS yang telah diproses
- String query4 = "UPDATE inbox SET Processed ='true' WHERE ID='"+id2+"'";
- int executeUpdate = konek.stat.executeUpdate(query4);
- }
- }
- System.out.println("suksess");
- } catch (SQLException e) {
- System.out.println(e);
- }
- }
- /**
- * @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(NewJFrame2.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (InstantiationException ex) {
- java.util.logging.Logger.getLogger(NewJFrame2.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (IllegalAccessException ex) {
- java.util.logging.Logger.getLogger(NewJFrame2.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (javax.swing.UnsupportedLookAndFeelException ex) {
- java.util.logging.Logger.getLogger(NewJFrame2.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 NewJFrame2().setVisible(true);
- }
- });
- }
- // Variables declaration - do not modify
- private javax.swing.JButton jButton1;
- // End of variables declaration
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement