📄 guichat.java
字号:
/* * To change this template, choose Tools | Templates * and open the template in the editor. *//* * GUIchat.java * * Created on 2009-1-19, 22:05:42 */package lanchat;import java.awt.Dimension;import java.awt.Toolkit;import java.net.Socket;import java.text.SimpleDateFormat;import java.util.Calendar;import list.list;import remotecontrol.RemoteAccessServer;import remotecontrol.RemoteClient;import trans.MainF;/** * * @author Administrator */public class GUIchat extends javax.swing.JFrame { /** Creates new form GUIchat */ public GUIchat(String str) { initComponents(); print.setEditable(false); this.setTitle("与"+str+"聊天中"); ip = str;//赋值ip地址 } /** This method is called from within the constructor to * initialize the form. * WARNING: Do NOT modify this code. The content of this method is * always regenerated by the Form Editor. */ @SuppressWarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents private void initComponents() { jPanel1 = new javax.swing.JPanel(); send = new javax.swing.JButton(); exit = new javax.swing.JButton(); jScrollPane1 = new javax.swing.JScrollPane(); print = new javax.swing.JTextArea(); jScrollPane2 = new javax.swing.JScrollPane(); input = new javax.swing.JTextArea(); sendfile = new javax.swing.JButton(); Rclient = new javax.swing.JButton(); Rserver = new javax.swing.JButton(); setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); setBackground(new java.awt.Color(51, 153, 255)); jPanel1.setBackground(new java.awt.Color(51, 153, 255)); jPanel1.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED)); send.setLabel("发送"); send.setName("发送"); // NOI18N send.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { sendActionPerformed(evt); } }); exit.setLabel("关闭"); exit.setName("关闭"); // NOI18N exit.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { exitActionPerformed(evt); } }); print.setColumns(20); print.setRows(5); jScrollPane1.setViewportView(print); input.setColumns(20); input.setRows(5); jScrollPane2.setViewportView(input); sendfile.setText("发送文件"); sendfile.setName("sendfile"); // NOI18N sendfile.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { sendfileActionPerformed(evt); } }); Rclient.setText("远程控制"); Rclient.setName("Rclient"); // NOI18N Rclient.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { RclientActionPerformed(evt); } }); Rserver.setText("远程被控"); Rserver.setName("Rserver"); // NOI18N Rserver.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { RserverActionPerformed(evt); } }); javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1); jPanel1.setLayout(jPanel1Layout); jPanel1Layout.setHorizontalGroup( jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel1Layout.createSequentialGroup() .addContainerGap() .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 477, Short.MAX_VALUE) .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 477, Short.MAX_VALUE) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup() .addComponent(send) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(exit)) .addGroup(jPanel1Layout.createSequentialGroup() .addComponent(sendfile) .addGap(27, 27, 27) .addComponent(Rclient) .addGap(18, 18, 18) .addComponent(Rserver))) .addContainerGap()) ); jPanel1Layout.setVerticalGroup( jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup() .addGap(10, 10, 10) .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(sendfile) .addComponent(Rclient) .addComponent(Rserver)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 288, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(27, 27, 27) .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 115, Short.MAX_VALUE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(exit) .addComponent(send)) .addContainerGap()) ); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jPanel1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) ); pack(); }// </editor-fold>//GEN-END:initComponents //按钮 “发送” 事件的 Action private void sendActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_sendActionPerformed // TODO add your handling code here: //发送消息 int n = -1; message = input.getText(); if(ip==null){ //ip = MainFrame.ipstr; ip = list.ip; } input.setText(""); Mserver.client(message,ip); setmyprint(message); }//GEN-LAST:event_sendActionPerformed //打印 自己 的message 到print textArea public void setmyprint(String message){ String temp; SimpleDateFormat sdf=new SimpleDateFormat("HH:mm:ss"); Calendar cal=Calendar.getInstance(); nowtime=sdf.format(cal.getTime()); nowtime = "你说: "+ nowtime + "\n"; message = nowtime+message ; temp = print.getText() + "\n"; temp = temp + message; print.setText(temp); } //打印 接收到 的message 到 printer textArea public void setprint(String message,String ip){ String temp; SimpleDateFormat sdf=new SimpleDateFormat("HH:mm:ss"); Calendar cal=Calendar.getInstance(); nowtime=sdf.format(cal.getTime()); nowtime = ip +"说: "+ nowtime + "\n"; message = nowtime+message ; temp = print.getText() + "\n"; temp = temp + message; print.setText(temp); } private void exitActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_exitActionPerformed // TODO add your handling code here: //关闭按钮 this.dispose(); }//GEN-LAST:event_exitActionPerformed private void sendfileActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_sendfileActionPerformed // TODO add your handling code here: //发送文件按钮 MainF frame = new MainF(this.ip); // Center the window Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); Dimension frameSize = frame.getSize(); if (frameSize.height > screenSize.height) { frameSize.height = screenSize.height; } if (frameSize.width > screenSize.width) { frameSize.width = screenSize.width; } frame.setLocation((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2); frame.setVisible(true); }//GEN-LAST:event_sendfileActionPerformed private void RserverActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_RserverActionPerformed // TODO add your handling code here: //远程被控按钮 RemoteAccessServer.createGUI(); }//GEN-LAST:event_RserverActionPerformed private void RclientActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_RclientActionPerformed // TODO add your handling code here: //System.out.println(ip); //远程控制按钮 RemoteClient.createGUI(this.ip); }//GEN-LAST:event_RclientActionPerformed public void setip(String ip){ this.ip = ip; } /** * @param args the command line arguments */ private String ip; private String message,nowtime; private Mserver ms; private Socket s; // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton Rclient; private javax.swing.JButton Rserver; private javax.swing.JButton exit; private javax.swing.JTextArea input; private javax.swing.JPanel jPanel1; private javax.swing.JScrollPane jScrollPane1; private javax.swing.JScrollPane jScrollPane2; private javax.swing.JTextArea print; private javax.swing.JButton send; private javax.swing.JButton sendfile; // End of variables declaration//GEN-END:variables}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -