📄 filetranfram.java
字号:
package filetran;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import com.borland.jbcl.layout.*;
import javax.swing.border.*;
import java.net.*;
import java.io.*;
import javax.swing.table.*;
import com.borland.dbswing.*;
import java.util.*;
/**
* <p>Title: FileTran</p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2004</p>
* <p>Company: </p>
* @author Netf
* @version 1.0
*/
public class FileTranFram extends JFrame {
JPanel contentPane;
JMenuBar jMenuBar1 = new JMenuBar();
JMenu jMenuFile = new JMenu();
JMenuItem jMenuFileExit = new JMenuItem();
JMenu jMenuHelp = new JMenu();
JMenuItem jMenuHelpAbout = new JMenuItem();
JToolBar jToolBar = new JToolBar();
JButton jButton1 = new JButton();
JButton jButton2 = new JButton();
JButton jButton3 = new JButton();
ImageIcon image1;
ImageIcon image2;
ImageIcon image3;
JLabel statusBar = new JLabel();
JLabel jLabel1 = new JLabel();
XYLayout xYLayout1 = new XYLayout();
JPanel jPanel1 = new JPanel();
Border border1;
TitledBorder titledBorder1;
JTextField Ipstr = new JTextField();
XYLayout xYLayout2 = new XYLayout();
JLabel jLabel2 = new JLabel();
JTextField files = new JTextField();
JButton jButton4 = new JButton();
JButton jButton5 = new JButton();
String localadd;
String sfile;
JProgressBar jpb = new JProgressBar();
JScrollPane jScrollPane1 = new JScrollPane();
JTable jtb;
JPanel jPanel2 = new JPanel();
Border border2;
TitledBorder titledBorder2;
JLabel status = new JLabel();
public DefaultTableModel dtm=null;
Vector v=new Vector(10);
JLabel s = new JLabel();
JLabel jLabel3 = new JLabel();
JLabel jLabel4 = new JLabel();
JLabel jLabel5 = new JLabel();
static Point origin = new Point();
//Construct the frame
public FileTranFram() {
enableEvents(AWTEvent.WINDOW_EVENT_MASK);
try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
try{
localadd=InetAddress.getLocalHost().getHostAddress();
}catch(IOException e){}
//lis lisTh=new lis(this);
// lisTh.start();
}
//Component initialization
private void jbInit() throws Exception {
Object conts[][]=new Object[0][5];
String[] names={"地址","任务 | 大小","文件","状态","进度"};
dtm=new DefaultTableModel(conts,names);
//tablem tm=new tablem();
image1 = new ImageIcon(filetran.FileTranFram.class.getResource("openFile.png"));
image2 = new ImageIcon(filetran.FileTranFram.class.getResource("closeFile.png"));
image3 = new ImageIcon(filetran.FileTranFram.class.getResource("help.png"));
contentPane = (JPanel) this.getContentPane();
border1 = new EtchedBorder(EtchedBorder.RAISED,Color.lightGray,Color.white);
titledBorder1 = new TitledBorder(border1,"传送选项");
jtb = new JTable(dtm);
// jtb.setAutoResizeMode(JTable.AUTO_RESIZE_LAST_COLUMN);
// TableColumnModel colm=jtb.getColumnModel();
//for(int i=0;i<colm.getColumnCount();i++){
// TableColumn col=colm.getColumn(i);
// col.sizeWidthToFit();
// col.setPreferredWidth(col.getWidth()+5);
// col.setMaxWidth(col.getWidth()+5);
// }
//jtb.setAutoResizeMode(4);
border2 = new EtchedBorder(EtchedBorder.RAISED,Color.gray,Color.white);
titledBorder2 = new TitledBorder(border2,"状态栏");
contentPane.setLayout(xYLayout1);
this.setSize(new Dimension(603, 379));
this.setTitle("文件传输");
this.addMouseMotionListener(new FileTranFram_this_mouseMotionAdapter(this));
this.addMouseListener(new FileTranFram_this_mouseAdapter(this));
statusBar.setFont(new java.awt.Font("Dialog", 0, 12));
statusBar.setText(" ");
jMenuFile.setText("文件");
jMenuFileExit.setText("退出");
jMenuFileExit.addActionListener(new FileTranFram_jMenuFileExit_ActionAdapter(this));
jMenuHelp.setText("帮助");
jMenuHelpAbout.setText("关于");
jMenuHelpAbout.addActionListener(new FileTranFram_jMenuHelpAbout_ActionAdapter(this));
jButton1.setIcon(image1);
jButton1.addActionListener(new FileTranFram_jButton1_actionAdapter(this));
jButton1.setToolTipText("Open File");
jButton2.setIcon(image2);
jButton2.setToolTipText("Close File");
jButton3.setIcon(image3);
jButton3.setToolTipText("Help");
jLabel1.setFont(new java.awt.Font("Dialog", 0, 12));
jLabel1.setText("IP:");
jPanel1.setBorder(titledBorder1);
jPanel1.setLayout(xYLayout2);
Ipstr.setMinimumSize(new Dimension(6, 22));
Ipstr.setText("");
Ipstr.addFocusListener(new FileTranFram_Ipstr_focusAdapter(this));
jLabel2.setFont(new java.awt.Font("Dialog", 0, 12));
jLabel2.setDebugGraphicsOptions(0);
jLabel2.setText("文件:");
files.setText("");
jButton4.setFont(new java.awt.Font("Dialog", 0, 12));
jButton4.setText("选择文件");
jButton4.addActionListener(new FileTranFram_jButton4_actionAdapter(this));
jButton5.setFont(new java.awt.Font("Dialog", 0, 12));
jButton5.setSelected(false);
jButton5.setText("传 送");
jButton5.addActionListener(new FileTranFram_jButton5_actionAdapter(this));
jpb.setToolTipText("");
jpb.setValue(0);
jScrollPane1.setFont(new java.awt.Font("Dialog", 0, 15));
jScrollPane1.setMinimumSize(new Dimension(22, 22));
jPanel2.setBorder(titledBorder2);
status.setFont(new java.awt.Font("Dialog", 0, 12));
jtb.setFont(new java.awt.Font("Dialog", 0, 15));
jtb.setGridColor(Color.white);
jtb.setRowMargin(1);
jtb.setShowHorizontalLines(true);
jLabel3.setFont(new java.awt.Font("Dialog", 0, 12));
jLabel3.setText("注意:本软件为多线程传输,可同时");
jLabel4.setText("传输或接收多个文件,但请关掉你的");
jLabel4.setFont(new java.awt.Font("Dialog", 0, 12));
jLabel5.setFont(new java.awt.Font("Dialog", 0, 12));
jLabel5.setText("防火墙!");
jToolBar.add(jButton1);
jToolBar.add(jButton2);
jToolBar.add(jButton3);
jMenuFile.add(jMenuFileExit);
jMenuHelp.add(jMenuHelpAbout);
jMenuBar1.add(jMenuFile);
jMenuBar1.add(jMenuHelp);
this.setJMenuBar(jMenuBar1);
contentPane.add(jToolBar, new XYConstraints(0, 0, 400, -1));
contentPane.add(Ipstr, new XYConstraints(88, 106, 141, -1));
contentPane.add(jLabel2, new XYConstraints(49, 65, 32, -1));
contentPane.add(files, new XYConstraints(88, 64, 143, 20));
contentPane.add(jButton4, new XYConstraints(247, 63, 86, 22));
contentPane.add(jLabel1, new XYConstraints(49, 107, 38, 21));
contentPane.add(jButton5, new XYConstraints(247, 105, 87, 24));
contentPane.add(jPanel1, new XYConstraints(20, 39, 561, 109));
jPanel1.add(jLabel3, new XYConstraints(334, 2, 208, 27));
jPanel1.add(jLabel4, new XYConstraints(333, 23, 208, 27));
jPanel1.add(jLabel5, new XYConstraints(335, 44, 208, 27));
contentPane.add(statusBar, new XYConstraints(21, 148, 287, 19));
contentPane.add(status, new XYConstraints(21, 172, 562, 17));
contentPane.add(jpb, new XYConstraints(329, 151, 252, 16));
contentPane.add(s, new XYConstraints(26, 323, 271, 25));
contentPane.add(jScrollPane1, new XYConstraints(23, 191, 552, 110));
contentPane.add(jPanel2, new XYConstraints(13, 175, 572, 135));
jScrollPane1.getViewport().add(jtb, null);
jpb.setVisible(false);
}
//File | Exit action performed
public void jMenuFileExit_actionPerformed(ActionEvent e) {
System.exit(0);
}
//Help | About action performed
public void jMenuHelpAbout_actionPerformed(ActionEvent e) {
FileTranFram_AboutBox dlg = new FileTranFram_AboutBox(this);
Dimension dlgSize = dlg.getPreferredSize();
Dimension frmSize = getSize();
Point loc = getLocation();
dlg.setLocation((frmSize.width - dlgSize.width) / 2 + loc.x, (frmSize.height - dlgSize.height) / 2 + loc.y);
dlg.setModal(true);
dlg.pack();
dlg.show();
}
public void chfile(){
FileDialog fd=new FileDialog(this,"选择你要传送的文件",FileDialog.LOAD);
fd.show();
files.setText(fd.getDirectory()+fd.getFile());
sfile=fd.getFile();
}
//Overridden so we can exit when window is closed
protected void processWindowEvent(WindowEvent e) {
super.processWindowEvent(e);
if (e.getID() == WindowEvent.WINDOW_CLOSING) {
jMenuFileExit_actionPerformed(null);
}
}
void jButton4_actionPerformed(ActionEvent e) {
chfile();
}
void jButton5_actionPerformed(ActionEvent e) {
//JOptionPane.showMessageDialog(this,Ipstr.getText()+"get?|"+localadd+"|"+sfile);
//JOptionPane.showMessageDialog(this,""+jtb.AUTO_RESIZE_ALL_COLUMNS);
if(files.getText().trim().length()>0&&Ipstr.getText().trim().length()>0){
File sf=new File(files.getText().trim());
long flen=sf.length();
sendmsg smsg = new sendmsg(Ipstr.getText(),
"get?|" + flen/1024 + "|" + sfile);
smsg.send();
statusBar.setText("已发送请示,正在等待连接....");
}else{
JOptionPane.showMessageDialog(this,"文件或IP不能为空!");
}
//send(Ipstr.getText(),"get?|"+localadd+"|"+sfile);
}
void Ipstr_focusLost(FocusEvent e) {
//if(Ipstr.getText().trim().length()>0&&files.getText().trim().length()>0){
// jButton5.setEnabled(true);
// }
}
void jButton1_actionPerformed(ActionEvent e) {
chfile();
}
void this_mousePressed(MouseEvent e) {
origin.x = e.getX();
origin.y = e.getY();
}
void this_mouseDragged(MouseEvent e) {
Point p = this.getLocation();
this.setLocation(
p.x + e.getX() - origin.x,
p.y + e.getY() - origin.y);
}
}
class FileTranFram_jMenuFileExit_ActionAdapter implements ActionListener {
FileTranFram adaptee;
FileTranFram_jMenuFileExit_ActionAdapter(FileTranFram adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jMenuFileExit_actionPerformed(e);
}
}
class FileTranFram_jMenuHelpAbout_ActionAdapter implements ActionListener {
FileTranFram adaptee;
FileTranFram_jMenuHelpAbout_ActionAdapter(FileTranFram adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jMenuHelpAbout_actionPerformed(e);
}
}
class FileTranFram_jButton4_actionAdapter implements java.awt.event.ActionListener {
FileTranFram adaptee;
FileTranFram_jButton4_actionAdapter(FileTranFram adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton4_actionPerformed(e);
}
}
class FileTranFram_jButton5_actionAdapter implements java.awt.event.ActionListener {
FileTranFram adaptee;
FileTranFram_jButton5_actionAdapter(FileTranFram adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton5_actionPerformed(e);
}
}
class FileTranFram_Ipstr_focusAdapter extends java.awt.event.FocusAdapter {
FileTranFram adaptee;
FileTranFram_Ipstr_focusAdapter(FileTranFram adaptee) {
this.adaptee = adaptee;
}
public void focusLost(FocusEvent e) {
adaptee.Ipstr_focusLost(e);
}
}
class FileTranFram_jButton1_actionAdapter implements java.awt.event.ActionListener {
FileTranFram adaptee;
FileTranFram_jButton1_actionAdapter(FileTranFram adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton1_actionPerformed(e);
}
}
class FileTranFram_this_mouseAdapter extends java.awt.event.MouseAdapter {
FileTranFram adaptee;
FileTranFram_this_mouseAdapter(FileTranFram adaptee) {
this.adaptee = adaptee;
}
public void mousePressed(MouseEvent e) {
adaptee.this_mousePressed(e);
}
}
class FileTranFram_this_mouseMotionAdapter extends java.awt.event.MouseMotionAdapter {
FileTranFram adaptee;
FileTranFram_this_mouseMotionAdapter(FileTranFram adaptee) {
this.adaptee = adaptee;
}
public void mouseDragged(MouseEvent e) {
adaptee.this_mouseDragged(e);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -