/* DESCRIPTION * Connect button event method, * Call the connect method * ARGUMENTS * ip - Peer IP variable, integer * port - Peer Port variable, integer * dlg - Warning dialog, Dialog * msg - Warning message, Label * ok - confirm button on the warning dialog */ protected void connect_btnMouseClicked(MouseEvent evt) { ip = ip_text.getText(); port = Integer.parseInt(port_text.getText()); final Dialog dlg = new Dialog(this, "Warning!"); dlg.setSize(300, 100); Label msg = new Label("Input the correct Ip address and Port number.", Label.CENTER); Button ok = new Button("OK"); dlg.setLayout(new FlowLayout()); dlg.add(msg); dlg.add(ok); ok.addMouseListener( new MouseAdapter() { public void mouseClicked(MouseEvent e) { dlg.dispose(); } }); // if user didn't a peer ip, it shows alarm dialog if (ip.equals("")) { dlg.setVisible(true); } // Call the connect method else { try { connect(); } catch (Exception e) { dlg.setVisible(true); System.out.println(e); } } }
/* DESCRIPTION * Send button event method, * Send the data to socket * ARGUMENTS * sendstr - send data, String * hexstr - send data converted to hex, String * dlg - Warning dialog, Dialog * msg - Warning message, Label * ok - confirm button on the warning dialog * pw - output stream */ protected void send_btnMouseClicked(MouseEvent evt) { String sendstr = ""; String hexstr = ""; // if the user click the send button when the socket is close, it shows warning dialog if (sock == null) { final Dialog dlg = new Dialog(this, "Warning!"); dlg.setSize(300, 100); Label msg = new Label("Connect the socket, first.", Label.CENTER); Button ok = new Button("OK"); dlg.setLayout(new FlowLayout()); dlg.add(msg); dlg.add(ok); ok.addMouseListener( new MouseAdapter() { public void mouseClicked(MouseEvent e) { dlg.dispose(); } }); dlg.setVisible(true); } // send the data to socket else { sendstr = send_text.getText(); if (sendstr.equals("") && cr_check.isSelected() == false && lf_check.isSelected() == false) { final Dialog dlg = new Dialog(this, "Warning!"); dlg.setSize(300, 100); Label msg = new Label("Insert the message", Label.CENTER); Button ok = new Button("OK"); dlg.setLayout(new FlowLayout()); dlg.add(msg); dlg.add(ok); ok.addMouseListener( new MouseAdapter() { public void mouseClicked(MouseEvent e) { dlg.dispose(); } }); dlg.setVisible(true); } else { pw.print(sendstr); if (cr_check.isSelected()) { pw.print("\r"); sendstr = sendstr + "\r"; } if (lf_check.isSelected()) { pw.print("\n"); sendstr = sendstr + "\n"; } pw.flush(); hexstr = StringtoHex(sendstr); data.append("Send data : "); data.append(hexstr + " | "); data.append(sendstr); data.append("\n"); send_text.setText(""); sendstr = ""; } } }