// 当鼠标单击事件发生时 public void actionPerformed(ActionEvent evt) { try { // 初始化聊天通信类 comUtil = new ComUtil(chatFrame); final String loginMsg = YeekuProtocol.PRESENCE + userField.getText() + YeekuProtocol.SPLITTER + iconList.getSelectedObjects()[0] + YeekuProtocol.PRESENCE; comUtil.broadCast(loginMsg); // 启动定时器每20秒广播一次在线信息 javax.swing.Timer timer = new javax.swing.Timer(1000 * 10, event -> comUtil.broadCast(loginMsg)); timer.start(); loginFrame.setVisible(false); chatFrame.setVisible(true); } catch (Exception ex) { loginFrame.setTipMsg("确认30001端口空闲,且网络正常!"); } }
public static void main(String[] args) { LoginFrame Cerceve = new LoginFrame(); Cerceve.setSize(500, 100); Cerceve.setVisible(true); Cerceve.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); }