📄 crbtgwifsender.java
字号:
package com.wireless.crbt.gwif.test;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.Panel;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.Vector;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.ScrollPaneLayout;
import javax.swing.border.Border;
import javax.swing.border.EtchedBorder;
import org.apache.commons.configuration.Configuration;
import org.apache.commons.configuration.DOM4JConfiguration;
import com.wireless.crbt.gwif.global.CRBT;
import com.wireless.crbt.gwif.global.Util;
import com.wireless.gwif.socketconn.ShortConnClient;
public class CrbtGwifSender extends JFrame {
static final long serialVersionUID=1L;
public static int test = 1;
public static Configuration configuration = null;
public static JTextArea txt = null;
public static boolean sendRespFlag = false;
public static int WIDTH = 800;
public static int HEIGHT = 600;
private static int cyclecount;
/**配置文件对象**/
private static String testtype = null;
private int cyclenum;
// private static String sendTime ;
private static int sendtype = 0;//标识下发的crbt类型
private String sou_addr_6;//此域为消息源地址,表示消息发起的原始发起方地址描述字串。 同步方式下该域保留。
private String des_addr_6;//此域为消息目的地址,表示消息希望到达的终端地址描述字串。 同步方式下该域保留
private String seq_no_10;//此域表示一个序列号,使用在异步通信模式下,由消息发起者设定,应答者对应给回此序列号。
//序列号范围:0000000000-9999999999,循环使用。 同步方式下该域保留
/**Crbt配置**/
String craccount_20;
String crid_20;
String ret1_10;
String srcflag_1;
String srcIpaddr_20;
String srcPrice_4;
String ringtype_4;
String old_pass_8;
String new_pass_8;
String receiver_20;
String mobile_number_20;
String password_8;
String oper_id_1;
String user_type_2;
String ringName_40;
String remark1;
String remark2;
public CrbtGwifSender() {
this.getContentPane().setLayout(new BorderLayout());
int maxLabelLength = 8;
String[] labelNames = new String[] {"网络测试说明:", "1 联通网关", "2 电信网关", "3 移动网关", "4 网通网关"};
Vector labels = new Vector();
for (int i = 0; i < labelNames.length; i++) {
String tempLabelName = labelNames[i];
int j = 0;
do {
String innerTempLabelName =
tempLabelName.substring(j * maxLabelLength,
tempLabelName.length() > (j + 1) * maxLabelLength ? (j + 1) * maxLabelLength : tempLabelName.length());
JLabel tempLabel = new JLabel(innerTempLabelName.length() >= 6 ? innerTempLabelName :
" " + innerTempLabelName);
tempLabel.setFont(new Font("宋体", Font.PLAIN, 12));
labels.add(tempLabel);
tempLabelName = tempLabelName.substring(innerTempLabelName.length());
} while (tempLabelName.length() > 0);
}
JButton b1 = new JButton(" Send ");
JButton b2 = new JButton(" Clear ");
JButton b3 = new JButton(" Exit ");
txt = new JTextArea();
txt.setLineWrap(true);
ActionListener a1 = new ActionListener() {
public void actionPerformed(ActionEvent e) {
boolean sendFlag = false;
try {
File file = new File("./conf/crbt_test.xml");
if (file.exists()) {
configuration = new DOM4JConfiguration(file);
} else {
JOptionPane.showMessageDialog(null, "当前目录未找到配置文件 ./conf/crbt_test.xml!", "错误提示",
JOptionPane.ERROR_MESSAGE);
return;
}
sendRespFlag = configuration.getBoolean("SendRespFlag");
testtype = configuration.getString("TestType");
sendtype = (configuration.getInt("SendType"));
cyclenum = configuration.getInt("CycleNum");
cyclecount = 1;
// boolean testConnectFlag = false;//测试链路通道标志,此项为true则向目的IP写字符串"REQUESTMESSAGE",我们应该收到目的IP的回复
txt.append("testtype="+testtype+"\n");
for (int i = 0; i < cyclenum; i++) {
commonConfig();
if (testtype.equalsIgnoreCase("cm")) {
getcm_submit();
sendFlag = sendCRBT(getCRBT());
} else if (testtype.equalsIgnoreCase("cn")) {
getcn_submit();
sendFlag = sendCRBT(getCRBT());
} else if (testtype.equalsIgnoreCase("ct")) {
getct_submit();
sendFlag = sendCRBT(getCRBT());
} else if (testtype.equalsIgnoreCase("un")) {
getun_submit();
sendFlag = sendCRBT(getCRBT());
} else if (testtype.equalsIgnoreCase("stop")) {
sendFlag = sendStop();
}
}
// printCrbtconfig();
} catch (Exception ex) {
txt.setText(txt.getText() + "\n*******************************************\n" +
getStackTrace(ex) + "\n*******************************************\n"+
"sendFlag: "+sendFlag);
}
}
};
ActionListener a2 = new ActionListener() {
public void actionPerformed(ActionEvent e) {
txt.setText("");
}
};
ActionListener a3 = new ActionListener() {
public void actionPerformed(ActionEvent e) {
setVisible(false);
dispose();
System.exit(0);
}
};
Border border = BorderFactory.createEtchedBorder(EtchedBorder.RAISED);
b1.addActionListener(a1);
b1.setBorder(border);
b1.setBackground(new Color(245, 174, 56));
b2.addActionListener(a2);
b2.setBorder(border);
b2.setBackground(new Color(179, 245, 53));
b3.addActionListener(a3);
b3.setBorder(border);
b3.setBackground(new Color(242, 60, 155));
txt.setBorder(border);
JScrollPane textPanel = new JScrollPane(txt);
textPanel.setLayout(new ScrollPaneLayout());
textPanel.setAutoscrolls(true);
Panel buttonPanel = new Panel();
buttonPanel.setLayout(new FlowLayout());
buttonPanel.setBackground(new Color(137, 196, 248));
buttonPanel.add(b1);
buttonPanel.add(b2);
buttonPanel.add(b3);
GridBagConstraints gbc = new GridBagConstraints();
Panel labelPanel = new Panel();
labelPanel.setLayout(new GridBagLayout());
labelPanel.setBackground(new Color(137, 196, 248));
for (int i = 0; i < labels.size(); i++) {
gbc.gridx = 0;
gbc.gridy = i;
gbc.gridwidth = 1;
gbc.gridheight = 1;
gbc.weighty = 1;
gbc.insets = new Insets(0, 5, 0, 5);
gbc.anchor = GridBagConstraints.CENTER;
gbc.fill = GridBagConstraints.HORIZONTAL;
labelPanel.add((JLabel)labels.elementAt(i), gbc);
}
Toolkit toolkit = Toolkit.getDefaultToolkit();
Dimension screenSize = toolkit.getScreenSize();
int screenSize_x = (int)screenSize.getWidth();
int screenSize_y = (int)screenSize.getHeight();
int location_x = (screenSize_x - WIDTH) / 2;
int location_y = (screenSize_y - HEIGHT) / 2;
this.getContentPane().setLocation(location_x, location_y);
this.getContentPane().setLayout(new BorderLayout());
this.getContentPane().add(buttonPanel, BorderLayout.NORTH);
this.getContentPane().add(textPanel, BorderLayout.CENTER);
this.getContentPane().add(labelPanel, BorderLayout.WEST);
this.setSize(WIDTH, HEIGHT);
this.setVisible(true);
this.setTitle("网络连接测试程序");
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -