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

📄 frmmain.java

📁 jxta实现的p2p聊天
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
                     mySharedTable.setValueAt(VideoIcon,j,0);
                 }else{
                     mySharedTable.setValueAt(OthersIcon,j,0);
                 }
                 mySharedTable.setValueAt(listOfFiles[i].getName(),j,1);
                 mySharedTable.setValueAt(listOfFiles[i].length(),j,2);
                 mySharedTable.setValueAt(myCheckSum.getFileSum(listOfFiles[i]),j,3);
                 j++;
             }
         }
         
    }//GEN-LAST:event_btnReloadActionPerformed

    private void btnVerifyActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnVerifyActionPerformed
    //Create Check sum for downloaded file and check it with original check sum
    // to make sure download was successfull.
        if(download.myDonwloader.isDone())
        {
            File myNewFile = new File(Path + File.separator + myFileName);
            String newSum = myCheckSum.getFileSum(myNewFile);
            if(newSum.equals(OriginalCheckSum)){
             lblStatus.setText("File Verification passed. Download was Successfull.");             
            }else{
                lblStatus.setText("File Verification NOT passed-- Download corrupted.");
                 JOptionPane.showMessageDialog(null,"CheckSum verification NOT passed.\nDownload Corrupted.","Failure",
                                               JOptionPane.ERROR_MESSAGE);
            }            
            
        }else{
           JOptionPane.showMessageDialog(null,"Download is not finished yet.\nPlease be patient...","Error",
                    JOptionPane.ERROR_MESSAGE); 
        }
    }//GEN-LAST:event_btnVerifyActionPerformed

    private void btnCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCancelActionPerformed
//Canceling the current Download
        download.myDonwloader.cancel();
        lblStatus.setText("Download Canceled.");
        myProgressBar.setValue(0);
        btnCancel.setEnabled(false);
    }//GEN-LAST:event_btnCancelActionPerformed

    private void btnDownloadActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnDownloadActionPerformed
//Start Downloading the Files
        int rowNum;
        if ((rowNum = mySearchTable.getSelectedRow()) != -1)
        {
            if(contentAdv != null)
            {
                OriginalCheckSum = mySearchTable.getValueAt(rowNum,2).toString();
                myFileName = mySearchTable.getValueAt(rowNum,0).toString();
                lblFilename.setText(myFileName);
                lblStatus.setText("Downloading.....");
                //initializing the file
                File saveTo = new File(Path + File.separator + myFileName);
                //starting Download
                download = new DownloadFile(connection.getSaEeDGroup(), contentAdv[rowNum],
                                            saveTo, this.txtLog, this.myProgressBar);
                download.start();
                btnCancel.setEnabled(true);
            }
            
        }else{
            JOptionPane.showMessageDialog(null,"Please select Row first then Press Download!","Error",
                    JOptionPane.ERROR_MESSAGE);
        }
    }//GEN-LAST:event_btnDownloadActionPerformed

    private void btnStopActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnStopActionPerformed
//Stoping the Search for content progress and reinitialize the Search class for furthure useage
        startSearch.killThread();
        //obtaining the ContentAdvertisements 
        contentAdv = startSearch.reqestor.searchResult;
        startSearch = null;
        btnSearch.setEnabled(true);
        btnDownload.setEnabled(true);
        btnStop.setEnabled(false);
    }//GEN-LAST:event_btnStopActionPerformed

    private void btnSearchActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSearchActionPerformed
//Start Searching for contents in Peer Group
        startSearch = new SearchFile(connection.getSaEeDGroup(), this.txtFilename.getText(), this.txtLog,
                                     this.mySearchTable);
        startSearch.start();
        btnSearch.setEnabled(false);
        btnStop.setEnabled(true);
        btnDownload.setEnabled(false);
    }//GEN-LAST:event_btnSearchActionPerformed

    private void btnStopPeerSearchActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnStopPeerSearchActionPerformed
        //Ending Peer Search Thread
        //We need to initialize the PeersListing class again because we ended its  thread
        btnFindPeers.setEnabled(true);
        peersList.setEndOfSearch(true);
        peersList = new PeersListing(connection.getSaEeDGroup(), this.txtLog, this.ListOfPeers);
        btnStopPeerSearch.setEnabled(false);
        
    }//GEN-LAST:event_btnStopPeerSearchActionPerformed

    private void btnFindPeersActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnFindPeersActionPerformed
    //Start finding peers in SaEeD's Group
        peersList.start();
        btnFindPeers.setEnabled(false);
        btnStopPeerSearch.setEnabled(true);
    }//GEN-LAST:event_btnFindPeersActionPerformed

    private void txtMessageActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtMessageActionPerformed
    btnSendMessageActionPerformed(evt);
    }//GEN-LAST:event_txtMessageActionPerformed

    private void btnSendMessageActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSendMessageActionPerformed
    //Sending Chat message through the pipe 
    //Because we using the same pipe for input and output first we need to stop input pipe
    // then send our message then again activate our input pipe
        chatIn.stopListening();
        chatOut.setMessage(txtMessage.getText());
        chatOut.startingPipe();
        //activating the Input pipe again
        chatIn.startListening();
        txtMessage.setText("");
    }//GEN-LAST:event_btnSendMessageActionPerformed

    private void MenuItemExitActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_MenuItemExitActionPerformed
        //Exiting 
        System.out.println("[+]Bye bye.");
        System.exit(0);
    }//GEN-LAST:event_MenuItemExitActionPerformed

    private void ItemOthersStyleActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ItemOthersStyleActionPerformed
        //Changing to Other Style Frame
        try{
            UIManager.setLookAndFeel ("com.sun.java.swing.plaf.motif.MotifLookAndFeel") ;
            SwingUtilities.updateComponentTreeUI(this); //=====> Repaint the whole Frame !!!!!!!        
          } catch (Exception e) {
            System.err.println("Unable to change");
          }
    }//GEN-LAST:event_ItemOthersStyleActionPerformed

    private void ItemSwingStyleActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ItemSwingStyleActionPerformed
        //Changing to Swing Default Frame Style
        try {
            UIManager.setLookAndFeel(new MetalLookAndFeel());
            SwingUtilities.updateComponentTreeUI(this); //=====> Repaint the whole Frame !!!!!!!!!        
      } catch (Exception e) {
        System.err.println("Unable to change");
      }
    }//GEN-LAST:event_ItemSwingStyleActionPerformed

    private void ItemWindowStyleActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ItemWindowStyleActionPerformed
        //changing to Windows Style Fram
        try {        
             UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
            SwingUtilities.updateComponentTreeUI(this); //=====> Repaint the whole Frame !!!!!!!        
      } catch (Exception e) {
        System.err.println("Unable to change");
      }
    }//GEN-LAST:event_ItemWindowStyleActionPerformed

    private void ItemAboutMeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ItemAboutMeActionPerformed
        //Showing the AboutMe Dialog box.
        this.AboutMe.setVisible(true); 
    }//GEN-LAST:event_ItemAboutMeActionPerformed

    private void btnExitActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnExitActionPerformed
