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

📄 addfriend.java

📁 下了就知道了
💻 JAVA
字号:
/*
 * AddFriend.java
 *
 * Created on 2007年3月26日, 下午4:29
 */

package cn.spig1home.chinafish.fqq;

import cn.spig1home.chinafish.fqq.todo.XMLCreator;
import java.awt.Container;
import java.awt.Insets;
import java.io.BufferedOutputStream;
import java.io.IOException;

/**
 *
 * @author  Administrator
 */
public class AddFriend extends javax.swing.JDialog {
    private String FriendName = new String();
    private String userName = new String();
    
    private Container	cont;
    private MainScreen  screen;
    private BufferedOutputStream	StreamToServer;
    
    private Insets insets;
    
    
    /** Creates new form AddFriend */
    public AddFriend(MainScreen  screen, String userName) {
        initComponents();
        setTitle("Add Friend --- FQQ_InstantMessage");
        setLocation(300,200);
        setVisible(true);
        this.screen=screen;
        this.userName=userName;
        this.StreamToServer=screen.StreamToServer;
        cont=getContentPane();
        cont.setLayout(null);
        insets=getInsets();
        
        m_UserName.setText(userName);
        m_UserName.setEnabled(false);
        
        
    }
    public void setBChatEnable(boolean b){
        b_Chat.setEnabled(b);
    }
    public void setBAddEnable(boolean b){
        b_friends_name.setEnabled(b);
    }
    public void setBDelEnable(boolean b){
        b_del.setEnabled(b);
    }
    
    /** 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.
     */
    // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
    private void initComponents() {
        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        m_FriendName = new javax.swing.JTextField();
        m_UserName = new javax.swing.JTextField();
        b_friends_name = new javax.swing.JButton();
        b_cancel = new javax.swing.JButton();
        b_del = new javax.swing.JButton();
        b_Chat = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "AddFriend", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("微软雅黑", 0, 11), new java.awt.Color(0, 0, 0)));
        jLabel1.setText("Friend");

        jLabel2.setText("User ID");

        b_friends_name.setText("OK");
        b_friends_name.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                b_friends_nameMouseClicked(evt);
            }
        });

        b_cancel.setText("Cancel");
        b_cancel.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                b_cancelMouseClicked(evt);
            }
        });

        b_del.setText("Del");
        b_del.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                b_delMouseClicked(evt);
            }
            public void mousePressed(java.awt.event.MouseEvent evt) {
                b_delMousePressed(evt);
            }
        });

        b_Chat.setText("Chat...");
        b_Chat.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                b_ChatMouseClicked(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)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel1)
                            .addComponent(jLabel2))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                                .addComponent(m_FriendName, javax.swing.GroupLayout.DEFAULT_SIZE, 70, Short.MAX_VALUE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(b_Chat, javax.swing.GroupLayout.PREFERRED_SIZE, 77, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(m_UserName, javax.swing.GroupLayout.DEFAULT_SIZE, 154, Short.MAX_VALUE)))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(b_friends_name, javax.swing.GroupLayout.PREFERRED_SIZE, 57, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(b_del, javax.swing.GroupLayout.PREFERRED_SIZE, 58, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(b_cancel)))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(b_Chat)
                    .addComponent(m_FriendName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(m_UserName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(b_friends_name)
                    .addComponent(b_del)
                    .addComponent(b_cancel)))
        );

        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, 224, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        pack();
    }// </editor-fold>//GEN-END:initComponents
    
    private void b_ChatMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_b_ChatMouseClicked
// TODO add your handling code here:
        int result;
        result = screen.CheckBeforeOpening(m_FriendName.getText());
        
        if (result == -1) {
            Message msgWindow = new Message(userName, m_FriendName.getText(), screen, StreamToServer);
            msgWindow.show();
            screen.ListOfMessageWindowsByName.add((Object)m_FriendName.getText());
            screen.ListOfMessageWindowsByObject.add((Object)msgWindow);
        } else if (result != -2) {
            Message	msg = (Message)(screen.ListOfMessageWindowsByObject.elementAt(result));
            msg.toFront();
            msg.show();
        }
        this.dispose();
    }//GEN-LAST:event_b_ChatMouseClicked
    
    private void b_delMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_b_delMousePressed
// TODO add your handling code here:
        String [] values = new String[2];
        values[0] = userName;
        values[1] = m_FriendName.getText();
        
        XMLCreator	createRequest;
        byte	[]		RequestGenerated;
        
        createRequest	= new XMLCreator("DELETEFRIEND", values);
        RequestGenerated	= createRequest.returnResult();
        
        try {
            StreamToServer.write(RequestGenerated, 0, RequestGenerated.length);
            StreamToServer.flush();
        } catch (Exception e) {
            System.out.println("Delete Friend Name:"+e);
        }
    }//GEN-LAST:event_b_delMousePressed
    
    private void b_delMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_b_delMouseClicked
// TODO add your handling code here:
//        String [] values = new String[2];
//        values[0] = userName;
//        values[1] = m_FriendName.getText();
//
//        XMLCreator	createRequest;
//        byte	[]		RequestGenerated;
//
//        createRequest	= new XMLCreator("DELETEFRIEND", values);
//        RequestGenerated	= createRequest.returnResult();
//
//        try {
//            StreamToServer.write(RequestGenerated, 0, RequestGenerated.length);
//            StreamToServer.flush();
//        } catch (Exception e) {
//            System.out.println("Delete Friend Name:"+e);
//        }
    }//GEN-LAST:event_b_delMouseClicked
    
    private void b_friends_nameMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_b_friends_nameMouseClicked
        XMLCreator createRequest;
        byte [] RequestGenerated;
        
        String[] values = new String[2];
        values[0] = userName;
        values[1] = m_FriendName.getText();
        createRequest = new XMLCreator("ADDFRIEND", values);
        RequestGenerated  = createRequest.returnResult();
        try {
            StreamToServer.write(RequestGenerated, 0, RequestGenerated.length);
            StreamToServer.flush();
        } catch(IOException exception) {
            System.out.println("Exception in Add Friend " + exception);
        }
        dispose();
    }//GEN-LAST:event_b_friends_nameMouseClicked
    
    private void b_cancelMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_b_cancelMouseClicked
        dispose();
    }//GEN-LAST:event_b_cancelMouseClicked
    
    /**
     * @param args the command line arguments
     */
//    public static void main(String args[]) {
//        java.awt.EventQueue.invokeLater(new Runnable() {
//            public void run() {
//                new AddFriend(new javax.swing.JFrame(), true).setVisible(true);
//            }
//        });
//    }
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton b_Chat;
    private javax.swing.JButton b_cancel;
    private javax.swing.JButton b_del;
    private javax.swing.JButton b_friends_name;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JTextField m_FriendName;
    private javax.swing.JTextField m_UserName;
    // End of variables declaration//GEN-END:variables
    
}

⌨️ 快捷键说明

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