1. package systems.crigges.kamil;
  2. import java.awt.EventQueue;
  3. import javax.swing.JFrame;
  4. import javax.swing.GroupLayout;
  5. import javax.swing.GroupLayout.Alignment;
  6. import javax.swing.JButton;
  7. import javax.swing.JFileChooser;
  8. import javax.swing.JTextField;
  9. import javax.swing.LayoutStyle.ComponentPlacement;
  10. import javax.swing.UIManager;
  11. import javax.swing.UnsupportedLookAndFeelException;
  12. import javax.swing.JLabel;
  13. import javax.swing.JTextArea;
  14. import javax.swing.border.LineBorder;
  15. import javax.swing.plaf.FileChooserUI;
  16. import java.awt.Color;
  17. import java.awt.event.ActionListener;
  18. import java.io.File;
  19. import java.io.FileOutputStream;
  20. import java.nio.file.Files;
  21. import java.awt.event.ActionEvent;
  22. public class Kamil {
  23. private JFrame frame;
  24. private JTextField textField;
  25. private JTextField textField_1;
  26. private JTextField textField_2;
  27. /**
  28. * Launch the application.
  29. * @throws UnsupportedLookAndFeelException
  30. * @throws IllegalAccessException
  31. * @throws InstantiationException
  32. * @throws ClassNotFoundException
  33. */
  34. public static void main(String[] args) throws ClassNotFoundException, InstantiationException, IllegalAccessException, UnsupportedLookAndFeelException {
  35. UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
  36. EventQueue.invokeLater(new Runnable() {
  37. public void run() {
  38. try {
  39. Kamil window = new Kamil();
  40. window.frame.setVisible(true);
  41. } catch (Exception e) {
  42. e.printStackTrace();
  43. }
  44. }
  45. });
  46. }
  47. /**
  48. * Create the application.
  49. */
  50. public Kamil() {
  51. initialize();
  52. }
  53. /**
  54. * Initialize the contents of the frame.
  55. */
  56. private void initialize() {
  57. frame = new JFrame();
  58. frame.setBounds(100, 100, 729, 354);
  59. frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  60. JButton btnSelect = new JButton("Select...");
  61. btnSelect.addActionListener(new ActionListener() {
  62. public void actionPerformed(ActionEvent e) {
  63. JFileChooser fc = new JFileChooser();
  64. fc.setCurrentDirectory(new File(textField.getText().equals("") ? "." : textField.getText()));
  65. fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
  66. fc.setAcceptAllFileFilterUsed(false);
  67. if (fc.showOpenDialog(frame) == JFileChooser.APPROVE_OPTION) {
  68. textField.setText(fc.getSelectedFile().getAbsolutePath());
  69. }
  70. }
  71. });
  72. textField = new JTextField();
  73. textField.setEditable(false);
  74. textField.setColumns(10);
  75. JLabel lblSource = new JLabel("Source Folder");
  76. textField_1 = new JTextField();
  77. textField_1.setEditable(false);
  78. textField_1.setColumns(10);
  79. JLabel lblDestinationFolder = new JLabel("Destination Folder");
  80. JButton button = new JButton("Select...");
  81. button.addActionListener(new ActionListener() {
  82. public void actionPerformed(ActionEvent e) {
  83. JFileChooser fc = new JFileChooser();
  84. fc.setCurrentDirectory(new File(textField_1.getText().equals("") ? "." : textField_1.getText() ));
  85. fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
  86. fc.setAcceptAllFileFilterUsed(false);
  87. if (fc.showOpenDialog(frame) == JFileChooser.APPROVE_OPTION) {
  88. textField_1.setText(fc.getSelectedFile().getAbsolutePath());
  89. }
  90. }
  91. });
  92. JButton btnNewButton = new JButton("Process");
  93. btnNewButton.addActionListener(new ActionListener() {
  94. public void actionPerformed(ActionEvent e) {
  95. try{
  96. File sourceFolder = new File(textField.getText());
  97. File[] files = sourceFolder.listFiles();
  98. for(File f : files){
  99. String content = new String(Files.readAllBytes(f.toPath()));
  100. int index = content.lastIndexOf(";$ZYKART_ENDE");
  101. String before = content.substring(0, index);
  102. String after = content.substring(index);
  103. String res = before + ";$ZYKLUS_ENDE\r\n" + after;
  104. FileOutputStream out = new FileOutputStream(new File(textField_1.getText() + "\\" + f.getName()));
  105. out.write(res.getBytes());
  106. out.close();
  107. if(!textField_2.getText().equals("")){
  108. out = new FileOutputStream(new File(textField_2.getText() + "\\" + f.getName()));
  109. out.write(res.getBytes());
  110. out.close();
  111. }
  112. f.delete();
  113. }
  114. }catch(Exception ec){
  115. ec.printStackTrace();;
  116. }
  117. }
  118. });
  119. JLabel lblDestinationFolder_1 = new JLabel("Destination Folder 2");
  120. textField_2 = new JTextField();
  121. textField_2.setEditable(false);
  122. textField_2.setColumns(10);
  123. JButton button_1 = new JButton("Select...");
  124. button_1.addActionListener(new ActionListener() {
  125. public void actionPerformed(ActionEvent e) {
  126. JFileChooser fc = new JFileChooser();
  127. fc.setCurrentDirectory(new File(textField_2.getText().equals("") ? "." : textField_2.getText() ));
  128. fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
  129. fc.setAcceptAllFileFilterUsed(false);
  130. if (fc.showOpenDialog(frame) == JFileChooser.APPROVE_OPTION) {
  131. textField_2.setText(fc.getSelectedFile().getAbsolutePath());
  132. }
  133. }
  134. });
  135. GroupLayout groupLayout = new GroupLayout(frame.getContentPane());
  136. groupLayout.setHorizontalGroup(
  137. groupLayout.createParallelGroup(Alignment.TRAILING)
  138. .addGroup(groupLayout.createSequentialGroup()
  139. .addContainerGap()
  140. .addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
  141. .addComponent(lblSource)
  142. .addComponent(btnNewButton, Alignment.TRAILING, GroupLayout.PREFERRED_SIZE, 143, GroupLayout.PREFERRED_SIZE)
  143. .addGroup(Alignment.TRAILING, groupLayout.createSequentialGroup()
  144. .addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
  145. .addComponent(textField_1, GroupLayout.DEFAULT_SIZE, 493, Short.MAX_VALUE)
  146. .addComponent(textField, Alignment.TRAILING, GroupLayout.DEFAULT_SIZE, 493, Short.MAX_VALUE))
  147. .addPreferredGap(ComponentPlacement.RELATED)
  148. .addGroup(groupLayout.createParallelGroup(Alignment.LEADING, false)
  149. .addComponent(btnSelect, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  150. .addComponent(button, GroupLayout.DEFAULT_SIZE, 101, Short.MAX_VALUE)))
  151. .addGroup(Alignment.TRAILING, groupLayout.createSequentialGroup()
  152. .addComponent(textField_2, GroupLayout.DEFAULT_SIZE, 567, Short.MAX_VALUE)
  153. .addPreferredGap(ComponentPlacement.RELATED)
  154. .addComponent(button_1, GroupLayout.PREFERRED_SIZE, 101, GroupLayout.PREFERRED_SIZE))
  155. .addComponent(lblDestinationFolder_1, GroupLayout.PREFERRED_SIZE, 182, GroupLayout.PREFERRED_SIZE)
  156. .addComponent(lblDestinationFolder, GroupLayout.PREFERRED_SIZE, 182, GroupLayout.PREFERRED_SIZE))
  157. .addContainerGap())
  158. );
  159. groupLayout.setVerticalGroup(
  160. groupLayout.createParallelGroup(Alignment.LEADING)
  161. .addGroup(groupLayout.createSequentialGroup()
  162. .addContainerGap()
  163. .addComponent(lblSource)
  164. .addPreferredGap(ComponentPlacement.RELATED)
  165. .addGroup(groupLayout.createParallelGroup(Alignment.BASELINE)
  166. .addComponent(textField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
  167. .addComponent(btnSelect))
  168. .addPreferredGap(ComponentPlacement.RELATED)
  169. .addComponent(lblDestinationFolder)
  170. .addPreferredGap(ComponentPlacement.RELATED)
  171. .addGroup(groupLayout.createParallelGroup(Alignment.BASELINE)
  172. .addComponent(textField_1, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
  173. .addComponent(button))
  174. .addPreferredGap(ComponentPlacement.RELATED)
  175. .addGroup(groupLayout.createParallelGroup(Alignment.TRAILING)
  176. .addGroup(groupLayout.createSequentialGroup()
  177. .addComponent(lblDestinationFolder_1)
  178. .addPreferredGap(ComponentPlacement.RELATED)
  179. .addComponent(textField_2, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
  180. .addComponent(button_1))
  181. .addPreferredGap(ComponentPlacement.RELATED, 38, Short.MAX_VALUE)
  182. .addComponent(btnNewButton)
  183. .addContainerGap())
  184. );
  185. frame.getContentPane().setLayout(groupLayout);
  186. }
  187. }

goto line:
Compare with:
text copy window edit this code post new code