⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 guimain.java

📁 试用JAVA通过COMM口发送短信的代码.
💻 JAVA
字号:
// Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.kpdus.com/jad.html
// Decompiler options: packimports(3) 
// Source File Name:   GUIMain.java

package org.cross.sms.gui;

import java.awt.*;
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.StringSelection;
import java.awt.event.*;
import java.io.PrintStream;
import javax.swing.*;
import org.cross.sms.SmsServer;

// Referenced classes of package org.cross.sms.gui:
//            AddressList, _guiThread, GUIMain_ta_content_keyAdapter, SMSClient_btn_Send_actionAdapter, 
//            GUIMain_this_componentAdapter, GUIMain_this_windowAdapter, SMSConnect, Sound

public class GUIMain extends JFrame
{

    public GUIMain()
    {
        m_server = null;
        m_add = new AddressList();
        panel_cont = new JPanel();
        panel_res = new JPanel();
        ltypetip = new JLabel();
        lstatus = new JLabel();
        btn_Send = new JButton();
        ta_res = new JTextArea();
        ta_cont = new JTextArea();
        scrollPane_res = new JScrollPane();
        scrollPane_cont = new JScrollPane();
        borderLayout1 = new BorderLayout();
        borderLayout2 = new BorderLayout();
        panel_cont_header = new JPanel();
        borderLayout3 = new BorderLayout();
        panel_cont_cent = new JPanel();
        borderLayout4 = new BorderLayout();
        panel_cont_bot = new JPanel();
        borderLayout5 = new BorderLayout();
        cb_phone = new JComboBox();
        m_server = new SmsServer();
        try
        {
            jbInit();
        }
        catch(Exception exception)
        {
            exception.printStackTrace();
        }
    }

    protected boolean isConnected()
    {
        return m_server != null;
    }

    public void open(String com)
    {
        m_add.init();
        fillAddList();
        m_server.setComName(com);
        try
        {
            m_server.start();
        }
        catch(Exception ex)
        {
            ex.printStackTrace();
        }
        m_thread = new _guiThread(m_server, this);
        m_thread.start();
    }

    public void close()
    {
        if(m_server != null)
        {
            m_server.stop();
            m_server = null;
        }
    }

    private void jbInit()
        throws Exception
    {
        getContentPane().setLayout(borderLayout1);
        panel_cont.setPreferredSize(new Dimension(270, 160));
        panel_cont.setLayout(borderLayout3);
        panel_cont.setAlignmentX(0.5F);
        panel_cont.setAlignmentY(0.5F);
        panel_cont.setBorder(BorderFactory.createLineBorder(Color.black));
        ltypetip.setText("\u624B\u673A\u53F7\u7801: +86");
        cb_phone.setPreferredSize(new Dimension(120, 22));
        cb_phone.setEditable(true);
        ta_cont.setBorder(BorderFactory.createLineBorder(Color.black));
        ta_cont.setLineWrap(true);
        ta_cont.addKeyListener(new GUIMain_ta_content_keyAdapter(this));
        ta_cont.setAutoscrolls(true);
        btn_Send.setText("\u53D1\u9001");
        btn_Send.addActionListener(new SMSClient_btn_Send_actionAdapter(this));
        btn_Send.setPreferredSize(new Dimension(60, 25));
        lstatus.setPreferredSize(new Dimension(0, 15));
        lstatus.setToolTipText("");
        panel_cont_cent.setLayout(borderLayout4);
        panel_cont_bot.setLayout(borderLayout5);
        panel_cont_cent.add(scrollPane_cont, "Center");
        panel_cont_header.add(ltypetip);
        panel_cont_header.add(cb_phone);
        panel_cont.add(panel_cont_cent, "Center");
        scrollPane_cont.getViewport().add(ta_cont, null);
        panel_cont.setAutoscrolls(true);
        panel_res.setBorder(BorderFactory.createLineBorder(Color.black));
        panel_res.setLayout(borderLayout2);
        ta_res.setBorder(BorderFactory.createLineBorder(Color.black));
        ta_res.setLineWrap(true);
        ta_res.setEditable(false);
        panel_res.setAutoscrolls(true);
        scrollPane_res.getViewport().add(ta_res, null);
        panel_res.add(scrollPane_res, "Center");
        setDefaultCloseOperation(3);
        addComponentListener(new GUIMain_this_componentAdapter(this));
        addWindowListener(new GUIMain_this_windowAdapter(this));
        getContentPane().add(panel_cont, "South");
        getContentPane().add(panel_res, "Center");
        panel_cont.add(panel_cont_bot, "South");
        panel_cont.add(panel_cont_header, "North");
        panel_cont_bot.add(btn_Send, "East");
        panel_cont_bot.add(lstatus, "Center");
        setSize(292, 470);
        setLocation(100, 100);
    }

    private void fillAddList()
    {
        cb_phone.removeAllItems();
        for(int i = 0; i < m_add.size(); i++)
            cb_phone.addItem(m_add.getPhone(i));

    }

    public static void main(String args[])
    {
        GUIMain cl = new GUIMain();
        SMSConnect con = new SMSConnect(cl);
        con.show();
        if(con.isok)
        {
            cl.open(con.m_com);
            cl.show();
        } else
        {
            System.exit(0);
        }
    }

    public void doSend()
    {
        String phone;
        String cont;
        phone = cb_phone.getSelectedItem().toString();
        m_server.send(phone, ta_cont.getText().trim());
        cont = ta_cont.getText();
        if(cont.trim().equals(""))
        {
            JOptionPane.showMessageDialog(this, "\u6CA1\u6709\u4FE1\u606F");
            return;
        }
        try
        {
            StringSelection ss = new StringSelection(cont);
            Clipboard cl = getToolkit().getSystemClipboard();
            cl.setContents(ss, ss);
            appendResp("\u6211\u8BF4\uFF1A\n");
            appendResp(cont + "\n");
            ta_cont.setText("");
            ta_cont.requestFocus();
            (new Sound(Sound.SEND)).start();
            if(!m_add.contains(phone))
            {
                m_add.add(0, phone);
                fillAddList();
            }
        }
        catch(Exception ex)
        {
            ex.printStackTrace();
        }
        return;
    }

    public void btn_Send_actionPerformed(ActionEvent e)
    {
        doSend();
    }

    public void appendResp(String rsp)
    {
        ta_res.append(rsp);
        ta_res.setCaretPosition(ta_res.getText().length());
    }

    public void this_windowActivated(WindowEvent e)
    {
        ta_cont.requestFocus();
    }

    public void ta_content_keyTyped(KeyEvent e)
    {
        if(e.isAltDown() && e.getKeyChar() == 's')
            doSend();
    }

    public void ta_content_keyReleased(KeyEvent e)
    {
        int len = ta_cont.getText().length();
        lstatus.setText("\u957F\u5EA6\u4E3A" + len);
    }

    public void this_componentResized(ComponentEvent e)
    {
        int y = getHeight();
        int x = getWidth();
        System.out.println("x=" + x + " y=" + y);
        if(x < 290 || y < 470)
        {
            if(x < 290)
                x = 290;
            if(y < 470)
                y = 470;
            setSize(new Dimension(x, y));
        }
    }

    public void this_windowClosing(WindowEvent e)
    {
        m_add.save();
    }

    SmsServer m_server;
    _guiThread m_thread;
    AddressList m_add;
    JPanel panel_cont;
    JPanel panel_res;
    JLabel ltypetip;
    JLabel lstatus;
    JButton btn_Send;
    JTextArea ta_res;
    JTextArea ta_cont;
    JScrollPane scrollPane_res;
    JScrollPane scrollPane_cont;
    BorderLayout borderLayout1;
    BorderLayout borderLayout2;
    JPanel panel_cont_header;
    BorderLayout borderLayout3;
    JPanel panel_cont_cent;
    BorderLayout borderLayout4;
    JPanel panel_cont_bot;
    BorderLayout borderLayout5;
    JComboBox cb_phone;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -