java rs232_Java程序与RSR232串口通讯小练手(转载)

packagecom.elkan1788.view;importjava.awt.BorderLayout;importjava.awt.Button;importjava.awt.Color;importjava.awt.Font;importjava.awt.GridLayout;importjava.awt.Image;importjava.awt.TextArea;importjava.awt.TextField;importjava.awt.event.ActionEvent;importjava.awt.event.ActionListener;importjava.io.IOException;importjava.io.InputStream;importjava.io.OutputStream;importjava.util.ArrayList;importjava.util.Enumeration;importjava.util.List;importjava.util.TooManyListenersException;importjavax.comm.CommPortIdentifier;importjavax.comm.NoSuchPortException;importjavax.comm.PortInUseException;importjavax.comm.SerialPort;importjavax.comm.SerialPortEvent;importjavax.comm.SerialPortEventListener;importjavax.comm.UnsupportedCommOperationException;importjavax.imageio.ImageIO;importjavax.swing.JComboBox;importjavax.swing.JFrame;importjavax.swing.JLabel;importjavax.swing.JOptionPane;importjavax.swing.JPanel;importjavax.swing.SwingConstants;importjavax.swing.border.EmptyBorder;public class JavaRs232 extends JFrame implementsActionListener, SerialPortEventListener {/*** JDK Serial Version UID*/

private static final long serialVersionUID = -7270865686330790103L;protected int WIN_WIDTH = 380;protected int WIN_HEIGHT = 300;private JComboBox>portCombox, rateCombox, dataCombox, stopCombox, parityCombox;privateButton openPortBtn, closePortBtn, sendMsgBtn;privateTextField sendTf;privateTextArea readTa;privateJLabel statusLb;privateString portname, rate, data, stop, parity;protectedCommPortIdentifier portId;protected Enumeration>ports;protected ListportList;protectedSerialPort serialPort;protected OutputStream outputStream = null;protected InputStream inputStream = null;protectedString mesg;protected intsendCount, reciveCount;/*** 默认构造函数*/

publicJavaRs232() {super("Java RS-232串口通信测试程序 凡梦星尘");

setSize(WIN_WIDTH, WIN_HEIGHT);

setLocationRelativeTo(null);

Image icon= null;try{

icon= ImageIO.read(JavaRs232.class.getResourceAsStream("/res/rs232.png"));

}catch(IOException e) {

showErrMesgbox(e.getMessage());

}

setIconImage(icon);

setResizable(false);

scanPorts();

initComponents();

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

setVisible(true);

}/*** 初始化各UI组件

*@since2012-3-22 下午11:56:39*/

public voidinitComponents() {//共用常量

Font lbFont = new Font("微软雅黑", Font.TRUETYPE_FONT, 14);//创建左边面板

JPanel northPane = new

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值