⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 chat.java

📁 P2P聊天系统 该程序是由NetBeans IDE 6.5
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)            .addGap(0, 85, Short.MAX_VALUE)        );        javax.swing.GroupLayout backLayout = new javax.swing.GroupLayout(back);        back.setLayout(backLayout);        backLayout.setHorizontalGroup(            backLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)            .addGroup(backLayout.createSequentialGroup()                .addGap(40, 40, 40)                .addGroup(backLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)                    .addGroup(backLayout.createSequentialGroup()                        .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 76, javax.swing.GroupLayout.PREFERRED_SIZE)                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)                        .addComponent(jButton2))                    .addGroup(backLayout.createSequentialGroup()                        .addGroup(backLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)                            .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)                            .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)                            .addGroup(backLayout.createSequentialGroup()                                .addComponent(send, javax.swing.GroupLayout.PREFERRED_SIZE, 54, javax.swing.GroupLayout.PREFERRED_SIZE)                                .addGap(18, 18, 18)                                .addComponent(jButton4, javax.swing.GroupLayout.PREFERRED_SIZE, 53, javax.swing.GroupLayout.PREFERRED_SIZE)))                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)                        .addGroup(backLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)                            .addComponent(jPanel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)                            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))                .addGap(29, 29, 29))        );        backLayout.setVerticalGroup(            backLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)            .addGroup(backLayout.createSequentialGroup()                .addGap(18, 18, 18)                .addGroup(backLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)                    .addGroup(backLayout.createSequentialGroup()                        .addGroup(backLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)                            .addComponent(jButton1)                            .addComponent(jButton2))                        .addGap(18, 18, 18)                        .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))                    .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))                .addGap(32, 32, 32)                .addGroup(backLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)                    .addComponent(jPanel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)                    .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)                .addGroup(backLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)                    .addComponent(jButton4)                    .addComponent(send))                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))        );        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());        getContentPane().setLayout(layout);        layout.setHorizontalGroup(            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)            .addComponent(back, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)        );        layout.setVerticalGroup(            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)            .addComponent(back, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)        );        pack();    }// </editor-fold>//GEN-END:initComponents    private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed        // TODO add your handling code here:        this.dispose();    }//GEN-LAST:event_jButton4ActionPerformed    private void sendActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_sendActionPerformed        // TODO add your handling code here:        String text = write.getText();        write.setText("");        Mserver.client(text,ip);        setmyprint(text);        }//GEN-LAST:event_sendActionPerformed    private void writeKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_writeKeyPressed        // TODO add your handling code here:        if(evt.getKeyCode()==10){            String text = write.getText();            write.setText("");            Mserver.client(text,ip);            setmyprint(text);        }    }//GEN-LAST:event_writeKeyPressed    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed        // TODO add your handling code here:        Mserver.client("fasongwenji",ip);        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_jButton1ActionPerformed    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed        // TODO add your handling code here:        try            {                Mserver.client("yuyinliaoti", ip);                yuyinrefuse.setVisible(true);                yuyins =new yuyinserver(serSock);                yuyins.start();            }            catch(Exception e)            {                System.out.println("Exception of voice server.");            }    }//GEN-LAST:event_jButton2ActionPerformed    private void yuyinacceptActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_yuyinacceptActionPerformed        // TODO add your handling code here:        try            {                yuyinaccept.setVisible(false);                yuyinrefuse.setVisible(true);                //System.out.println(ip);                yuyinc = new yuyinclient(cli,ip);                yuyinc.start();            }            catch(Exception e)            {                System.out.println("Exception of voice client.");            }    }//GEN-LAST:event_yuyinacceptActionPerformed    private void yuyinrefuseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_yuyinrefuseActionPerformed        Mserver.client("guanbiyuyin", ip);        guanbiyuyin();    }//GEN-LAST:event_yuyinrefuseActionPerformed        //打印 自己 的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);    }    public void setyuyin(){        yuyinaccept.setVisible(true);        yuyinrefuse.setVisible(true);    }    public void guanbiyuyin(){                   // TODO add your handling code here:        if(yuyins != null)            yuyins.stopserver();        if(yuyinc != null)            yuyinc.stopclient();        yuyinrefuse.setVisible(false);            //serSock.close();            //cli.close();            }    /**    * @param args the command line arguments    */    /*public static void main(String args[]) {        java.awt.EventQueue.invokeLater(new Runnable() {            public void run() {                new chat();            }        });    }*/    // Variables declaration - do not modify//GEN-BEGIN:variables    private javax.swing.JPanel back;    private javax.swing.JButton jButton1;    private javax.swing.JButton jButton2;    private javax.swing.JButton jButton4;    private javax.swing.JPanel jPanel1;    private javax.swing.JPanel jPanel2;    private javax.swing.JPanel jPanel3;    private javax.swing.JPanel jPanel5;    private javax.swing.JScrollPane jScrollPane1;    private javax.swing.JScrollPane jScrollPane2;    private javax.swing.JTextArea print;    private javax.swing.JButton send;    private javax.swing.JTextArea write;    private javax.swing.JButton yuyinaccept;    private javax.swing.JButton yuyinrefuse;    // End of variables declaration//GEN-END:variables}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -