📄 frame1.java~11~
字号:
package untitled1;import java.awt.*;import java.awt.event.*;import javax.swing.*;import java.io.*;/** * <p>Title: </p> * <p>Description: </p> * <p>Copyright: Copyright (c) 2004</p> * <p>Company: </p> * @author not attributable * @version 1.0 */public class Frame1 extends JFrame { private JPanel contentPane; private BorderLayout borderLayout1=new BorderLayout(); private JPanel jPanel1=new JPanel(); private JScrollPane jScollPane1=new JScrollPane(); private JTextArea jTextArea1=new JTextArea(); private JButton jButton1 = new JButton(); private JLabel jLabel1=new JLabel(); private JLabel jLabel2=new JLabel(); private GridLayout gridLayout=new GridLayout(); private JTextField jTextField1=new JTextField(); private JTextField jTextField2=new JTextField(); File infile=null; File outfile=null; FileInputStream fis=null; FileOutputStream fos=null; DataInputStream dis=null; DataOutputStream dos=null; public Frame1() { enableEvents(AWTEvent.WINDOW_EVENT_MASK); try { jbInit(); } catch(Exception e) { e.printStackTrace(); } } //Component initialization private void jbInit() throws Exception { contentPane=(JPanel)this.getContentPane(); contentPane.setLayout(borderLayout1); this.setSize(new Dimension(292, 206)); this.setTitle("大文件copy"); jButton1.setText("Start"); jLabel1.setMaximumSize(new Dimension(50,18)); jLabel1.setText("源文件:"); jLabel2.setText("目标文件:"); jPanel1.setLayout(gridLayout); gridLayout.setColumns(2); gridLayout.setRows(2); contentPane.add(jPanel1,BorderLayout.NORTH); jPanel1.add(jLabel1,null); jPanel1.add(jTextField1,null); jPanel1.add(jLabel2,null); jPanel1.add(jTextField2,null); contentPane.add(jScollPane1,BorderLayout.CENTER); jScollPane1.getViewport().add(jTextArea1,null); contentPane.add(jButton1,BorderLayout.SOUTH); jButton1.addActionListener(new java.awt.event.ActionListener(){ public void actionPerformed(ActionEvent e){ jButton1_actionPerformed(e); } }); } //Overridden so we can exit when window is closed protected void processWindowEvent(WindowEvent e) { super.processWindowEvent(e); if (e.getID() == WindowEvent.WINDOW_CLOSING) { System.exit(0); } }void jButton1_actionPerformed(ActionEvent e) { final int BufferSize=1024; byte[] buffer=new byte[BufferSize]; try{ infile=new File(this.jTextField1.getText()); outfile=new File(this.jTextField2.getText()); if(!outfile.exists()) outfile.createNewFile(); fis=new FileInputStream(infile); fos=new FileOutputStream(outfile); dis=new DataInputStream(fis); dos=new DataOutputStream(fos); this.jTextArea1.setText(""); this.jTextArea1.append("Read from file "+ infile.getAbsolutePath()+"\n"); this.jTextArea1.append("Write to file "+ outfile.getAbsolutePath()+"\n"); int bytes; while((bytes=dis.read(buffer,0,BufferSize))!=-1){ dos.write(buffer,0,bytes); this.jTextArea1.append("Read "+ bytes+ "B"+ " Write "+ bytes+ "B"+"\n"); } this.jTextArea1.append("Complete\n"); dis.close(); dos.close(); } catch(Exception err){ } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -