📄 fss.java
字号:
checkp.setLayout(new GridLayout(1, 4));
checkp.add(readc);
checkp.add(writec);
checkp.add(deletec);
checkp.add(exec);
d.add(checkp);
JButton b2 = new JButton("确认");
b2.addActionListener(this);
d.add(b2, "South");
d.setVisible(true);
} else if (s.equals("清除列表")) {
xiaoxi.setText("");
editedfiles.removeAllElements();
} else if (s.equals("在线用户")) {
d7 = new Dialog(this, "在线用户", true);
d7.setSize(400, 400);
d7.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
d7.dispose();
}
});
JList l = new JList(zaixian);
JScrollPane pane = new JScrollPane(l);
pane
.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
pane
.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
d7.add(pane);
d7.setVisible(true);
} else if (s.equals("管理用户")) {
d4.setSize(250, 100);
Dimension sc = d4.getToolkit().getScreenSize();
Dimension sz = d4.getSize();
d4.setLocation(sc.width / 2 - sz.width / 2, sc.height / 2
- sz.height / 2);
d4.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
d4.dispose();
}
});
JButton db = new JButton("增加用户");
db.addActionListener(this);
JButton m1 = new JButton("选择要删除的用户");
m1.addActionListener(this);
JMenuBar bar = new JMenuBar();
bar.add(m1);
bar.add(db);
d4.setJMenuBar(bar);
d4.setVisible(true);
} else if (s.equals("选择要删除的用户")) {
d6 = new Dialog(d4, "选择要删除的用户", true);
d6.setSize(400, 400);
Dimension sc = d6.getToolkit().getScreenSize();
Dimension sz = d6.getSize();
d6.setLocation(sc.width / 2 - sz.width / 2, sc.height / 2
- sz.height / 2);
d6.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
d6.dispose();
}
});
JPanel ppp = new JPanel();
ppp.setLayout(new GridLayout(user.size(), 1));
JScrollPane pane = new JScrollPane(ppp);
pane
.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
pane
.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
cmi = new Checkbox[user.size()];
for (int i = 0; i < cmi.length; i++) {
cmi[i] = new Checkbox(user.elementAt(i) + " { "
+ users.get(user.elementAt(i)) + " }");
ppp.add(cmi[i]);
}
d6.add(pane);
JButton db = new JButton("确认");
db.setActionCommand("确认6");
db.addActionListener(this);
d6.add(db, "North");
d6.setVisible(true);
} else if (s.equals("确认6")) {
d6.dispose();
for (int i = 0; i < cmi.length; i++) {
if (cmi[i].getState()) {
users.remove(user.elementAt(i));
user.removeElementAt(i);
}
}
} else if (s.equals("增加用户")) {
d5 = new Dialog(d4, "增加用户", true);
d5.setSize(400, 200);
Dimension sc = d5.getToolkit().getScreenSize();
Dimension sz = d5.getSize();
d5.setLocation(sc.width / 2 - sz.width / 2, sc.height / 2
- sz.height / 2);
d5.setLayout(new GridLayout(3, 1));
d5.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
d5.dispose();
}
});
JPanel p1 = new JPanel();
p1.setLayout(new FlowLayout(FlowLayout.LEFT));
p1.add(new JLabel("新用户名 :"));
z1 = new JTextField(20);
p1.add(z1);
d5.add(p1);
JPanel p2 = new JPanel();
p2.setLayout(new FlowLayout(FlowLayout.LEFT));
p2.add(new JLabel("新用户密码:"));
z2 = new JPasswordField(20);
p2.add(z2);
d5.add(p2);
JButton db = new JButton("确认");
db.setActionCommand("确认4");
db.addActionListener(this);
d5.add(db);
d5.setVisible(true);
} else if (s.equals("确认4")) {
d5.dispose();
String s1 = z1.getText().trim();
String s2 = z2.getText().trim();
if (s1 == null || s2 == null || s1.length() == 0
|| s2.length() == 0) {
JOptionPane.showMessageDialog(this, "有未填的数据!", "Error",
JOptionPane.ERROR_MESSAGE);
return;
}
if (users.containsKey(s1)) {
} else {
user.addElement(s1);
}
users.put(s1, s2);
} else if (s.equals("刷新")) {
dispose();
new BendiFrame();
} else if (s.equals("浏览...")) {
new FileTree1(f, d);
} else if (s.equals("浏览")) {
new FileTree1(f2, d1);
} else if (s.equals("确认")) {
d.dispose();
if (readc.getState()) {
read.remove(f.getText());
} else {
read.put(f.getText(), "notread");
}
if (writec.getState()) {
write.remove(f.getText());
} else {
write.put(f.getText(), "notwrite");
}
if (exec.getState()) {
exe.remove(f.getText());
} else {
exe.put(f.getText(), "notexe");
}
if (!deletec.getState()) {
notdeletef.add(f.getText());
} else {
notdeletef.remove(f.getText());
}
f.setText("");
} else if (s.equals("确认2")) {
String sa = f2.getText().trim();
if (f2.getText() == null || sa.length() == 0) {
for (int j = 0; j < v.size(); j++) {
}
} else {
{
for (int i = 0; i < v.size(); i++) {
if (sa.indexOf(v.elementAt(i)) != -1) {
JOptionPane.showMessageDialog(this,
"本文件(夹)的上层目录已共享,无需设置共享!", "Error",
JOptionPane.ERROR_MESSAGE);
break;
} else {
if (f2.getText().trim().lastIndexOf("\\") != f2
.getText().trim().length() - 1) {
v.add(f2.getText().trim());
} else {
v.add(f2.getText().trim().substring(
0,
f2.getText().trim().lastIndexOf(
"\\")));
}
break;
}
}
}
d1.dispose();
}
} else if (s.equals("确认3")) {
for (int i = 0; i < chs.length; i++) {
if (!chs[i].getState()) {
v.removeElementAt(i);
}
}
d3.dispose();
} else if (s.equals("添加共享文件(夹)")) {
d1 = new Dialog(this, "添加共享文件(夹)", true);
d1.setSize(200, 100);
Dimension sc = d1.getToolkit().getScreenSize();
Dimension sz = d1.getSize();
d1.setLocation(sc.width / 2 - sz.width / 2, sc.height / 2
- sz.height / 2);
d1.setLayout(new FlowLayout(FlowLayout.CENTER));
f2 = new JTextField(20);
d1.add(f2);
JButton bb = new JButton("浏览...");
bb.addActionListener(this);
bb.setActionCommand("浏览");
d1.add(bb);
JButton q = new JButton("确认");
q.addActionListener(this);
q.setActionCommand("确认2");
d1.add(q);
d1.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
d1.dispose();
}
});
d1.setVisible(true);
} else if (s.equals("删除共享文件(夹)")) {
d3 = new Dialog(this, "删除共享文件夹", true);
d3.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
d3.dispose();
}
});
// Container c = d2.getContentPane();
d3.setSize(300, 300);
JPanel p = new JPanel();
p.setLayout(new GridLayout(v.size(), 1));
JScrollPane con = new JScrollPane(p);
chs = new Checkbox[v.size()];
for (int i = 0; i < v.size(); i++) {
chs[i] = new Checkbox(v.elementAt(i), true);
p.add(chs[i]);
}
con
.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
con
.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
d3.add(con);
d3.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
d3.dispose();
}
});
JButton b = new JButton("确认");
b.addActionListener(this);
b.setActionCommand("确认3");
d3.add(b, "North");
Dimension sc = d3.getToolkit().getScreenSize();
Dimension sz = d3.getSize();
d3.setLocation(sc.width / 2 - sz.width / 2, sc.height / 2
- sz.height / 2);
d3.setVisible(true);
} else if (s.equals("浏览已共享文件夹")) {
d2 = new Dialog(this, "浏览已共享文件夹", true);
String[] s5 = new String[v.size()];
for (int i = 0; i < v.size(); i++) {
s5[i] = (String) v.elementAt(i);
}
// Container c = d2.getContentPane();
d2.setSize(300, 300);
JList l = new JList(s5);
JScrollPane con = new JScrollPane(l);
con
.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
con
.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
d2.add(con);
d2.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
d2.dispose();
}
});
Dimension sc = d2.getToolkit().getScreenSize();
Dimension sz = d2.getSize();
d2.setLocation(sc.width / 2 - sz.width / 2, sc.height / 2
- sz.height / 2);
d2.setVisible(true);
}
}
}
public class Download extends Thread {
String s = "";
boolean b;
JFrame frame;
public Download(String ns, boolean nb, JFrame newFrame) {
s = ns;
b = nb;
frame = newFrame;
}
public void run() {
DatagramSocket jieshoutongyi = null;
try {
DatagramSocket uploads = new DatagramSocket();
byte[] uploadb = s.getBytes();
DatagramPacket uploadsp = new DatagramPacket(uploadb,
uploadb.length, InetAddress.getByName(ip.getText()
.trim()), 8003);
uploads.send(uploadsp);
uploads.close();
File newf = new File(s.substring(
(s.substring(0, s.length() - 1)).lastIndexOf("\\") + 1)
.trim());
;
newf.createNewFile();
FileOutputStream out = new FileOutputStream(newf);
int ccc = 0;
byte[] jieshoutongyib = new byte[20];
try {
jieshoutongyi = new DatagramSocket(6767);
} catch (Exception e) {
return;
}
DatagramPacket jieshoutongyip = new DatagramPacket(
jieshoutongyib, jieshoutongyib.length);
jieshoutongyi.receive(jieshoutongyip);
jieshoutongyi.close();
String tongyi = new String(jieshoutongyip.getData(), 0,
jieshoutongyip.getLength()).trim();
DatagramSocket tongyis = new DatagramSocket();//
String tongyist = "B";
byte[] tongyib = tongyist.getBytes();
DatagramPacket tongyisp = new DatagramPacket(tongyib,
tongyib.length, InetAddress.getByName(ip.getText()),
8005);
tongyis.send(tongyisp);
tongyis.close();
baaa.setMinimum(0);
baaa.setStringPainted(true);
baaa.setMaximum((int) Double.parseDouble(tongyi));
tip.setText("等待......");
double max = baaa.getMaximum() * 1.0;
new COPY().jieshou();
baaa.setString(Double.toString(1.0 * ccc * 100.0 / max)
.substring(0, 5)
+ "%");
out.flush();
out.close();
tip.setText("拷贝成功");
downloadedfiles.add(newf.getName());
newf.exists();
} catch (Exception e) {
// TODO 自动生成 catch 块
if (jieshoutongyi != null && !jieshoutongyi.isClosed()) {
jieshoutongyi.close();
}
e.printStackTrace();
}
}
}
public class JieshouDownload extends Thread {
public void run() {
InetAddress add;
while (true) {
try {
DatagramSocket JieshouUploadserver = new DatagramSocket(
8003);
byte[] JieshouUploadserverb = new byte[400];
DatagramPacket JieshouUploadserverp = new DatagramPacket(
JieshouUploadserverb, JieshouUploadserverb.length);
JieshouUploadserver.receive(JieshouUploadserverp);
add = JieshouUploadserverp.getAddress();
JieshouUploadserver.close();
String filen = new String(JieshouUploadserverp.getData(),
0, JieshouUploadserverp.getLength()).trim();
File file = new File(filen);
DatagramSocket tongyis3 = new DatagramSocket();
String tongyist = "";
COPY copy = new COPY(file.getName(), filen, "", add
.toString().substring(1));
System.out.println(filen + "dfdfdfdf"+file.getName());
byte[] tongyib = (Integer.toString((int) (copy.f2(filen))))
.getBytes();
DatagramPacket tongyis3p = new DatagramPacket(tongyib,
tongyib.length, add, 6767);
tongyis3.send(tongyis3p);
tongyis3.close();
if (tongyist.equals("OK")) {
DatagramSocket jieshoutongyi = new DatagramSocket(8005);
byte[] jieshoutongyib = new byte[3];
DatagramPacket jieshoutongyip = new DatagramPacket(
jieshoutongyib, jieshoutongyib.length);
jieshoutongyi.receive(jieshoutongyip);
jieshoutongyi.close();
Date currentDate = new Date();
String lastdate = currentDate.toString();
copy.f1();
editedfiles.add("于" + lastdate + " , 文件: " + filen
+ "被 " + host + " 复制");
} else {
return;
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
private class link extends Thread {
public void run() {
while (true) {
try {
DatagramSocket links = new DatagramSocket(7567);
byte[] linkb = new byte[1];
DatagramPacket linkp = new DatagramPacket(linkb,
linkb.length);
links.receive(linkp);
String host3 = linkp.getAddress().getHostName()
+ " {" + linkp.getAddress().toString()
+ "}";
zaixian.remove(host3);
links.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -