UserInterface.DoctorRole.SendAlertMessage.java Source code

Java tutorial

Introduction

Here is the source code for UserInterface.DoctorRole.SendAlertMessage.java

Source

/*
 * 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 UserInterface.DoctorRole;

import com.twilio.sdk.TwilioRestClient;
import com.twilio.sdk.TwilioRestException;
import com.twilio.sdk.resource.factory.MessageFactory;
import com.twilio.sdk.resource.instance.Message;
import java.awt.CardLayout;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;

/**
 *
 * @author shivam
 */
public class SendAlertMessage extends javax.swing.JPanel {
    private JPanel container;

    /**
     * Creates new form SendAlertMessage
     */
    public SendAlertMessage(JPanel container) {
        initComponents();
        this.container = container;
    }

    /**
     * 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">//GEN-BEGIN:initComponents
    private void initComponents() {

        NumberTextField = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        MessageBtn = new javax.swing.JButton();
        backjButton2 = new javax.swing.JButton();

        setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());
        add(NumberTextField, new org.netbeans.lib.awtextra.AbsoluteConstraints(213, 111, 119, -1));

        jLabel1.setText("Enter Number");
        add(jLabel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(73, 116, -1, -1));

        jLabel2.setFont(new java.awt.Font("Lucida Grande", 1, 24)); // NOI18N
        jLabel2.setText("Send Message");
        add(jLabel2, new org.netbeans.lib.awtextra.AbsoluteConstraints(118, 39, -1, -1));

        MessageBtn.setIcon(
                new javax.swing.ImageIcon(getClass().getResource("/UserInterface/DoctorRole/images (2).jpeg"))); // NOI18N
        MessageBtn.setText("Send Message");
        MessageBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                MessageBtnActionPerformed(evt);
            }
        });
        add(MessageBtn, new org.netbeans.lib.awtextra.AbsoluteConstraints(230, 210, 60, 70));

        backjButton2.setFont(new java.awt.Font("Tahoma", 0, 13)); // NOI18N
        backjButton2.setText("<< Back");
        backjButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                backjButton2ActionPerformed(evt);
            }
        });
        add(backjButton2, new org.netbeans.lib.awtextra.AbsoluteConstraints(40, 240, 80, -1));
    }// </editor-fold>//GEN-END:initComponents

    private void MessageBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_MessageBtnActionPerformed
        // TODO add your handling code here:
        try {
            TwilioRestClient client = new TwilioRestClient("ACd4d9c14696f348fe21e4506a5e7b14e3",
                    "d83be392f0c78d3a493675bf8d7942f1");
            List<NameValuePair> params = new ArrayList<NameValuePair>();
            String Number = NumberTextField.getText();
            params.add(new BasicNameValuePair("To", Number));
            params.add(new BasicNameValuePair("From", "+19073122832"));
            params.add(new BasicNameValuePair("Body", "Donor is Currently Avaliable"));
            MessageFactory messageFactory = client.getAccount().getMessageFactory();
            Message message = (Message) messageFactory.create(params);
            JOptionPane.showMessageDialog(null, "Message Sent");
        } catch (TwilioRestException ex) {
            Logger.getLogger(SelectMatchingPatientJPanel.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_MessageBtnActionPerformed

    private void backjButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_backjButton2ActionPerformed
        // TODO add your handling code here:
        container.remove(this);
        CardLayout layout = (CardLayout) container.getLayout();
        layout.previous(container);
    }//GEN-LAST:event_backjButton2ActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton MessageBtn;
    private javax.swing.JTextField NumberTextField;
    private javax.swing.JButton backjButton2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    // End of variables declaration//GEN-END:variables
}