📄 frmmain.java
字号:
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 JButton b1; private JButton b2; private JButton b3; private JPanel p; private FileInputStream fin=null; private FileOutputStream fout=null; private String pathname=null; private String filename=null; private String pathname_to=null; private byte buf[]; Thread th; public void init() { msg=new TextArea(50,20); b1=new JButton("选择"); b2=new JButton("复制"); b3=new JButton("保存"); b1.setFont(new Font("DialogInput", 0, 12)); b2.setFont(new Font("DialogInput", 0, 12)); b3.setFont(new Font("DialogInput", 0, 12)); p=new JPanel(); this.setLayout(new BorderLayout()); this.add("Center",msg); this.add("South",p); p.add(b1); p.add(b3); p.add(b2); b1.addActionListener(this); b2.addActionListener(this); b3.addActionListener(this); } public void run() { try { fin=new FileInputStream(pathname); fout=new FileOutputStream(pathname_to); buf=new byte[1024]; msg.append("正在复制文件"+filename+"\n"); while(fin.read(buf)!=-1) { fout.write(buf); } msg.append("复制成功!\n"); } catch(Exception e) { msg.append(e.getMessage()+"\n"); } } public static void main(String[] args) { FrmMain app=new FrmMain(); Frame frm=new Frame("坏碟文件拷贝工具"); app.init(); app.start(); frm.add(app); frm.setSize(500,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); msg.append("要复制的文件:"+fdlg.getDirectory()+fdlg.getFile()+"\n"); filename=fdlg.getFile(); pathname=fdlg.getDirectory()+fdlg.getFile(); return; } if(e.getActionCommand().equals("复制")) { if(pathname.equals("")||pathname.equals("nullnull")) { JOptionPane.showMessageDialog(null,"没有选择发送的文件","错误",JOptionPane.ERROR_MESSAGE); return; } th=new Thread(this); th.start(); return; } if(e.getActionCommand().equals("保存")) { System.out.println("aaa"); FileDialog fdlg=new FileDialog(new Frame(),"选择传送的文件",FileDialog.SAVE); fdlg.setVisible(true); msg.append("复制到:"+fdlg.getDirectory()+fdlg.getFile()+"\n"); pathname_to=fdlg.getDirectory()+fdlg.getFile(); return; } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -