📄 gwifmoreceiver.java
字号:
package com.wireless.sms.gwif.test.receive;
import javax.swing.*;
import javax.swing.border.*;
import java.awt.event.*;
import java.awt.*;
import java.io.*;
//import java.util.Vector;
import org.apache.commons.configuration.Configuration;
import org.apache.commons.configuration.DOM4JConfiguration;
//import com.wireless.sms.pub.entity.MT;
//import com.wireless.sms.gwif.test.*;
public class GwifMoReceiver extends JFrame {
static final long serialVersionUID =1L;
/**配置文件对象**/
public static Configuration configuration = null;
public static int WIDTH = 400;
public static int HEIGHT = 280;
public GwifMoReceiver(int port) {
final MOServer moServer = new MOServer(port);
this.getContentPane().setLayout(new BorderLayout());
final JButton b1 = new JButton(" Start ");
final JButton b2 = new JButton(" Clear ");
JButton b3 = new JButton(" Exit ");
final JTextArea txt = new JTextArea();
txt.setLineWrap(true);
moServer.setTextArea(txt);
ActionListener a1 = new ActionListener() {
public void actionPerformed(ActionEvent e) {
if( moServer.isOpenflag() ){
moServer.stop();
b1.setText(" Start ");
}
else{
moServer.start();
b1.setText(" Stop ");
}
}
};
ActionListener a2 = new ActionListener() {
public void actionPerformed(ActionEvent e) {
txt.setText("");
}
};
ActionListener a3 = new ActionListener() {
public void actionPerformed(ActionEvent e) {
if( moServer.isOpenflag() ){
moServer.stop();
}
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);
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.setSize(WIDTH, HEIGHT);
this.setVisible(true);
this.setTitle("网络连接测试程序");
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public String getStackTrace(Exception e) {
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
e.printStackTrace(pw);
return sw.toString();
}
public static void main(String args[]) {
try{
File file = new File("./conf/GwifTest.xml");
if (file.exists()) {
configuration = new DOM4JConfiguration(file);
} else {
JOptionPane.showMessageDialog(null, "当前目录未找到配置文件 GwifTest.xml!", "错误提示",
JOptionPane.ERROR_MESSAGE);
return;
}
}
catch(Exception e){
e.printStackTrace();
return;
}
String [] ports = configuration.getStringArray("MO.LocalPort");
for(int i=0; i<ports.length; i++){
// GwifMoReceiver frame = new GwifMoReceiver( Integer.parseInt(ports[i]) );
new GwifMoReceiver( Integer.parseInt(ports[i]) );
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -