?? sms.java
字號:
package sms;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
import com.infobank.sms.Client;
public class Sms
{
private Text text_11;
private Text text_12;
private Text text_10;
private Text text_6;
private Text text_9;
private Text text_8;
private Text text_7;
private Text text_5;
private Text text_4;
private Text text_3;
private Text text_2;
private Text text_1;
private Text text;
private String result;//result為函數的返回值
// 定義client對象,以調用它的函數
Client func = new Client();
// 用戶名ID,密碼,所屬代理商 ,擴展位,手機號碼,關鍵字,短信內容,發送時間
String szUserID, szPassword, szCPN, szCallback, szDestination, szKeyword, szContents, szDatetime;
// 新密碼
String newpw;
public static void main(String[] args)
{
try
{
// 初始化
Sms window = new Sms();
// 調用函數,實現發送等功能
window.open();
} catch (Exception e)
{
e.printStackTrace();
}
}
/**
* Open the window
*/
public void open()
{
final Display display = Display.getDefault();
final Shell smsShell = new Shell(SWT.CLOSE);
// 加載左上角的圖片
smsShell.setImage(SWTResourceManager.getImage(Sms.class, "/img/logo.png"));
// 定義窗體大小
smsShell.setSize(512, 501);
// 定義窗體名稱
smsShell.setText("SMS TEST");
//
smsShell.open();
final Group group = new Group(smsShell, SWT.NONE);
group.setBounds(11, 20, 201, 113);
group.setText("帳號");
final Label label_1 = new Label(group, SWT.NONE);
label_1.setText("用戶名");
label_1.setBounds(31, 20, 42, 12);
final Label label_2 = new Label(group, SWT.NONE);
label_2.setText("密碼");
label_2.setBounds(31, 51, 33, 12);
final Label label_3 = new Label(group, SWT.NONE);
label_3.setText("所屬代理商");
label_3.setBounds(31, 82, 69, 12);
text_1 = new Text(group, SWT.BORDER);
text_1.setBounds(112, 17, 80, 25);
text_2 = new Text(group, SWT.BORDER);
text_2.setBounds(112, 48, 80, 25);
text_3 = new Text(group, SWT.BORDER);
text_3.setText("ibc");
text_3.setBounds(112, 79, 80, 25);
final Group group_1 = new Group(smsShell, SWT.NONE);
group_1.setBounds(223, 20, 150, 114);
group_1.setText("密碼修改");
final Label label_4 = new Label(group_1, SWT.NONE);
label_4.setText("請輸入新密碼");
// 定義一個按鈕,功能為修改密碼
final Button button = new Button(group_1, SWT.NONE);
button.addSelectionListener(new SelectionAdapter()
{
public void widgetSelected(final SelectionEvent e)
{
// 從text獲取用戶名等
szUserID = text_1.getText();
szPassword = text_2.getText();
szCPN = text_3.getText();
newpw = text_4.getText();
// 調用修改密碼函數
result = func.changePwd(szUserID, szPassword, szCPN, newpw);
text.setText("" + result); //顯示函數的返回值
}
});
label_4.setBounds(18, 20, 75, 12);
button.setText("修改密碼");
button.setBounds(25, 78, 65, 22);
text_4 = new Text(group_1, SWT.BORDER);
text_4.setBounds(16, 42, 80, 25);
final Group group_2 = new Group(smsShell, SWT.NONE);
group_2.setText("短信息發送");
group_2.setBounds(11, 142, 477, 155);
final Label label_5 = new Label(group_2, SWT.NONE);
label_5.setText("擴展位");
label_5.setBounds(18, 25, 54, 12);
final Label label_5_1 = new Label(group_2, SWT.NONE);
label_5_1.setBounds(18, 54, 64, 12);
label_5_1.setText("手機號列表");
final Label label_5_2 = new Label(group_2, SWT.NONE);
label_5_2.setBounds(18, 82, 70, 12);
label_5_2.setText("關鍵詞列表");
final Label label_5_3 = new Label(group_2, SWT.NONE);
label_5_3.setBounds(18, 113, 66, 12);
label_5_3.setText("發送時間");
text_5 = new Text(group_2, SWT.BORDER);
text_5.setBounds(98, 21, 93, 22);
text_7 = new Text(group_2, SWT.BORDER);
text_7.setBounds(98, 51, 93, 22);
text_8 = new Text(group_2, SWT.BORDER);
text_8.setBounds(98, 80, 93, 22);
text_9 = new Text(group_2, SWT.BORDER);
text_9.setBounds(98, 110, 93, 22);
final Label label_6 = new Label(group_2, SWT.NONE);
label_6.setText("短信內容");
label_6.setBounds(302, 17, 57, 12);
text_6 = new Text(group_2, SWT.V_SCROLL | SWT.BORDER | SWT.WRAP);
text_6.setBounds(205, 34, 254, 79);
// 定義一個按鈕,功能為發送短信
final Button button_1 = new Button(group_2, SWT.NONE);
button_1.setText("發送");
button_1.setBounds(305, 118, 48, 22);
button_1.addSelectionListener(new SelectionAdapter()
{
public void widgetSelected(final SelectionEvent e)
{
// 從text獲取用戶名等
szUserID = text_1.getText();
szPassword = text_2.getText();
szCPN = text_3.getText();
szCallback = text_5.getText();
szDestination = text_7.getText();
szKeyword = text_8.getText();
szContents = text_6.getText();
szDatetime = text_9.getText();
// if(szPassword.equals(""))
// 調用發送函數
result = func.smsSend(szUserID, szPassword, szCPN, szCallback, szDestination, szKeyword, szContents, szDatetime);
text.setText("" + result); //顯示函數的返回值
}
});
final Group group_3 = new Group(smsShell, SWT.NONE);
group_3.setText("信息管理");
group_3.setBounds(11, 303, 218, 154);
final Label label_7 = new Label(group_3, SWT.NONE);
label_7.setText("返回結果");
label_7.setBounds(72, 23, 55, 12);
// 定義一個按鈕,功能為用戶認證
final Button button_2 = new Button(group_3, SWT.NONE);
button_2.addSelectionListener(new SelectionAdapter()
{
public void widgetSelected(final SelectionEvent e)
{
//StringBuffer為一個可變對象,通過smsUser函數修改之后,賦值給text_10,做為返回結果
StringBuffer szResult = new StringBuffer();
// 從text獲取用戶名等
szUserID = text_1.getText();
szPassword = text_2.getText();
szCPN = text_3.getText();
// 調用用戶認證函數
result = func.smsUser(szUserID, szPassword, szCPN, szResult);
text.setText(result); //顯示函數的返回值
text_10.setText("" + szResult);//顯示函數的返回結果
}
});
button_2.setText("用戶認證");
button_2.setBounds(8, 123, 55, 22);
// 定義一個按鈕,功能為用戶帳戶查詢
final Button button_2_1 = new Button(group_3, SWT.NONE);
button_2_1.addSelectionListener(new SelectionAdapter()
{
public void widgetSelected(final SelectionEvent e)
{
// 從text獲取用戶名等
StringBuffer szResult = new StringBuffer();
szUserID = text_1.getText();
szPassword = text_2.getText();
szCPN = text_3.getText();
// 調用用戶帳戶查詢函數
result = func.smsCount(szUserID, szPassword, szCPN, szResult);
text.setText(result);//顯示函數的返回值
text_10.setText("" + szResult);//顯示函數的返回結果
}
});
button_2_1.setBounds(68, 123, 81, 22);
button_2_1.setText("賬戶信息查詢");
text_10 = new Text(group_3, SWT.V_SCROLL | SWT.BORDER | SWT.WRAP);
text_10.setEditable(false);
text_10.setBounds(10, 41, 198, 70);
// 定義一個按鈕,功能為接受短信
final Button button_2_2 = new Button(group_3, SWT.NONE);
button_2_2.setBounds(153, 123, 60, 22);
button_2_2.addSelectionListener(new SelectionAdapter()
{
public void widgetSelected(final SelectionEvent e)
{
// 從text獲取用戶名等
StringBuffer szResult = new StringBuffer();
szUserID = text_1.getText();
szPassword = text_2.getText();
szCPN = text_3.getText();
//調用短信接受函數
result = func.smsReceive(szUserID, szPassword, szCPN, szResult);
text.setText(result);
text_10.setText("" + szResult);
}
});
button_2_2.setText("接收短信");
final Group group_4 = new Group(smsShell, SWT.NONE);
group_4.setText("查詢發送結果");
group_4.setBounds(252, 304, 236, 151);
final Label label_7_1 = new Label(group_4, SWT.NONE);
label_7_1.setBounds(83, 20, 55, 12);
label_7_1.setText("返回結果");
text_12 = new Text(group_4, SWT.V_SCROLL | SWT.BORDER | SWT.WRAP);
text_12.setBounds(10, 38, 216, 70);
text_12.setEditable(false);
final Label label_8 = new Label(group_4, SWT.NONE);
label_8.setText("關鍵詞");
label_8.setBounds(16, 125, 41, 12);
text_11 = new Text(group_4, SWT.BORDER);
text_11.setBounds(69, 119, 80, 23);
// 定義一個按鈕,功能為查詢
final Button button_3 = new Button(group_4, SWT.NONE);
button_3.addSelectionListener(new SelectionAdapter()
{
public void widgetSelected(final SelectionEvent e)
{
// 從text獲取用戶名等
StringBuffer szResult = new StringBuffer();
szUserID = text_1.getText();
szPassword = text_2.getText();
szCPN = text_3.getText();
szKeyword = text_11.getText();
//調用短信查詢函數
result = func.smsQuery(szUserID, szPassword, szCPN, szKeyword, szResult);
System.out.println("----" + result);
text.setText(result);
text_12.setText("" + szResult);
}
});
button_3.setText("查詢");
button_3.setBounds(164, 119, 48, 22);
final Group group_5 = new Group(smsShell, SWT.NONE);
group_5.setText("返回結果");
group_5.setBounds(378, 20, 113, 113);
final Label label = new Label(group_5, SWT.NONE);
label.setBounds(30, 22, 42, 19);
label.setText("返回值");
text = new Text(group_5, SWT.BORDER);
text.setBounds(10, 47, 80, 25);
text.setEnabled(false);
text.setEditable(false);
// 定義一個按鈕,將text內容清空
final Button button_4 = new Button(group_5, SWT.NONE);
button_4.addSelectionListener(new SelectionAdapter()
{
public void widgetSelected(final SelectionEvent e)
{
// 將返回結果的TEXT清空
text_12.setText("");
text_10.setText("");
text.setText("");
// text_4.setText("");
}
});
button_4.setBounds(27, 81, 48, 22);
button_4.setText("清除");
// text_13為輸入IP的TEXT,只能輸入數字和點
// text_15為輸入端口號的TEXT,只能輸入數字
// 定義一個按鈕,設置服務器IP和PORT
smsShell.layout();
while (!smsShell.isDisposed())//
{
if (!display.readAndDispatch())//循環,等待事件調用
display.sleep();
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -