?? clientwindow.java
字號:
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 + -