//Make sure that user will accept Terms and Conditions
        System.out.println("[-]Terms And Conditions did NOT accepted!\nExiting...");
        System.exit(0);
    }//GEN-LAST:event_btnExitActionPerformed

    private void btnAcceptActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAcceptActionPerformed
//Make sure that user will accept Terms and Conditions
        this.AboutMe.setVisible(false);
    }//GEN-LAST:event_btnAcceptActionPerformed
    
    //Executing the Main code and initialising the Objects used in out program
    public static void main(String args[]) 
    {
        frmMain myapp = new frmMain();
        myapp.setVisible(true);
        myapp.AboutMe.setVisible(true);
        //first make sure that Terms and Conditions are Accepted by User
        FirstTimeCheck checkFirstTime = new FirstTimeCheck(myapp.txtLog);
        //Search for Configuration file, it not found assumes that it is the first time
        //that we are using this Application
        if(checkFirstTime.isFirstTime()){
            JOptionPane.showMessageDialog(null,"Please Select Folder to Share","First Time Configuration",
                                          JOptionPane.INFORMATION_MESSAGE);
            checkFirstTime.searchForConfigFile();
            Path = checkFirstTime.getSharedPath();
        }else{
            checkFirstTime.searchForConfigFile();
            Path = checkFirstTime.getSharedPath();           
        }
        //Launching JXTA 
        connection = new StartJXTA(myapp.txtLog);
        //Starting Chat Services, which includes chat input and Output using the same pipe.
        chatIn = new ChatInput(connection.getSaEeDGroup(), myapp.txtLog, myapp.txtChatArea);
        chatIn.startListening();
        chatOut = new ChatOutput(connection.getSaEeDGroup(), myapp.txtLog, myapp.txtChatArea);
        chatOut.start();
        
        //initializing the PeersListing class to be able to find peers in SaEeDGroup
        peersList = new PeersListing(connection.getSaEeDGroup(), myapp.txtLog, myapp.ListOfPeers);
        
        //Start Sharing Services
        File myPath = new File(Path);
        launchSharing = new SaEeDSharing(connection.getSaEeDGroup(), myapp.txtLog, myPath);
        //Starting the Sharing Thread
        launchSharing.start();        
        
        
    }
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JDialog AboutMe;
    private javax.swing.JMenuItem ItemAboutMe;
    private javax.swing.JMenuItem ItemOthersStyle;
    private javax.swing.JMenuItem ItemSwingStyle;
    private javax.swing.JMenuItem ItemWindowStyle;
    public javax.swing.JList ListOfPeers;
    private javax.swing.JMenuItem MenuItemConnect;
    private javax.swing.JMenuItem MenuItemDisconnect;
    private javax.swing.JMenuItem MenuItemExit;
    private javax.swing.JButton btnAccept;
    private javax.swing.JButton btnCancel;
    private javax.swing.JButton btnDownload;
    private javax.swing.JButton btnExit;
    private javax.swing.JButton btnFindPeers;
    private javax.swing.JButton btnReload;
    private javax.swing.JButton btnSearch;
    private javax.swing.JButton btnSendMessage;
    private javax.swing.JButton btnStop;
    private javax.swing.JButton btnStopPeerSearch;
    private javax.swing.JButton btnVerify;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenu jMenu2;
    private javax.swing.JMenu jMenu3;
    private javax.swing.JMenu jMenu4;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JPanel jPanel6;
    private javax.swing.JPanel jPanel7;
    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.JScrollPane jScrollPane6;
    private javax.swing.JScrollPane jScrollPane7;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JSeparator jSeparator3;
    private javax.swing.JSeparator jSeparator4;
    private javax.swing.JSeparator jSeparator5;
    private javax.swing.JSeparator jSeparator6;
    private javax.swing.JSeparator jSeparator7;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JTextArea jTextArea1;
    private javax.swing.JTextArea jTextArea2;
    private javax.swing.JLabel lblFilename;
    private javax.swing.JLabel lblStatus;
    public javax.swing.JProgressBar myProgressBar;
    public javax.swing.JTable mySearchTable;
    private javax.swing.JTable mySharedTable;
    public javax.swing.JTextArea txtChatArea;
    private javax.swing.JTextField txtFilename;
    public javax.swing.JTextArea txtLog;
    private javax.swing.JTextField txtMessage;
    // End of variables declaration//GEN-END:variables
    
}

⌨️ 快捷键说明

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