Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
qq_51543278
FTPsystem
提交
be8b661c
F
FTPsystem
项目概览
qq_51543278
/
FTPsystem
通知
13
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
3
列表
看板
标记
里程碑
合并请求
1
DevOps
流水线
流水线任务
计划
Wiki
12
Wiki
分析
仓库
DevOps
项目成员
Pages
F
FTPsystem
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
3
Issue
3
列表
看板
标记
里程碑
合并请求
1
合并请求
1
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
12
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
be8b661c
编写于
11月 15, 2022
作者:
weixin_50772964
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
yhx
上级
9e026d6f
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
216 addition
and
16 deletion
+216
-16
out/production/ftpsystem/ftp/UI.class
out/production/ftpsystem/ftp/UI.class
+0
-0
src/ftp/FtpPanel.java
src/ftp/FtpPanel.java
+171
-1
src/ftp/UI.java
src/ftp/UI.java
+45
-15
未找到文件。
out/production/ftpsystem/ftp/UI.class
浏览文件 @
be8b661c
无法预览此类型文件
src/ftp/FtpPanel.java
浏览文件 @
be8b661c
package
ftp
;
public
class
FtpPanel
{
import
javax.swing.*
;
import
javax.swing.table.DefaultTableModel
;
import
java.awt.*
;
import
java.awt.event.ActionEvent
;
import
java.awt.event.ActionListener
;
import
java.awt.event.MouseEvent
;
import
java.awt.event.MouseListener
;
import
java.text.SimpleDateFormat
;
import
java.util.List
;
import
static
ftp
.
Global
.
ftpClient
;
/**
* 实现本地文件浏览,为继承JPanel的一个面板
*
* @author Lonsy
* @version 1.0
*/
public
class
FtpPanel
extends
JPanel
implements
ActionListener
,
MouseListener
{
private
JButton
jbUp
;
private
JComboBox
jcbPath
;
private
JTable
jtFile
;
private
DefaultTableModel
dtmFile
;
private
JLabel
jlLocal
;
private
Fileinfo
path
;
private
boolean
init
;
private
String
currentPath
;
private
int
currentIndex
;
List
<
Fileinfo
>
list
;
private
String
file1
=
new
String
();
public
FtpPanel
()
{
super
(
new
BorderLayout
());
JPanel
jp
=
new
JPanel
(
new
BorderLayout
());
jbUp
=
new
JButton
(
" up "
);
jbUp
.
addActionListener
(
this
);
jcbPath
=
new
JComboBox
();
jcbPath
.
addActionListener
(
this
);
jp
.
add
(
jbUp
,
BorderLayout
.
WEST
);
jp
.
add
(
jcbPath
,
BorderLayout
.
CENTER
);
dtmFile
=
new
LocalTableModel
();
dtmFile
.
addColumn
(
" 名称 "
);
dtmFile
.
addColumn
(
" 大小 "
);
dtmFile
.
addColumn
(
" 类型 "
);
dtmFile
.
addColumn
(
" 修改日期 "
);
jtFile
=
new
JTable
(
dtmFile
);
jtFile
.
setShowGrid
(
false
);
jtFile
.
addMouseListener
(
this
);
jlLocal
=
new
JLabel
(
" / "
,
JLabel
.
CENTER
);
add
(
jp
,
BorderLayout
.
NORTH
);
add
(
new
JScrollPane
(
jtFile
),
BorderLayout
.
CENTER
);
add
(
jlLocal
,
BorderLayout
.
SOUTH
);
// 显示系统分区及文件路径 并 在JTabel中显示当前路径的文件信息
currentPath
=
"/"
;
List
<
Fileinfo
>
list
=
FileView
.
viewFile
(
ftpClient
);
listFiles
();
}
public
String
getCurrentPath
()
{
return
currentPath
;
}
private
boolean
listFiles
()
{
list
=
FileView
.
viewFile
(
ftpClient
);
dtmFile
.
setRowCount
(
0
);
if
(
list
.
size
()>
0
){
for
(
int
i
=
1
;
i
<
list
.
size
();
i
++){
dtmFile
.
addRow
(
new
String
[]{
list
.
get
(
i
).
name
,
sizeFormat
(
list
.
get
(
i
).
size
)
,
list
.
get
(
i
).
type
,
new
SimpleDateFormat
(
"yyyy年MM月dd日"
).
format
(
list
.
get
(
i
).
date
.
getTime
())});
}
return
true
;
}
return
false
;
}
private
String
sizeFormat
(
long
length
)
{
long
kb
;
if
(
length
<
1024
)
{
return
String
.
valueOf
(
length
);
}
else
if
((
kb
=
length
/
1024
)
<
1024
)
{
return
(
String
.
valueOf
(
kb
)
+
" kb "
);
}
else
{
return
(
String
.
valueOf
(
length
/
1024
/
1024
)
+
" kb "
);
}
}
public
void
refresh
(){
listFiles
();
}
// 处理路径的选择事件
public
void
actionPerformed
(
ActionEvent
e
)
{
if
(
e
.
getSource
()
==
jbUp
){
if
(
currentPath
.
equals
(
"/"
)){
}
else
{
FileView
.
BackPreviousFolder
(
ftpClient
);
jlLocal
.
setText
(
jlLocal
.
getText
().
substring
(
0
,
jlLocal
.
getText
().
lastIndexOf
(
"/"
)));
currentPath
=
jlLocal
.
getText
();
}
}
}
public
String
getfile1
(){
int
row
=
jtFile
.
getSelectedRow
();
int
column
=
0
;
file1
=
(
String
)
jtFile
.
getValueAt
(
row
,
column
);
return
file1
;
}
public
int
getindex
(){
int
i
=
jtFile
.
getSelectedRow
();
return
i
;
}
// JTable里文件夹双击事件
public
void
mouseClicked
(
MouseEvent
e
)
{
if
(
e
.
getClickCount
()
==
2
)
{
if
(
jtFile
.
getValueAt
(
jtFile
.
getSelectedRow
(),
2
).
equals
(
"文件夹"
)){
FileView
.
EnterFolder
(
ftpClient
,(
String
)
jtFile
.
getValueAt
(
jtFile
.
getSelectedRow
(),
0
));
jlLocal
.
setText
(
jlLocal
.
getText
()+(
String
)
jtFile
.
getValueAt
(
jtFile
.
getSelectedRow
(),
0
)+
"/"
);
currentPath
=
jlLocal
.
getText
();
}
else
{
JOptionPane
.
showMessageDialog
(
this
,
" 此路径不存在,或无此文件 "
);
}
}
}
// 其他一堆无用的事件
public
void
mouseEntered
(
MouseEvent
e
)
{}
public
void
mouseExited
(
MouseEvent
e
)
{}
public
void
mousePressed
(
MouseEvent
e
)
{}
public
void
mouseReleased
(
MouseEvent
e
)
{}
// 显示系统分区及文件路径 并 在JTabel中显示当前路径的文件信息
// 将文件大小转换成相应字符串格式
// 测试
public
static
void
main
(
String
[]
args
)
{
JFrame
jf
=
new
JFrame
(
" 测试 "
);
jf
.
setSize
(
300
,
400
);
jf
.
setDefaultCloseOperation
(
JFrame
.
EXIT_ON_CLOSE
);
Dimension
di
=
Toolkit
.
getDefaultToolkit
().
getScreenSize
();
jf
.
setLocation
((
int
)(
di
.
getWidth
()
-
jf
.
getWidth
())
/
2
,
(
int
)(
di
.
getHeight
()
-
jf
.
getHeight
())
/
2
);
jf
.
add
(
new
FtpPanel
());
jf
.
setVisible
(
true
);
}
// 实现相应的tablemodel类
class
LocalTableModel
extends
DefaultTableModel
{
public
boolean
isCellEditable
(
int
row
,
int
column
)
{
return
false
;
}
}
}
src/ftp/UI.java
浏览文件 @
be8b661c
...
...
@@ -27,8 +27,10 @@ public class UI extends JFrame {
JTextField
jTextField3
=
new
JTextField
();
JPasswordField
jPasswordField
=
new
JPasswordField
();
localPanel
localpanel
=
new
localPanel
();
FtpPanel
ftpPanel
=
new
FtpPanel
();
JScrollPane
jScrollPane
=
new
JScrollPane
();
TaskList
t
=
new
TaskList
();
public
UI
(){
setTitle
(
"ftp软件"
);
...
...
@@ -65,13 +67,15 @@ public class UI extends JFrame {
jButton2
.
setBounds
(
820
,
20
,
100
,
20
);
jButton3
.
setBounds
(
170
,
290
,
90
,
40
);
jButton4
.
setBounds
(
750
,
290
,
90
,
40
);
localpanel
.
setBounds
(
30
,
330
,
500
,
300
);
localpanel
.
setBounds
(
30
,
330
,
450
,
300
);
ftpPanel
.
setBounds
(
500
,
330
,
450
,
300
);
jButton5
.
setBounds
(
650
,
290
,
90
,
40
);
jButton6
.
setBounds
(
850
,
290
,
90
,
40
);
jScrollPane
.
setBounds
(
30
,
50
,
800
,
200
);
c
.
add
(
jLabel1
);
c
.
add
(
jLabel2
);
c
.
add
(
jLabel3
);
...
...
@@ -87,6 +91,7 @@ public class UI extends JFrame {
c
.
add
(
jButton5
);
c
.
add
(
jButton6
);
c
.
add
(
localpanel
);
c
.
add
(
ftpPanel
);
//c.add(jTextArea);
c
.
add
(
jScrollPane
);
...
...
@@ -183,6 +188,7 @@ public class UI extends JFrame {
@Override
public
void
actionPerformed
(
ActionEvent
e
)
{
//刷新操作
ftpPanel
.
refresh
();
jTextArea
.
append
(
number
+
".刷新成功"
);
jTextArea
.
append
(
"\n"
);
number
++;
...
...
@@ -191,36 +197,60 @@ public class UI extends JFrame {
class
jButton6event
implements
ActionListener
{
@Override
public
void
actionPerformed
(
ActionEvent
e
)
{
jTextArea
.
append
(
number
+
".删除成功"
);
jTextArea
.
append
(
"\n"
);
number
++;
DeleteFiles
deleteFiles
=
new
DeleteFiles
();
if
(
ftpPanel
.
getindex
()!=-
1
){
deleteFiles
.
deleteServerFiles
(
ftpClient
,
ftpPanel
.
getfile1
(),
ftpPanel
.
getCurrentPath
());
jTextArea
.
append
(
number
+
".删除成功"
);
jTextArea
.
append
(
"\n"
);
number
++;
}
else
{
jTextArea
.
append
(
number
+
".请选择文件"
);
jTextArea
.
append
(
"\n"
);
number
++;
}
}
}
class
jButton
3
event
implements
ActionListener
{
class
jButton
4
event
implements
ActionListener
{
@Override
public
void
actionPerformed
(
ActionEvent
e
)
{
if
(
localpanel
.
getindex
()==-
1
){
jTextArea
.
append
(
number
+
".请选择文件"
);
jTextArea
.
append
(
"\n"
);
number
++;
}
else
{
String
filepath
=
new
String
();
filepath
=
localpanel
.
getCurrentPath
()+
"\\"
+
localpanel
.
getfile1
();
System
.
out
.
println
(
filepath
);
}
//文件路径为filepath,剩下的代码为
上传
操作。
jTextArea
.
append
(
number
+
".
上传
成功"
);
System
.
out
.
println
(
filepath
);
t
.
newDownload
(
ftpPanel
.
getfile1
(),
localpanel
.
getCurrentPath
(),
ftpClient
);
//文件路径为filepath,剩下的代码为
下载
操作。
jTextArea
.
append
(
number
+
".
下载
成功"
);
jTextArea
.
append
(
"\n"
);
number
++;
}
}
}
class
jButton
4
event
implements
ActionListener
{
class
jButton
3
event
implements
ActionListener
{
@Override
public
void
actionPerformed
(
ActionEvent
e
)
{
//下载操作
jTextArea
.
append
(
number
+
".下载成功"
);
jTextArea
.
append
(
"\n"
);
number
++;
//上传操作
if
(
localpanel
.
getindex
()==-
1
){
jTextArea
.
append
(
number
+
".请选择文件"
);
jTextArea
.
append
(
"\n"
);
number
++;
}
else
{
String
filepath
=
new
String
();
filepath
=
localpanel
.
getCurrentPath
()+
"\\"
+
localpanel
.
getfile1
();
System
.
out
.
println
(
filepath
);
t
.
newUpload
(
ftpClient
,
filepath
);
//文件路径为filepath,剩下的代码为上传操作。
jTextArea
.
append
(
number
+
"."
);
jTextArea
.
append
(
"\n"
);
number
++;
}
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录