On Tuesday, April 23, 2013 2:51:17 PM UTC+5:30, Clement Murimi wrote:
>
> I have the same problem. How do can I be able to start the application once
>
>
> package marksheet;
> import java.awt.*;
> import java.util.logging.Level;
> import java.util.logging.Logger;
> import javax.swing.JOptionPane;
> import org.smslib.AGateway;
>
> import org.smslib.IOutboundMessageNotification;
> import org.smslib.Library;
> import org.smslib.OutboundMessage;
> import org.smslib.Service;
> import org.smslib.modem.SerialModemGateway;
>
> /**
> *
> * @author user
> */
> public class MessageFrame extends javax.swing.JFrame {
>
> /** Creates new form MessageFrame */
> public MessageFrame() {
> initComponents();
>
> }
>
>
>
> }
> /** 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();
> number = new javax.swing.JTextField();
> sendbutton = new javax.swing.JButton();
> jScrollPane1 = new javax.swing.JScrollPane();
> message = new javax.swing.JTextArea();
> jLabel3 = new javax.swing.JLabel();
> jButton1 = new javax.swing.JButton();
>
>
> setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
>
> jLabel1.setFont(new java.awt.Font("Tw Cen MT Condensed Extra
> Bold", 1, 14)); // NOI18N
> jLabel1.setText("SEND SMS");
>
> jLabel2.setText("TO");
>
> number.addActionListener(new java.awt.event.ActionListener() {
> public void actionPerformed(java.awt.event.ActionEvent evt) {
> numberActionPerformed(evt);
> }
> });
>
> sendbutton.setText("SEND");
> sendbutton.addActionListener(new java.awt.event.ActionListener() {
> public void actionPerformed(java.awt.event.ActionEvent evt) {
> sendbuttonActionPerformed(evt);
> }
> });
>
> message.setColumns(20);
> message.setRows(5);
> jScrollPane1.setViewportView(message);
>
> jLabel3.setText("Message");
>
> jButton1.setText("CANCEL");
> jButton1.addActionListener(new java.awt.event.ActionListener() {
> public void actionPerformed(java.awt.event.ActionEvent evt) {
> jButton1ActionPerformed(evt);
> }
> });
>
> 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()
> .addContainerGap(151, Short.MAX_VALUE)
> .addComponent(jLabel1,
> javax.swing.GroupLayout.PREFERRED_SIZE, 100,
> javax.swing.GroupLayout.PREFERRED_SIZE)
> .addGap(144, 144, 144))
> .addGroup(jPanel1Layout.createSequentialGroup()
> .addContainerGap()
>
> .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
> .addComponent(jLabel2,
> javax.swing.GroupLayout.PREFERRED_SIZE, 41,
> javax.swing.GroupLayout.PREFERRED_SIZE)
> .addComponent(jLabel3))
> .addGap(38, 38, 38)
>
> .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING,
>
> false)
> .addGroup(jPanel1Layout.createSequentialGroup()
> .addComponent(sendbutton,
> javax.swing.GroupLayout.PREFERRED_SIZE, 89,
> javax.swing.GroupLayout.PREFERRED_SIZE)
>
> .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED,
> javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
> .addComponent(jButton1))
> .addComponent(jScrollPane1)
> .addComponent(number,
> javax.swing.GroupLayout.DEFAULT_SIZE, 203, Short.MAX_VALUE))
> .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE,
> Short.MAX_VALUE))
> );
> jPanel1Layout.setVerticalGroup(
>
> jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
> .addGroup(jPanel1Layout.createSequentialGroup()
> .addContainerGap()
> .addComponent(jLabel1)
> .addGap(15, 15, 15)
>
> .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
> .addComponent(jLabel2,
> javax.swing.GroupLayout.PREFERRED_SIZE, 24,
> javax.swing.GroupLayout.PREFERRED_SIZE)
> .addComponent(number,
> javax.swing.GroupLayout.PREFERRED_SIZE,
> javax.swing.GroupLayout.DEFAULT_SIZE,
> javax.swing.GroupLayout.PREFERRED_SIZE))
>
> .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
>
> .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
> .addComponent(jScrollPane1,
> javax.swing.GroupLayout.PREFERRED_SIZE, 147,
> javax.swing.GroupLayout.PREFERRED_SIZE)
> .addComponent(jLabel3))
> .addGap(18, 18, 18)
>
> .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
> .addComponent(sendbutton)
> .addComponent(jButton1))
> .addContainerGap(22, 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.Alignment.TRAILING,
> 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.Alignment.TRAILING,
> javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE,
> Short.MAX_VALUE)
> );
>
> pack();
> }// </editor-fold>
>
> private void sendbuttonActionPerformed(java.awt.event.ActionEvent evt)
> {
> try {
> doIt();
>
> } catch (Exception ex) {
>
> Logger.getLogger(MessageFrame.class.getName()).log(Level.SEVERE, null, ex);
> JOptionPane.showMessageDialog(this, "Message Sending Failed");
> }
>
> }
>
> private void numberActionPerformed(java.awt.event.ActionEvent evt) {
>
> // TODO add your handling code here:
> }
>
> private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
>
> this.dispose(); // TODO add your handling code here:
> }
>
> public void doIt() throws Exception
> {
>
> OutboundNotification outboundNotification = new
> OutboundNotification();
> System.out.println("Example: Send message from a serial gsm modem.");
> System.out.println(Library.getLibraryDescription());
> System.out.println("Version: " + Library.getLibraryVersion());
> SerialModemGateway gateway = new SerialModemGateway("modem.com39",
> "COM39", 115200, "Huawei", "");
> gateway.setInbound(true);
> gateway.setOutbound(true);
> gateway.setSimPin("4057");
> // Explicit SMSC address set is required for some modems.
> gateway.setSmscNumber("+254722500029");
> Service.getInstance().setOutboundMessageNotification(outboundNotification);
> Service.getInstance().addGateway(gateway);
> Service.getInstance().startService();
> System.out.println();
> System.out.println("Modem Information:");
> System.out.println(" Manufacturer: " + gateway.getManufacturer());
> System.out.println(" Model: " + gateway.getModel());
> System.out.println(" Serial No: " + gateway.getSerialNo());
> System.out.println(" SIM IMSI: " + gateway.getImsi());
> System.out.println(" Signal Level: " + gateway.getSignalLevel() + " dBm");
> System.out.println(" Battery Level: " + gateway.getBatteryLevel() + "%");
> System.out.println();
> // Send a message synchronously.
> String phonenumber=number.getText();
> String text=message.getText();
> OutboundMessage msg = new OutboundMessage(phonenumber,
> text);
> Service.getInstance().sendMessage(msg);
> System.out.println(msg);
> Service.getInstance().stopService();
> JOptionPane.showMessageDialog(null, "Message sent");
> System.out.println("Now Sleeping - Hit <enter> to terminate.");
> System.in.read();
> Service.getInstance().stopService();
> number.setText(null);
> message.setText(null);
> //this.dispose();
> }
>
> public class OutboundNotification implements
> IOutboundMessageNotification
> {
> public void process(AGateway gateway, OutboundMessage msg)
> {
> System.out.println("Outbound handler called from Gateway: " +
> gateway.getGatewayId());
> System.out.println(msg);
> }
> }
> /**
> * @param args the command line arguments
> */
>
> // Variables declaration - do not modify
> private javax.swing.JButton jButton1;
> private javax.swing.JLabel jLabel1;
> private javax.swing.JLabel jLabel2;
> private javax.swing.JLabel jLabel3;
> private javax.swing.JPanel jPanel1;
> private javax.swing.JScrollPane jScrollPane1;
> private javax.swing.JTextArea message;
> private javax.swing.JTextField number;
> private javax.swing.JButton sendbutton;
> // End of variables declaration
> }
>
>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "SMSLib Discussion Group" group.
>>>
>>> stop gateway and remove gateway in the same method
>>
>>
>>
--
You received this message because you are subscribed to the Google Groups
"SMSLib Discussion Group" group.
To view this discussion on the web visit
https://groups.google.com/d/msg/smslib/-/nvbdUoh5EGIJ.