📄 frmmain.java
字号:
/*
* Student Name: Seyed Saeed Ghiassy
* Student ID : 05994390
* Supervisor : Dr.Fakas
* Project Name: Peer-to-Peer File Sharing Application Using JXTA technology
* Unit Name : Final Year Project
* Unit Code : 63CP3261
* DeadLine : 21-April-2008
* University : Manchester Metropolitan University
* E-mail : seyed.ghiassy@student.mmu.ac.uk
* Softwares : JXTA Version 2.4.1, JDK Version 1.6.0_05, NetBeans IDE 5.5
*/
package myPackage;
import java.awt.Component;
import java.io.File;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTable;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.plaf.metal.MetalLookAndFeel;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.JTableHeader;
import javax.swing.table.TableCellRenderer;
//import jxta Library
import net.jxta.share.ContentAdvertisement;
//this is Main Frame and it handles the Application start up and also initialisation of all
//object that are needed in out program
public class frmMain extends javax.swing.JFrame
{
//Defining Class Variables
private final ImageIcon mp3Icon = new ImageIcon(getClass().getResource("/myPackage/myIcons/16x16/mp3Icon.png"));
private final ImageIcon VideoIcon = new ImageIcon(getClass().getResource("/myPackage/myIcons/16x16/videoIcon.png"));
private final ImageIcon OthersIcon = new ImageIcon(getClass().getResource("/myPackage/myIcons/16x16/otherfilesIcon.png"));
static String Path = null;
//Original check sum which will be taken from Content Advertisement
//to make sure download is not corrupted
static String OriginalCheckSum = "unknown";
static String myFileName=null;
//Classes that needed to launch into jxta, share contenets through JXTA network,
//Search for content, Download content, Chat services and Peers Listing in Group
static StartJXTA connection = null;
static ChatInput chatIn = null;
static ChatOutput chatOut=null;
static PeersListing peersList = null;
static SaEeDSharing launchSharing =null;
static SearchFile startSearch =null;
static DownloadFile download = null;
static CheckSumCalc myCheckSum = new CheckSumCalc();
static ContentAdvertisement [] contentAdv = null;
public frmMain() //Main Frame Constructor
{
initComponents();
}
/** 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() {
AboutMe = new javax.swing.JDialog();
jPanel7 = new javax.swing.JPanel();
jLabel7 = new javax.swing.JLabel();
jLabel8 = new javax.swing.JLabel();
jLabel9 = new javax.swing.JLabel();
jLabel10 = new javax.swing.JLabel();
jScrollPane6 = new javax.swing.JScrollPane();
jTextArea1 = new javax.swing.JTextArea();
jSeparator7 = new javax.swing.JSeparator();
jScrollPane7 = new javax.swing.JScrollPane();
jTextArea2 = new javax.swing.JTextArea();
btnAccept = new javax.swing.JButton();
btnExit = new javax.swing.JButton();
jTabbedPane1 = new javax.swing.JTabbedPane();
jPanel1 = new javax.swing.JPanel();
jScrollPane1 = new javax.swing.JScrollPane();
txtLog = new javax.swing.JTextArea();
jPanel2 = new javax.swing.JPanel();
jLabel1 = new javax.swing.JLabel();
txtFilename = new javax.swing.JTextField();
jScrollPane2 = new javax.swing.JScrollPane();
mySearchTable = new javax.swing.JTable();
jSeparator3 = new javax.swing.JSeparator();
btnSearch = new javax.swing.JButton();
btnStop = new javax.swing.JButton();
btnDownload = new javax.swing.JButton();
jPanel3 = new javax.swing.JPanel();
jScrollPane3 = new javax.swing.JScrollPane();
mySharedTable = new javax.swing.JTable();
jSeparator4 = new javax.swing.JSeparator();
btnReload = new javax.swing.JButton();
jPanel4 = new javax.swing.JPanel();
jLabel2 = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
jLabel4 = new javax.swing.JLabel();
lblFilename = new javax.swing.JLabel();
lblStatus = new javax.swing.JLabel();
myProgressBar = new javax.swing.JProgressBar();
btnVerify = new javax.swing.JButton();
btnCancel = new javax.swing.JButton();
jPanel5 = new javax.swing.JPanel();
jScrollPane4 = new javax.swing.JScrollPane();
txtChatArea = new javax.swing.JTextArea();
jSeparator5 = new javax.swing.JSeparator();
jLabel5 = new javax.swing.JLabel();
txtMessage = new javax.swing.JTextField();
btnSendMessage = new javax.swing.JButton();
jPanel6 = new javax.swing.JPanel();
jScrollPane5 = new javax.swing.JScrollPane();
ListOfPeers = new javax.swing.JList();
jSeparator6 = new javax.swing.JSeparator();
btnFindPeers = new javax.swing.JButton();
btnStopPeerSearch = new javax.swing.JButton();
jLabel6 = new javax.swing.JLabel();
jMenuBar1 = new javax.swing.JMenuBar();
jMenu1 = new javax.swing.JMenu();
MenuItemConnect = new javax.swing.JMenuItem();
MenuItemDisconnect = new javax.swing.JMenuItem();
jSeparator1 = new javax.swing.JSeparator();
MenuItemExit = new javax.swing.JMenuItem();
jMenu2 = new javax.swing.JMenu();
jMenu4 = new javax.swing.JMenu();
ItemWindowStyle = new javax.swing.JMenuItem();
ItemSwingStyle = new javax.swing.JMenuItem();
ItemOthersStyle = new javax.swing.JMenuItem();
jMenu3 = new javax.swing.JMenu();
ItemAboutMe = new javax.swing.JMenuItem();
AboutMe.setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);
AboutMe.setTitle("About Me");
AboutMe.setLocationByPlatform(true);
AboutMe.setMinimumSize(new java.awt.Dimension(540, 430));
AboutMe.setModal(true);
AboutMe.getAccessibleContext().setAccessibleParent(this);
jLabel7.setIcon(new javax.swing.ImageIcon(getClass().getResource("/myPackage/myIcons/24x24/MMU.png")));
jLabel7.setBorder(javax.swing.BorderFactory.createTitledBorder(""));
jLabel8.setFont(new java.awt.Font("Comic Sans MS", 3, 14));
jLabel8.setForeground(new java.awt.Color(102, 0, 0));
jLabel8.setText("Project Name: Peer-To-Peer File Sharing Application");
jLabel9.setFont(new java.awt.Font("Comic Sans MS", 3, 14));
jLabel9.setForeground(new java.awt.Color(102, 0, 0));
jLabel9.setText("Author Name: Seyed Saeed Ghiassy");
jLabel10.setFont(new java.awt.Font("Comic Sans MS", 3, 14));
jLabel10.setForeground(new java.awt.Color(102, 0, 0));
jLabel10.setText("Supervisor: Dr. Fakas");
jTextArea1.setColumns(20);
jTextArea1.setEditable(false);
jTextArea1.setRows(5);
jTextArea1.setText("Year: 2007-2008\nDescription: This application is based on JXTA technology \nby Sun Microsystems; The concept of this application is to \nsharing resources over the specified Groups in JXTA network.");
jScrollPane6.setViewportView(jTextArea1);
jTextArea2.setColumns(20);
jTextArea2.setEditable(false);
jTextArea2.setFont(new java.awt.Font("Monospaced", 1, 13));
jTextArea2.setForeground(new java.awt.Color(252, 0, 51));
jTextArea2.setRows(5);
jTextArea2.setText("!!!! WARNING !!!! \nThis application is for educational purposes only, And \nThe Author has No responsibility over the Resources \nthat might be Shared in this Network. \n");
jTextArea2.setBorder(javax.swing.BorderFactory.createTitledBorder("Terms and Conditions"));
jScrollPane7.setViewportView(jTextArea2);
btnAccept.setText("Accept");
btnAccept.setToolTipText("Accept terms and conditions");
btnAccept.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnAcceptActionPerformed(evt);
}
});
btnExit.setText("Exit");
btnExit.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnExitActionPerformed(evt);
}
});
javax.swing.GroupLayout jPanel7Layout = new javax.swing.GroupLayout(jPanel7);
jPanel7.setLayout(jPanel7Layout);
jPanel7Layout.setHorizontalGroup(
jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel7Layout.createSequentialGroup()
.addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel7Layout.createSequentialGroup()
.addContainerGap()
.addComponent(jLabel7)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel9, javax.swing.GroupLayout.DEFAULT_SIZE, 413, Short.MAX_VALUE)
.addComponent(jLabel8, javax.swing.GroupLayout.DEFAULT_SIZE, 413, Short.MAX_VALUE)
.addComponent(jLabel10)))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel7Layout.createSequentialGroup()
.addContainerGap()
.addComponent(jSeparator7, javax.swing.GroupLayout.DEFAULT_SIZE, 500, Short.MAX_VALUE))
.addGroup(jPanel7Layout.createSequentialGroup()
.addContainerGap()
.addComponent(btnExit, javax.swing.GroupLayout.DEFAULT_SIZE, 67, Short.MAX_VALUE)
.addGap(366, 366, 366)
.addComponent(btnAccept, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addGroup(jPanel7Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jScrollPane7, javax.swing.GroupLayout.DEFAULT_SIZE, 500, Short.MAX_VALUE)
.addComponent(jScrollPane6, javax.swing.GroupLayout.DEFAULT_SIZE, 500, Short.MAX_VALUE))))
.addContainerGap())
);
jPanel7Layout.setVerticalGroup(
jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel7Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel7Layout.createSequentialGroup()
.addComponent(jLabel8)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jLabel9)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jLabel10))
.addComponent(jLabel7))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jSeparator7, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jScrollPane6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jScrollPane7, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(btnExit)
.addComponent(btnAccept))
.addContainerGap(22, Short.MAX_VALUE))
);
javax.swing.GroupLayout AboutMeLayout = new javax.swing.GroupLayout(AboutMe.getContentPane());
AboutMe.getContentPane().setLayout(AboutMeLayout);
AboutMeLayout.setHorizontalGroup(
AboutMeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(AboutMeLayout.createSequentialGroup()
.addContainerGap()
.addComponent(jPanel7, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addContainerGap())
);
AboutMeLayout.setVerticalGroup(
AboutMeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(AboutMeLayout.createSequentialGroup()
.addContainerGap()
.addComponent(jPanel7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(43, Short.MAX_VALUE))
);
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("SaEeD P2P File Sharing Application V0.01");
setLocationByPlatform(true);
jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Connection Information:"));
txtLog.setColumns(20);
txtLog.setEditable(false);
txtLog.setRows(5);
txtLog.setText("===== Welcome to SaEeD's Peer-To-Peer File Sharing Application =====\n");
txtLog.setToolTipText("Connection Information");
txtLog.setBorder(javax.swing.BorderFactory.createTitledBorder("Log:"));
jScrollPane1.setViewportView(txtLog);
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()
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 748, Short.MAX_VALUE)
.addContainerGap())
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 473, Short.MAX_VALUE)
.addContainerGap())
);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -