Advertisement
Guest User

CopyFile

a guest
Apr 4th, 2017
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.74 KB | None | 0 0
  1. package data;
  2.  
  3. import java.nio.file.Files;
  4.  
  5. import java.nio.file.Paths;
  6.  
  7. import javax.swing.JButton;
  8. import javax.swing.JFrame;
  9. import javax.swing.JProgressBar;
  10.  
  11. import java.awt.EventQueue;
  12. import java.awt.event.ActionEvent;
  13. import java.awt.event.ActionListener;
  14. import java.io.File;
  15. import java.io.IOException;
  16.  
  17. public class CopyFile {
  18. private JFrame frame;
  19. private JProgressBar bar0;
  20. private JProgressBar bar1;
  21. private JProgressBar bar2;
  22. private JProgressBar bar3;
  23.  
  24. public static void main(String[] args) {
  25. EventQueue.invokeLater(new Runnable() {
  26. public void run() {
  27. try {
  28. CopyFile window = new CopyFile();
  29. window.frame.setVisible(true);
  30. } catch (Exception e) {
  31. e.printStackTrace();
  32. }
  33. }
  34. });
  35. }
  36.  
  37. public CopyFile() {
  38. initialize();
  39. }
  40.  
  41. private void initialize() {
  42. frame = new JFrame();
  43. frame.setBounds(250, 250, 450, 300);
  44. frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  45. frame.getContentPane().setLayout(null);
  46.  
  47. bar0 = new JProgressBar();
  48. bar0.setBounds(130, 70, 250, 30);
  49. frame.getContentPane().add(bar0);
  50.  
  51. bar1 = new JProgressBar();
  52. bar1.setBounds(130, 110, 250, 30);
  53. frame.getContentPane().add(bar1);
  54.  
  55. bar2 = new JProgressBar();
  56. bar2.setBounds(130, 150, 250, 30);
  57. frame.getContentPane().add(bar2);
  58.  
  59. bar3 = new JProgressBar();
  60. bar3.setBounds(130, 190, 250, 30);
  61. frame.getContentPane().add(bar3);
  62.  
  63. JButton copy = new JButton("Kopiuj");
  64. copy.addActionListener(new ActionListener() {
  65. public void actionPerformed(ActionEvent e) {
  66. int i;
  67. String source = "C:/Users/Osa/Desktop/kopiowanie1/";
  68. String destination = "C:/Users/Osa/Desktop/New/";
  69. for (i = 0; i != new File(source).list().length; i++) {
  70. }
  71. try {
  72. Files.createDirectory(Paths.get(destination));
  73. } catch (IOException e1) {
  74. e1.printStackTrace();
  75. }
  76. Runnable[] runners = new Runnable[4];
  77. Thread[] threads = new Thread[4];
  78.  
  79. runners[0] = new MyRun(source + new File(source).list()[0], destination + new File(source).list()[0],
  80. bar0);
  81. runners[1] = new MyRun(source + new File(source).list()[1], destination + new File(source).list()[1],
  82. bar1);
  83. runners[2] = new MyRun(source + new File(source).list()[2], destination + new File(source).list()[2],
  84. bar2);
  85. runners[3] = new MyRun(source + new File(source).list()[3], destination + new File(source).list()[3],
  86. bar3);
  87.  
  88. for (int counter = 0; counter < 4; counter++) {
  89. threads[counter] = new Thread(runners[counter]);
  90. }
  91.  
  92. for (int counter = 0; counter < new File(source).list().length; counter++) {
  93. threads[counter].start();
  94. }
  95. }
  96. });
  97. copy.setBounds(25, 15, 100, 35);
  98. frame.getContentPane().add(copy);
  99.  
  100. }
  101. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement