从PC向移动设备发送短信:发送空白消息

时间:2013-05-17 08:01:06

标签: java swing sms sms-gateway

我得到了一个非常意外的结果。自从2周以来一直试图找出确切的原因但是徒劳无功。这是我最后的希望。

我有一个显示预先格式化的消息内容的GUI。用户可以编辑它或按原样发送它。单击发送按钮时,将通过GSM调制解调器将带有该文本的SMS发送到PC上的所选号码。

我面临的问题是我在手机上收到空白留言。我已经通过打印文本内容测试了我的代码,似乎没有问题。

即使在我的SendSMS类中,在发送消息之前,我打印出消息内容,它显示了我的GUI中完全相同的文本。

为什么我在手机上收到空白消息呢?我在各种手机上测试过,每次都收到一条空白信息。可能是什么问题?请帮忙!

这是我的代码:

taMessage = new JTextArea();        
        taMessage.setLocation(30, 249);
        frame.getContentPane().add(taMessage);
        taMessage.setLineWrap(true);
        taMessage.setWrapStyleWord(true);
        taMessage.setFont(font);    

        JScrollPane scrollPane = new JScrollPane(taMessage);
        scrollPane.setSize(238, 128);
        scrollPane.setLocation(407, 30);
        frame.getContentPane().add(scrollPane); 


        cbLanguage.addActionListener (new ActionListener(){

            @Override
            public void actionPerformed(ActionEvent arg0) {
                // TODO Auto-generated method stub
                lang = cbLanguage.getSelectedItem().toString();              
                String sql2 = "Select message from messages where language = '"+lang+"';";
                try {
                    result = statement.executeQuery(sql2);
                    while(result.next()){
                        taMessage.setText(result.getString(1));
                        }
                } catch (SQLException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }

        });     

        lblRegion = new JLabel("Region");
        lblRegion.setSize(50, 20);
        lblRegion.setLocation(46, 108);
        frame.getContentPane().add(lblRegion);



        DefaultListModel list = new DefaultListModel();
        String sql = "Select distinct region from users;";      
        try {           
            result = statement.executeQuery(sql);
            while(result.next()){
                String region = result.getString(1);            
                list.addElement(region);

            }           
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        listRegion = new JList(list);       
        frame.getContentPane().add(listRegion);
        listRegion.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
        listRegion.setVisibleRowCount(3);
        JScrollPane scroll = new JScrollPane(listRegion);
        scroll.setSize(135, 54);
        scroll.setLocation(136, 108);
        frame.getContentPane().add(scroll);

        btnSendNow = new JButton("Send Now");
        btnSendNow.setSize(106, 20);
        btnSendNow.setLocation(44, 218);
        frame.getContentPane().add(btnSendNow);     




        btnSendNow.addActionListener(new ActionListener() {         
            public void actionPerformed(ActionEvent arg0) {
                nos.clear();
                String msgTxt = taMessage.getText();
                areaList = listRegion.getSelectedValues();
                sql2 = "select phone_no from users where region in (";
                for( int i=0; i<areaList.length ; i++){
                    sql2 += "\'"+ areaList[i]+"\'";
                    if (i<areaList.length-1)
                        sql2+=",";
                }
                sql2+=")";
                //System.out.println("sql2: "+sql2);
                try {
                    result = statement.executeQuery(sql2);
                    while(result.next()){
                        nos.add(result.getString(1));
                    }
                    System.out.println(nos);
                } catch (SQLException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                } catch (Exception e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }

                    if( lang.equals("English")) {
                        for( int i=0; i<nos.size();i++){
                            System.out.println("taMessage.getText()= "+taMessage.getText());
                            try {
                                new SendSMS(port, msgTxt, nos.get(i));
                            } catch (Exception e) {
                                // TODO Auto-generated catch block
                                e.printStackTrace();
                            }                           
                        }
                        }
                    else if(lang.equals("eng + hin + telugu")){
                        for( int i=0; i<nos.size();i++){
                            System.out.println("taMessage.getText()= "+taMessage.getText());
                            try {
                                new SendLongMsg(port, msgTxt, nos.get(i));
                            } catch (Exception e) {
                                // TODO Auto-generated catch block
                                e.printStackTrace();
                            }                           
                        }
                    }
                        else {
                            System.out.println(taMessage.getText());
                            for(int i=0;i<nos.size(); i++){
                                System.out.println("taMessage.getText()= "+taMessage.getText());
                                new SendUnicodeMessage(port, taMessage.getText(), nos.get(i));
                            }
                        }
                    }


        });        

0 个答案:

没有答案