📄 mainjframe.java
字号:
/*
* MainJFrame.java
*
* Created on 2008年4月24日, 下午11:47
*/
/**
*
* @author 602
*/
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.*;
import java.io.*;
import java.net.*;
import java.util.StringTokenizer;
public class MainJFrame extends javax.swing.JFrame implements ActionListener
{
/** Creates new form MainJFrame */
String downloadFileName="";
String downloadFilePath="";
public MainJFrame()
{
initComponents();
shareBut.addActionListener(this);
listenBut.addActionListener(this);
connectionBut.addActionListener(this);
saveBut.addActionListener(this);
downloadBut.addActionListener(this);
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==shareBut)
{
JFileChooser filechooser = new JFileChooser();
filechooser.setFileSelectionMode(0);
filechooser.showOpenDialog(this);
File file_list;
long lengthOfFile;
// selected the current file or directroy
file_list = filechooser.getSelectedFile();
// Find the length of the file
lengthOfFile = file_list.length();
// Display the text on to the JTextField
list1.add(file_list.toString()+"->"+lengthOfFile+"K");//用一个"->"隔开文件大小
}
else if(e.getSource()==saveBut)
{
JFileChooser filechooser = new JFileChooser();
filechooser.setFileSelectionMode(1);
File saveDir;
filechooser.showOpenDialog(this);
// selected the current file or directroy
saveDir = filechooser.getSelectedFile();
jTextField2.setText(saveDir.toString());
}
else if(e.getSource()==listenBut)
{
SendFileInfo_thread sendThread=null;
if(listenBut.getText()=="启动服务")
{
listenBut.setText("关闭服务");
sendThread=new SendFileInfo_thread();
sendThread.start();
}
else
{
listenBut.setText("启动服务");
}
ReceiveDownloadFileInfo_thread receiveDownloadInfoThread=new ReceiveDownloadFileInfo_thread();
receiveDownloadInfoThread.start();
// SendDownloadFile_thread sendDownloadThread=new SendDownloadFile_thread();
// sendDownloadThread.start();
// FileServer server=new FileServer();
// server.start();
}
else if(e.getSource()==connectionBut)
{
ReceiveFileInfo_thread receiveThread=new ReceiveFileInfo_thread();
receiveThread.start();
}
else if(e.getSource()==downloadBut)
{
jLabel2.setText("");
SendDownloadFileInfo_thread sendDownloadInfoThread=new SendDownloadFileInfo_thread();
sendDownloadInfoThread.start();
// ReceiveDownloadFile_thread receiveDownloadThread=new ReceiveDownloadFile_thread("d://","newFile.jpg");
// receiveDownloadThread.start();
}
}
/** 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=" 生成的代码 ">//GEN-BEGIN:initComponents
private void initComponents() {
jPanel1 = new javax.swing.JPanel();
listenBut = new javax.swing.JButton();
connectionBut = new javax.swing.JButton();
saveBut = new javax.swing.JButton();
shareBut = new javax.swing.JButton();
downloadBut = new javax.swing.JButton();
jTextField1 = new javax.swing.JTextField();
jTextField2 = new javax.swing.JTextField();
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
jScrollPane1 = new javax.swing.JScrollPane();
list1 = new java.awt.List();
jScrollPane2 = new javax.swing.JScrollPane();
list2 = new java.awt.List();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
listenBut.setText("\u542f\u52a8\u670d\u52a1");
connectionBut.setText("\u8fde\u63a5");
saveBut.setText("\u4fdd\u5b58\u76ee\u5f55");
shareBut.setText("\u5171\u4eab\u6587\u4ef6");
downloadBut.setText("\u4e0b\u8f7d");
jTextField1.setText("127.0.0.1");
jTextField2.setText("c:\\");
jScrollPane1.setViewportView(list1);
jScrollPane2.setViewportView(list2);
org.jdesktop.layout.GroupLayout jPanel1Layout = new org.jdesktop.layout.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jPanel1Layout.createSequentialGroup()
.add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(connectionBut)
.add(saveBut))
.add(21, 21, 21)
.add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jTextField1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 163, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(jTextField2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 151, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
.add(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.add(jLabel1))
.add(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.add(jLabel2))
.add(jPanel1Layout.createSequentialGroup()
.add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
.add(jScrollPane2)
.add(jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 407, Short.MAX_VALUE))
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(shareBut)
.add(downloadBut)))
.add(listenBut)
);
jPanel1Layout.linkSize(new java.awt.Component[] {jTextField1, jTextField2}, org.jdesktop.layout.GroupLayout.HORIZONTAL);
jPanel1Layout.linkSize(new java.awt.Component[] {connectionBut, listenBut, saveBut}, org.jdesktop.layout.GroupLayout.HORIZONTAL);
jPanel1Layout.linkSize(new java.awt.Component[] {downloadBut, shareBut}, org.jdesktop.layout.GroupLayout.HORIZONTAL);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jPanel1Layout.createSequentialGroup()
.add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(shareBut)
.add(jScrollPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 100, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(listenBut)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(connectionBut)
.add(jTextField1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.add(9, 9, 9)
.add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
.add(jPanel1Layout.createSequentialGroup()
.add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(jTextField2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(saveBut))
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(jScrollPane2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 100, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.add(downloadBut))
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(jLabel1)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(jLabel2))
);
org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.addContainerGap()
.add(jPanel1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.addContainerGap()
.add(jPanel1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.addContainerGap(49, Short.MAX_VALUE))
);
pack();
}// </editor-fold>//GEN-END:initComponents
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new MainJFrame().setVisible(true);
}
});
}
// 变量声明 - 不进行修改//GEN-BEGIN:variables
private javax.swing.JButton connectionBut;
private javax.swing.JButton downloadBut;
public static javax.swing.JLabel jLabel1;
public static javax.swing.JLabel jLabel2;
private javax.swing.JPanel jPanel1;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JScrollPane jScrollPane2;
public static javax.swing.JTextField jTextField1;
public static javax.swing.JTextField jTextField2;
public static java.awt.List list1;
public static java.awt.List list2;
private javax.swing.JButton listenBut;
private javax.swing.JButton saveBut;
private javax.swing.JButton shareBut;
// 变量声明结束//GEN-END:variables
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -