|
@ -0,0 +1,156 @@ |
|
|
|
|
|
package Package; |
|
|
|
|
|
import java.awt.EventQueue;import java.awt.FontMetrics; |
|
|
|
|
|
import java.awt.Graphics; |
|
|
|
|
|
|
|
|
|
|
|
import javax.swing.JFrame; |
|
|
|
|
|
import javax.swing.JMenuBar; |
|
|
|
|
|
import javax.swing.JMenuItem; |
|
|
|
|
|
import javax.swing.JMenu; |
|
|
|
|
|
import javax.swing.JButton; |
|
|
|
|
|
import java.awt.BorderLayout; |
|
|
|
|
|
import java.awt.Color; |
|
|
|
|
|
import java.awt.Dimension; |
|
|
|
|
|
|
|
|
|
|
|
import javax.swing.JTextArea; |
|
|
|
|
|
import javax.swing.JTextField; |
|
|
|
|
|
import javax.swing.JProgressBar; |
|
|
|
|
|
import javax.swing.JSplitPane; |
|
|
|
|
|
import javax.swing.JLabel; |
|
|
|
|
|
import java.awt.GridLayout; |
|
|
|
|
|
import java.awt.Image; |
|
|
|
|
|
import java.awt.Rectangle; |
|
|
|
|
|
import java.awt.Shape; |
|
|
|
|
|
import java.awt.event.ActionEvent; |
|
|
|
|
|
import java.awt.event.ActionListener; |
|
|
|
|
|
import java.awt.image.ImageObserver; |
|
|
|
|
|
import java.io.DataInputStream; |
|
|
|
|
|
import java.io.DataOutputStream; |
|
|
|
|
|
import java.io.File; |
|
|
|
|
|
import java.io.FileInputStream; |
|
|
|
|
|
import java.io.FileNotFoundException; |
|
|
|
|
|
import java.io.FileOutputStream; |
|
|
|
|
|
import java.io.IOException; |
|
|
|
|
|
import java.text.AttributedCharacterIterator; |
|
|
|
|
|
|
|
|
|
|
|
import javax.swing.JPanel; |
|
|
|
|
|
import javax.swing.SwingConstants; |
|
|
|
|
|
|
|
|
|
|
|
public class MyAplication { |
|
|
|
|
|
|
|
|
|
|
|
private JFrame frame; |
|
|
|
|
|
private JTextField textField; |
|
|
|
|
|
private JTextField textField_1; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* Launch the application. |
|
|
|
|
|
*/ |
|
|
|
|
|
public static void main(String[] args) { |
|
|
|
|
|
EventQueue.invokeLater(new Runnable() { |
|
|
|
|
|
public void run() { |
|
|
|
|
|
try { |
|
|
|
|
|
MyAplication window = new MyAplication(); |
|
|
|
|
|
window.frame.setVisible(true); |
|
|
|
|
|
} catch (Exception e) { |
|
|
|
|
|
e.printStackTrace(); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* Create the application. |
|
|
|
|
|
*/ |
|
|
|
|
|
public MyAplication() { |
|
|
|
|
|
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); |
|
|
|
|
|
|
|
|
|
|
|
JMenuBar menuBar = new JMenuBar(); |
|
|
|
|
|
frame.setJMenuBar(menuBar); |
|
|
|
|
|
|
|
|
|
|
|
JMenu mnNewMenu = new JMenu("New menu"); |
|
|
|
|
|
menuBar.add(mnNewMenu); |
|
|
|
|
|
frame.getContentPane().setLayout(new GridLayout(0, 1, 0, 0)); |
|
|
|
|
|
|
|
|
|
|
|
JPanel panel = new JPanel(); |
|
|
|
|
|
frame.getContentPane().add(panel); |
|
|
|
|
|
|
|
|
|
|
|
JSplitPane splitPane_1 = new JSplitPane(); |
|
|
|
|
|
panel.add(splitPane_1); |
|
|
|
|
|
|
|
|
|
|
|
JLabel f1 = new JLabel("Fichero 1"); |
|
|
|
|
|
splitPane_1.setLeftComponent(f1); |
|
|
|
|
|
|
|
|
|
|
|
textField = new JTextField(); |
|
|
|
|
|
splitPane_1.setRightComponent(textField); |
|
|
|
|
|
textField.setColumns(10); |
|
|
|
|
|
|
|
|
|
|
|
JSplitPane splitPane = new JSplitPane(); |
|
|
|
|
|
panel.add(splitPane); |
|
|
|
|
|
|
|
|
|
|
|
JLabel f2 = new JLabel("Fichero 2"); |
|
|
|
|
|
splitPane.setLeftComponent(f2); |
|
|
|
|
|
|
|
|
|
|
|
textField_1 = new JTextField(); |
|
|
|
|
|
splitPane.setRightComponent(textField_1); |
|
|
|
|
|
|
|
|
|
|
|
JProgressBar progressBar = new JProgressBar(0,100); |
|
|
|
|
|
panel.add(progressBar); |
|
|
|
|
|
textField_1.setColumns(10); |
|
|
|
|
|
|
|
|
|
|
|
JButton btnNewButton = new JButton("COPY!"); |
|
|
|
|
|
panel.add(btnNewButton); |
|
|
|
|
|
|
|
|
|
|
|
btnNewButton.addActionListener(new ActionListener() { |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
public void actionPerformed(ActionEvent e) { |
|
|
|
|
|
// TODO Auto-generated method stub |
|
|
|
|
|
copy(f1.getText(),f2.getText(), progressBar); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void copy(String f1, String f2, JProgressBar progressBar) { |
|
|
|
|
|
File input=new File(textField.getText()); |
|
|
|
|
|
File output=new File(textField_1.getText()); |
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
|
|
FileInputStream in = new FileInputStream(textField.getText()); |
|
|
|
|
|
FileOutputStream out = new FileOutputStream(textField_1.getText()); |
|
|
|
|
|
|
|
|
|
|
|
int n=0,c,total = progressBar.getMinimum(); |
|
|
|
|
|
|
|
|
|
|
|
System.out.print ("\nCopiando ..."); |
|
|
|
|
|
while( (c = in.read()) != -1){ |
|
|
|
|
|
progressBar.setValue(total++); |
|
|
|
|
|
out.write(c); |
|
|
|
|
|
n++; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
in.close(); |
|
|
|
|
|
out.close(); |
|
|
|
|
|
System.out.print ("\nSe han copiado "+n+" caracteres\n"); |
|
|
|
|
|
|
|
|
|
|
|
} catch (FileNotFoundException e1) { |
|
|
|
|
|
// TODO Auto-generated catch block |
|
|
|
|
|
e1.printStackTrace(); |
|
|
|
|
|
} catch (IOException e1) { |
|
|
|
|
|
// TODO Auto-generated catch block |
|
|
|
|
|
e1.printStackTrace(); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |