|
@ -0,0 +1,153 @@ |
|
|
|
|
|
package package1; |
|
|
|
|
|
|
|
|
|
|
|
import java.awt.EventQueue; |
|
|
|
|
|
|
|
|
|
|
|
import javax.swing.JFrame; |
|
|
|
|
|
import javax.swing.JPanel; |
|
|
|
|
|
import java.awt.BorderLayout; |
|
|
|
|
|
import java.awt.TextField; |
|
|
|
|
|
import java.awt.event.ActionEvent; |
|
|
|
|
|
import java.awt.event.ActionListener; |
|
|
|
|
|
import java.io.File; |
|
|
|
|
|
import java.io.FileInputStream; |
|
|
|
|
|
import java.io.FileNotFoundException; |
|
|
|
|
|
import java.io.FileOutputStream; |
|
|
|
|
|
import java.io.IOException; |
|
|
|
|
|
import java.awt.Button; |
|
|
|
|
|
import javax.swing.JTextPane; |
|
|
|
|
|
import javax.swing.SwingWorker; |
|
|
|
|
|
|
|
|
|
|
|
import java.awt.Color; |
|
|
|
|
|
import javax.swing.JLabel; |
|
|
|
|
|
import javax.swing.JTextField; |
|
|
|
|
|
import javax.swing.JProgressBar; |
|
|
|
|
|
import java.awt.Font; |
|
|
|
|
|
|
|
|
|
|
|
public class Window extends SwingWorker<Object, Object>{ |
|
|
|
|
|
|
|
|
|
|
|
private JFrame frame; |
|
|
|
|
|
private JTextField tfOriginal; |
|
|
|
|
|
private JTextField tfCopy; |
|
|
|
|
|
private JProgressBar progressBar; |
|
|
|
|
|
private JLabel lbResult; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* Launch the application. |
|
|
|
|
|
*/ |
|
|
|
|
|
public static void main(String[] args) { |
|
|
|
|
|
EventQueue.invokeLater(new Runnable() { |
|
|
|
|
|
public void run() { |
|
|
|
|
|
try { |
|
|
|
|
|
Window window = new Window(); |
|
|
|
|
|
window.frame.setVisible(true); |
|
|
|
|
|
} catch (Exception e) { |
|
|
|
|
|
e.printStackTrace(); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* Create the application. |
|
|
|
|
|
*/ |
|
|
|
|
|
public Window() { |
|
|
|
|
|
initialize(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* Initialize the contents of the frame. |
|
|
|
|
|
*/ |
|
|
|
|
|
private void initialize() { |
|
|
|
|
|
frame = new JFrame(); |
|
|
|
|
|
frame.setBounds(100, 100, 450, 300); |
|
|
|
|
|
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); |
|
|
|
|
|
|
|
|
|
|
|
JPanel panel = new JPanel(); |
|
|
|
|
|
frame.getContentPane().add(panel, BorderLayout.CENTER); |
|
|
|
|
|
panel.setLayout(null); |
|
|
|
|
|
|
|
|
|
|
|
Button button = new Button("Copy"); |
|
|
|
|
|
button.setBounds(176, 84, 70, 22); |
|
|
|
|
|
panel.add(button); |
|
|
|
|
|
|
|
|
|
|
|
JTextPane textPane = new JTextPane(); |
|
|
|
|
|
textPane.setText(" --->"); |
|
|
|
|
|
textPane.setBackground(new Color(192, 192, 192)); |
|
|
|
|
|
textPane.setBounds(186, 56, 54, 20); |
|
|
|
|
|
panel.add(textPane); |
|
|
|
|
|
|
|
|
|
|
|
JLabel lblNewLabel = new JLabel("WARNING: Please put the absolute route with the file name and extention"); |
|
|
|
|
|
lblNewLabel.setBounds(24, 11, 379, 35); |
|
|
|
|
|
panel.add(lblNewLabel); |
|
|
|
|
|
|
|
|
|
|
|
tfOriginal = new JTextField(); |
|
|
|
|
|
tfOriginal.setToolTipText("Original File"); |
|
|
|
|
|
tfOriginal.setColumns(10); |
|
|
|
|
|
tfOriginal.setBounds(24, 56, 153, 20); |
|
|
|
|
|
panel.add(tfOriginal); |
|
|
|
|
|
|
|
|
|
|
|
tfCopy = new JTextField(); |
|
|
|
|
|
tfCopy.setToolTipText("Copied File"); |
|
|
|
|
|
tfCopy.setColumns(10); |
|
|
|
|
|
tfCopy.setBounds(250, 56, 153, 20); |
|
|
|
|
|
panel.add(tfCopy); |
|
|
|
|
|
|
|
|
|
|
|
progressBar = new JProgressBar(); |
|
|
|
|
|
progressBar.setBounds(24, 179, 379, 22); |
|
|
|
|
|
panel.add(progressBar); |
|
|
|
|
|
|
|
|
|
|
|
lbResult = new JLabel(""); |
|
|
|
|
|
lbResult.setFont(new Font("Tahoma", Font.BOLD, 13)); |
|
|
|
|
|
lbResult.setBounds(186, 132, 106, 31); |
|
|
|
|
|
panel.add(lbResult); |
|
|
|
|
|
|
|
|
|
|
|
button.addActionListener(new ActionListener() { |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
public void actionPerformed(ActionEvent e) { |
|
|
|
|
|
|
|
|
|
|
|
operacion(); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void operacion() { |
|
|
|
|
|
try{ |
|
|
|
|
|
FileInputStream input = new FileInputStream(tfOriginal.getText()); |
|
|
|
|
|
FileOutputStream output = new FileOutputStream(tfCopy.getText()); |
|
|
|
|
|
byte[] complet = input.readAllBytes(); |
|
|
|
|
|
progressBar.setMinimum(0); |
|
|
|
|
|
progressBar.setMaximum(complet.length); |
|
|
|
|
|
|
|
|
|
|
|
for(int i = 0; i < complet.length; i++) { |
|
|
|
|
|
output.write(complet[i]); |
|
|
|
|
|
lbResult.setText("1"); |
|
|
|
|
|
Thread.sleep(50); |
|
|
|
|
|
lbResult.setText("2"); |
|
|
|
|
|
progressBar.setValue(i + 1); |
|
|
|
|
|
progressBar.update(progressBar.getGraphics()); |
|
|
|
|
|
} |
|
|
|
|
|
lbResult.setText("Copied"); |
|
|
|
|
|
|
|
|
|
|
|
} catch (FileNotFoundException e) { |
|
|
|
|
|
lbResult.setText("FileError"); |
|
|
|
|
|
e.printStackTrace(); |
|
|
|
|
|
} catch (IOException e) { |
|
|
|
|
|
lbResult.setText("Error"); |
|
|
|
|
|
e.printStackTrace(); |
|
|
|
|
|
} catch (InterruptedException e) { |
|
|
|
|
|
lbResult.setText("ThreadError"); |
|
|
|
|
|
e.printStackTrace(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
protected Object doInBackground() throws Exception { |
|
|
|
|
|
lbResult.setText("xd"); |
|
|
|
|
|
return null; |
|
|
|
|
|
} |
|
|
|
|
|
} |