import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.io.*;
public class FrmMain extends Applet implements Runnable, ActionListener
{
private TextArea msg;
private JTextField t;
private JButton b1;
private JButton b2;
private JPanel p;
private FileInputStream fin=null;
private FileOutputStream fout=null;
private String pathname=null;
private String filename=null;
private byte buf[];
Thread th;
public void init()
{
msg=new TextArea(50,20);
t=new JTextField(20);
b1=new JButton(\"选择\");
b2=new JButton(\"复制\");
b1.setFont(new Font(\"DialogInput\", 0, 12));
b2.setFont(new Font(\"DialogInput\", 0, 12));
p=new JPanel();
this.setLayout(new BorderLayout());
this.add(\"Center\",msg);
this.add(\"South\",p);
p.add(t);
p.add(b1);
p.add(b2);b1.addActionListener(this);
b2.addActionListener(this);
}
public void run()
{
try
{
fin=new FileInputStream(pathname);
fout=new FileOutputStream(filename);
buf=new byte[1024];
msg.append(\"正在复制文件\"+filename+\"\n\");
while(fin.read(buf)!=-1)
{
fout.write(buf);
}
msg.append(\"复制成功!\n\");
}
catch(Exception e)
{
System.out.println(e);
msg.append(\"复制失败!\n\");
}
}
public static void main(String[] args)
{
FrmMain app=new FrmMain();
Frame frm=new Frame(\"坏碟文件拷贝工具\");
app.init();
app.start();
frm.add(app);
frm.setSize(400,300);
frm.setResizable(false);
Dimension d=Toolkit.getDefaultToolkit().getScreenSize();
Dimension f=frm.getSize();
frm.setLocation(d.width/2-f.width/2,d.height/2-f.height/2);
frm.show();
frm.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent evt)
{
System.exit(0);
}
});
}public void actionPerformed(ActionEvent e)
{
if(e.getActionCommand().equals(\"选择\"))
{
FileDialog fdlg=new FileDialog(new Frame(),\"选择传送的文件\",FileDialog.LOAD);
fdlg.setVisible(true);
t.setText(fdlg.getDirectory()+fdlg.getFile());
filename=fdlg.getFile();
pathname=t.getText();
}
else
{
if(pathname.equals(\"\")||pathname.equals(\"nullnull\"))
{
JOptionPane.showMessageDialog(null,\"没有选择发送的文件\",\"错误\",JOptionPane.ERROR_MESSAGE);
return;
}
th=new Thread(this);
th.start();
}
}
}