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

📄 clientwindow.java

📁 QQ聊天工具的源代码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
                        Class[] types = new Class [] {
                                java.lang.String.class
                        };
                        boolean[] canEdit = new boolean [] {
                                false
                        };

                        public Class getColumnClass(int columnIndex) {
                                return types [columnIndex];
                        }

                        public boolean isCellEditable(int rowIndex, int columnIndex) {
                                return canEdit [columnIndex];
                        }
                });
                jScrollPane5.setViewportView(activeuserTab);

                transmitBtn.setText("transmit file");
                transmitBtn.addActionListener(new java.awt.event.ActionListener() {
                        public void actionPerformed(java.awt.event.ActionEvent evt) {
                                transmitBtnActionPerformed(evt);
                        }
                });

                logoffBtn.setText("LOG OFF");
                logoffBtn.addActionListener(new java.awt.event.ActionListener() {
                        public void actionPerformed(java.awt.event.ActionEvent evt) {
                                logoffBtnActionPerformed(evt);
                        }
                });

                javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
                getContentPane().setLayout(layout);
                layout.setHorizontalGroup(
                        layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addGroup(layout.createSequentialGroup()
                                                .addGap(29, 29, 29)
                                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                                        .addComponent(usernameLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 59, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                        .addComponent(IPLabel))
                                                .addGap(90, 90, 90)
                                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                                        .addComponent(IPtextLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                                        .addComponent(usernametextLabel, javax.swing.GroupLayout.DEFAULT_SIZE, 84, Short.MAX_VALUE)))
                                        .addGroup(layout.createSequentialGroup()
                                                .addContainerGap()
                                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                        .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 456, Short.MAX_VALUE)
                                                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 456, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                                                .addComponent(privateBtn)
                                                                .addGap(16, 16, 16)
                                                                .addComponent(sendBtn, javax.swing.GroupLayout.PREFERRED_SIZE, 74, javax.swing.GroupLayout.PREFERRED_SIZE)))))
                                .addGap(26, 26, 26)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                        .addComponent(logoffBtn, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addComponent(transmitBtn, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addComponent(jScrollPane5, javax.swing.GroupLayout.DEFAULT_SIZE, 140, Short.MAX_VALUE))
                                .addGap(25, 25, 25))
                );
                layout.setVerticalGroup(
                        layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(layout.createSequentialGroup()
                                .addGap(34, 34, 34)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                        .addComponent(usernameLabel)
                                        .addComponent(usernametextLabel))
                                .addGap(13, 13, 13)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                        .addComponent(IPLabel)
                                        .addComponent(IPtextLabel))
                                .addGap(25, 25, 25)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(jScrollPane5, javax.swing.GroupLayout.PREFERRED_SIZE, 152, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGroup(layout.createSequentialGroup()
                                                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 182, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addGap(26, 26, 26)
                                                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 98, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addGap(42, 42, 42)
                                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                                        .addComponent(sendBtn)
                                                        .addComponent(privateBtn)
                                                        .addComponent(transmitBtn))))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 26, Short.MAX_VALUE)
                                .addComponent(logoffBtn)
                                .addContainerGap())
                );
                pack();
        }// </editor-fold>//GEN-END:initComponents
//登出按钮,调用log函数,正常结束连接;
	private void logoffBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_logoffBtnActionPerformed
// TODO 将在此处添加您的处理代码:
		log("off");
		this.setVisible(false);  
		new logon().setVisible(true);
		
	}//GEN-LAST:event_logoffBtnActionPerformed
//传输文件请求按钮;请求向一个特定的在线用户传文件;
	private void transmitBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_transmitBtnActionPerformed
// TODO 将在此处添加您的处理代码:
		try{
			String input = sendtextTA.getText();
			int r = activeuserTab.getSelectedRow();
			int c = activeuserTab.getSelectedColumn();		//从在线用户列表中选择请求对象;
			String tarname = (String)activeuserTab.getValueAt(r,c);
			if(tarname != null)
			{
				filechooser frame1 = new filechooser(tarname, rckey);	//初始化一个filechooser, 并将对象用户名&自己sission key 传进参数;
				frame1.setTitle("档案选择对话方块");
				frame1.setSize(550,350);
				frame1.setVisible(true);
			}else
			{
				JOptionPane.showMessageDialog(null,"您的好友可能不在线,请重新选择", "warning", JOptionPane.INFORMATION_MESSAGE);
			}

		}catch(java.lang.ArrayIndexOutOfBoundsException aiofex)
		{
			JOptionPane.showMessageDialog(null,"请先选择请求对象", "error", JOptionPane.ERROR_MESSAGE);
		}
	}//GEN-LAST:event_transmitBtnActionPerformed
//好友私聊按钮;
	private void privateBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_privateBtnActionPerformed
// TODO 将在此处添加您的处理代码:
		try{
			String input = sendtextTA.getText();
			int r = activeuserTab.getSelectedRow();
			int c = activeuserTab.getSelectedColumn();				//选择好友;
			String tarname = (String)activeuserTab.getValueAt(r,c);
			if(tarname==null)							//好友为null
			{
				JOptionPane.showMessageDialog(null,"您的好友可能不在线,请重新选择", "warning", JOptionPane.INFORMATION_MESSAGE);
			}
			else
			{	
				if(input.equals(""))
				{
					JOptionPane.showMessageDialog(null,"跟好友什么都不说,这样不太好吧!", "warning", JOptionPane.INFORMATION_MESSAGE);
				}else
				{
					sendtextTA.setText("");
					//message 为特定格式消息; 以[好友姓名]开头.此消息与原文档不同,原文档无此消息;
					String message = "["+tarname+"]"+PORT+"&"+usernametextLabel.getText() + " talks to " + tarname + ":" + input+"\n";
					message = EncryptAndDecrypt.encryption(message, rckey, "RC4");
					try{
						Socket skt = new Socket("127.0.0.1",2501);		//服务器处理私聊的端口为2501
						DataOutputStream dos = new DataOutputStream(skt.getOutputStream());
						dos.writeBytes(message+"&"+usernametextLabel.getText());
						dos.close();
						skt.close();
					}catch(UnknownHostException unex)
					{
						System.err.println(unex);
					}catch(IOException ioex)
					{
						System.err.println(ioex);
					}
				}
			}
		}catch(java.lang.ArrayIndexOutOfBoundsException aiofex)
		{
			JOptionPane.showMessageDialog(null,"请先选择好友", "error", JOptionPane.ERROR_MESSAGE);
		}
	}//GEN-LAST:event_privateBtnActionPerformed

	private void messageTAAncestorAdded(javax.swing.event.AncestorEvent evt) {//GEN-FIRST:event_messageTAAncestorAdded
// TODO 将在此处添加您的处理代码:
		new Listen().start();
	}//GEN-LAST:event_messageTAAncestorAdded
//发送群聊按钮;
	private void sendBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_sendBtnActionPerformed
// TODO 将在此处添加您的处理代码:
		String input = sendtextTA.getText();
		if(input.equals(""))
		{ 
			JOptionPane.showMessageDialog(null,"跟大家什么都不说,这样不太好吧!", "warning", JOptionPane.INFORMATION_MESSAGE);
		}else
		{
			sendtextTA.setText("");
			String message = PORT+"&"+usernametextLabel.getText() + " talks to everyone:" + input+"\n";
			message = EncryptAndDecrypt.encryption(message, rckey, "RC4");
			try{
				Socket skt = new Socket("127.0.0.1",2002);		//服务器处理群聊消息端口为2002;
				DataOutputStream dos = new DataOutputStream(skt.getOutputStream());
				dos.writeBytes(message+"&"+usernametextLabel.getText());
				dos.close();
				skt.close();
			}catch(UnknownHostException unex)
			{
				System.err.println(unex);
			}catch(IOException ioex)
			{
				System.err.println(ioex);
			}
		}
	}//GEN-LAST:event_sendBtnActionPerformed

	/**
	 * @param args the command line arguments
	 */
	public static void main(String args[]) {
		java.awt.EventQueue.invokeLater(new Runnable() {
			public void run() {
				new clientWindow("Guest","\0.0.0.0","").setVisible(true);
			}
		});
	}
	
        // 变量声明 - 不进行修改//GEN-BEGIN:variables
        private javax.swing.JLabel IPLabel;
        private javax.swing.JLabel IPtextLabel;
        private javax.swing.JTable activeuserTab;
        private javax.swing.JScrollPane jScrollPane1;
        private javax.swing.JScrollPane jScrollPane2;
        private javax.swing.JScrollPane jScrollPane3;
        private javax.swing.JScrollPane jScrollPane4;
        private javax.swing.JScrollPane jScrollPane5;
        private javax.swing.JTable jTable1;
        private javax.swing.JTable jTable2;
        private javax.swing.JButton logoffBtn;
        private javax.swing.JTextArea messageTA;
        private javax.swing.JButton privateBtn;
        private javax.swing.JButton sendBtn;
        private javax.swing.JTextArea sendtextTA;
        private javax.swing.JButton transmitBtn;
        private javax.swing.JLabel usernameLabel;
        private javax.swing.JLabel usernametextLabel;
        // 变量声明结束//GEN-END:variables
	
}

⌨️ 快捷键说明

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