Skip to content
Home
Post Code
Jass (Warcraft III)
Wurst
GUI (Warcraft III)
Galaxy (StarCraft II)
GUI (StarCraft II)
C++
Java
Delphi
Text
Search Code
Compare Code
Uploads
Draw
Create New Drawing
View Drawings
Graph
Log in
[code][color=7777FF][b]package[/b][/color] systems[b].[/b]crigges[b].[/b]kamil; import java[b].[/b]awt[b].[/b]EventQueue; import javax[b].[/b]swing[b].[/b]JFrame; import javax[b].[/b]swing[b].[/b]GroupLayout; import javax[b].[/b]swing[b].[/b]GroupLayout[b].[/b]Alignment; import javax[b].[/b]swing[b].[/b]JButton; import javax[b].[/b]swing[b].[/b]JFileChooser; import javax[b].[/b]swing[b].[/b]JTextField; import javax[b].[/b]swing[b].[/b]LayoutStyle[b].[/b]ComponentPlacement; import javax[b].[/b]swing[b].[/b]UIManager; import javax[b].[/b]swing[b].[/b]UnsupportedLookAndFeelException; import javax[b].[/b]swing[b].[/b]JLabel; import javax[b].[/b]swing[b].[/b]JTextArea; import javax[b].[/b]swing[b].[/b]border[b].[/b]LineBorder; import javax[b].[/b]swing[b].[/b]plaf[b].[/b]FileChooserUI; import java[b].[/b]awt[b].[/b]Color; import java[b].[/b]awt[b].[/b]event[b].[/b]ActionListener; import java[b].[/b]io[b].[/b][color=7777FF][b]File[/b][/color]; import java[b].[/b]io[b].[/b]FileOutputStream; import java[b].[/b]nio[b].[/b][color=7777FF][b]file[/b][/color][b].[/b]Files; import java[b].[/b]awt[b].[/b]event[b].[/b]ActionEvent; [color=7777FF][b]public[/b][/color] [color=7777FF][b]class[/b][/color] Kamil [color=999999][i]{[/i][/color] [color=999999][i][/i][/color] [color=999999][i] private JFrame frame;[/i][/color] [color=999999][i] private JTextField textField;[/i][/color] [color=999999][i] private JTextField textField_1;[/i][/color] [color=999999][i] private JTextField textField_2;[/i][/color] [color=999999][i][/i][/color] [color=999999][i] /**[/i][/color] [color=999999][i] * Launch the application.[/i][/color] [color=999999][i] * @throws UnsupportedLookAndFeelException[/i][/color] [color=999999][i] * @throws IllegalAccessException[/i][/color] [color=999999][i] * @throws InstantiationException[/i][/color] [color=999999][i] * @throws ClassNotFoundException[/i][/color] [color=999999][i] */[/i][/color] [color=999999][i] public static void main(String[] args) throws ClassNotFoundException, InstantiationException, IllegalAccessException, UnsupportedLookAndFeelException {[/i][/color] [color=999999][i] UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());[/i][/color] [color=999999][i] EventQueue.invokeLater(new Runnable() {[/i][/color] [color=999999][i] public void run() {[/i][/color] [color=999999][i] try {[/i][/color] [color=999999][i] Kamil window = new Kamil();[/i][/color] [color=999999][i] window.frame.setVisible(true);[/i][/color] [color=999999][i] }[/i][/color] catch (Exception e) [color=999999][i]{[/i][/color] [color=999999][i] e.printStackTrace();[/i][/color] [color=999999][i] }[/i][/color] } }); } [b]/[/b]** * Create the application[b].[/b] *[b]/[/b] [color=7777FF][b]public[/b][/color] Kamil() [color=999999][i]{[/i][/color] [color=999999][i] initialize();[/i][/color] [color=999999][i] }[/i][/color] [b]/[/b]** * Initialize the contents [color=7777FF][b]of[/b][/color] the frame[b].[/b] *[b]/[/b] [color=7777FF][b]private[/b][/color] void initialize() [color=999999][i]{[/i][/color] [color=999999][i] frame = new JFrame();[/i][/color] [color=999999][i] frame.setBounds(100, 100, 729, 354);[/i][/color] [color=999999][i] frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);[/i][/color] [color=999999][i][/i][/color] [color=999999][i] JButton btnSelect = new JButton("Select...");[/i][/color] [color=999999][i] btnSelect.addActionListener(new ActionListener() {[/i][/color] [color=999999][i] public void actionPerformed(ActionEvent e) {[/i][/color] [color=999999][i] JFileChooser fc = new JFileChooser();[/i][/color] [color=999999][i] fc.setCurrentDirectory(new File(textField.getText().equals("") ? "." : textField.getText()));[/i][/color] [color=999999][i] fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);[/i][/color] [color=999999][i] fc.setAcceptAllFileFilterUsed(false);[/i][/color] [color=999999][i] if (fc.showOpenDialog(frame) == JFileChooser.APPROVE_OPTION) {[/i][/color] [color=999999][i] textField.setText(fc.getSelectedFile().getAbsolutePath());[/i][/color] [color=999999][i] }[/i][/color] } }); textField [b]=[/b] new JTextField(); textField[b].[/b]setEditable([color=7777FF][b]false[/b][/color]); textField[b].[/b]setColumns([color=FFFF77]10[/color]); JLabel lblSource [b]=[/b] new JLabel([color=77FF77]"Source Folder"[/color]); textField_1 [b]=[/b] new JTextField(); textField_1[b].[/b]setEditable([color=7777FF][b]false[/b][/color]); textField_1[b].[/b]setColumns([color=FFFF77]10[/color]); JLabel lblDestinationFolder [b]=[/b] new JLabel([color=77FF77]"Destination Folder"[/color]); JButton button [b]=[/b] new JButton([color=77FF77]"Select..."[/color]); button[b].[/b]addActionListener(new ActionListener() [color=999999][i]{[/i][/color] [color=999999][i] public void actionPerformed(ActionEvent e) {[/i][/color] [color=999999][i] JFileChooser fc = new JFileChooser();[/i][/color] [color=999999][i] fc.setCurrentDirectory(new File(textField_1.getText().equals("") ? "." : textField_1.getText() ));[/i][/color] [color=999999][i] fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);[/i][/color] [color=999999][i] fc.setAcceptAllFileFilterUsed(false);[/i][/color] [color=999999][i] if (fc.showOpenDialog(frame) == JFileChooser.APPROVE_OPTION) {[/i][/color] [color=999999][i] textField_1.setText(fc.getSelectedFile().getAbsolutePath());[/i][/color] [color=999999][i] }[/i][/color] } }); JButton btnNewButton [b]=[/b] new JButton([color=77FF77]"Process"[/color]); btnNewButton[b].[/b]addActionListener(new ActionListener() [color=999999][i]{[/i][/color] [color=999999][i] public void actionPerformed(ActionEvent e) {[/i][/color] [color=999999][i] try{[/i][/color] [color=999999][i] File sourceFolder = new File(textField.getText());[/i][/color] [color=999999][i] File[] files = sourceFolder.listFiles();[/i][/color] [color=999999][i] for(File f : files){[/i][/color] [color=999999][i] String content = new String(Files.readAllBytes(f.toPath()));[/i][/color] [color=999999][i] int index = content.lastIndexOf(";$ZYKART_ENDE");[/i][/color] [color=999999][i] String before = content.substring(0, index);[/i][/color] [color=999999][i] String after = content.substring(index);[/i][/color] [color=999999][i] String res = before + ";$ZYKLUS_ENDE\r\n" + after;[/i][/color] [color=999999][i] FileOutputStream out = new FileOutputStream(new File(textField_1.getText() + "\\" + f.getName()));[/i][/color] [color=999999][i] out.write(res.getBytes());[/i][/color] [color=999999][i] out.close();[/i][/color] [color=999999][i] if(!textField_2.getText().equals("")){[/i][/color] [color=999999][i] out = new FileOutputStream(new File(textField_2.getText() + "\\" + f.getName()));[/i][/color] [color=999999][i] out.write(res.getBytes());[/i][/color] [color=999999][i] out.close();[/i][/color] [color=999999][i] }[/i][/color] f[b].[/b]delete(); } }catch(Exception ec)[color=999999][i]{[/i][/color] [color=999999][i] ec.printStackTrace();;[/i][/color] [color=999999][i] }[/i][/color] } }); JLabel lblDestinationFolder_1 [b]=[/b] new JLabel([color=77FF77]"Destination Folder 2"[/color]); textField_2 [b]=[/b] new JTextField(); textField_2[b].[/b]setEditable([color=7777FF][b]false[/b][/color]); textField_2[b].[/b]setColumns([color=FFFF77]10[/color]); JButton button_1 [b]=[/b] new JButton([color=77FF77]"Select..."[/color]); button_1[b].[/b]addActionListener(new ActionListener() [color=999999][i]{[/i][/color] [color=999999][i] public void actionPerformed(ActionEvent e) {[/i][/color] [color=999999][i] JFileChooser fc = new JFileChooser();[/i][/color] [color=999999][i] fc.setCurrentDirectory(new File(textField_2.getText().equals("") ? "." : textField_2.getText() ));[/i][/color] [color=999999][i] fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);[/i][/color] [color=999999][i] fc.setAcceptAllFileFilterUsed(false);[/i][/color] [color=999999][i] if (fc.showOpenDialog(frame) == JFileChooser.APPROVE_OPTION) {[/i][/color] [color=999999][i] textField_2.setText(fc.getSelectedFile().getAbsolutePath());[/i][/color] [color=999999][i] }[/i][/color] } }); GroupLayout groupLayout [b]=[/b] new GroupLayout(frame[b].[/b]getContentPane()); groupLayout[b].[/b]setHorizontalGroup( groupLayout[b].[/b]createParallelGroup(Alignment[b].[/b]TRAILING) [b].[/b]addGroup(groupLayout[b].[/b]createSequentialGroup() [b].[/b]addContainerGap() [b].[/b]addGroup(groupLayout[b].[/b]createParallelGroup(Alignment[b].[/b]LEADING) [b].[/b]addComponent(lblSource) [b].[/b]addComponent(btnNewButton[b],[/b] Alignment[b].[/b]TRAILING[b],[/b] GroupLayout[b].[/b]PREFERRED_SIZE[b],[/b] [color=FFFF77]143[/color][b],[/b] GroupLayout[b].[/b]PREFERRED_SIZE) [b].[/b]addGroup(Alignment[b].[/b]TRAILING[b],[/b] groupLayout[b].[/b]createSequentialGroup() [b].[/b]addGroup(groupLayout[b].[/b]createParallelGroup(Alignment[b].[/b]LEADING) [b].[/b]addComponent(textField_1[b],[/b] GroupLayout[b].[/b]DEFAULT_SIZE[b],[/b] [color=FFFF77]493[/color][b],[/b] Short[b].[/b]MAX_VALUE) [b].[/b]addComponent(textField[b],[/b] Alignment[b].[/b]TRAILING[b],[/b] GroupLayout[b].[/b]DEFAULT_SIZE[b],[/b] [color=FFFF77]493[/color][b],[/b] Short[b].[/b]MAX_VALUE)) [b].[/b]addPreferredGap(ComponentPlacement[b].[/b]RELATED) [b].[/b]addGroup(groupLayout[b].[/b]createParallelGroup(Alignment[b].[/b]LEADING[b],[/b] [color=7777FF][b]false[/b][/color]) [b].[/b]addComponent(btnSelect[b],[/b] GroupLayout[b].[/b]DEFAULT_SIZE[b],[/b] GroupLayout[b].[/b]DEFAULT_SIZE[b],[/b] Short[b].[/b]MAX_VALUE) [b].[/b]addComponent(button[b],[/b] GroupLayout[b].[/b]DEFAULT_SIZE[b],[/b] [color=FFFF77]101[/color][b],[/b] Short[b].[/b]MAX_VALUE))) [b].[/b]addGroup(Alignment[b].[/b]TRAILING[b],[/b] groupLayout[b].[/b]createSequentialGroup() [b].[/b]addComponent(textField_2[b],[/b] GroupLayout[b].[/b]DEFAULT_SIZE[b],[/b] [color=FFFF77]567[/color][b],[/b] Short[b].[/b]MAX_VALUE) [b].[/b]addPreferredGap(ComponentPlacement[b].[/b]RELATED) [b].[/b]addComponent(button_1[b],[/b] GroupLayout[b].[/b]PREFERRED_SIZE[b],[/b] [color=FFFF77]101[/color][b],[/b] GroupLayout[b].[/b]PREFERRED_SIZE)) [b].[/b]addComponent(lblDestinationFolder_1[b],[/b] GroupLayout[b].[/b]PREFERRED_SIZE[b],[/b] [color=FFFF77]182[/color][b],[/b] GroupLayout[b].[/b]PREFERRED_SIZE) [b].[/b]addComponent(lblDestinationFolder[b],[/b] GroupLayout[b].[/b]PREFERRED_SIZE[b],[/b] [color=FFFF77]182[/color][b],[/b] GroupLayout[b].[/b]PREFERRED_SIZE)) [b].[/b]addContainerGap()) ); groupLayout[b].[/b]setVerticalGroup( groupLayout[b].[/b]createParallelGroup(Alignment[b].[/b]LEADING) [b].[/b]addGroup(groupLayout[b].[/b]createSequentialGroup() [b].[/b]addContainerGap() [b].[/b]addComponent(lblSource) [b].[/b]addPreferredGap(ComponentPlacement[b].[/b]RELATED) [b].[/b]addGroup(groupLayout[b].[/b]createParallelGroup(Alignment[b].[/b]BASELINE) [b].[/b]addComponent(textField[b],[/b] GroupLayout[b].[/b]PREFERRED_SIZE[b],[/b] GroupLayout[b].[/b]DEFAULT_SIZE[b],[/b] GroupLayout[b].[/b]PREFERRED_SIZE) [b].[/b]addComponent(btnSelect)) [b].[/b]addPreferredGap(ComponentPlacement[b].[/b]RELATED) [b].[/b]addComponent(lblDestinationFolder) [b].[/b]addPreferredGap(ComponentPlacement[b].[/b]RELATED) [b].[/b]addGroup(groupLayout[b].[/b]createParallelGroup(Alignment[b].[/b]BASELINE) [b].[/b]addComponent(textField_1[b],[/b] GroupLayout[b].[/b]PREFERRED_SIZE[b],[/b] GroupLayout[b].[/b]DEFAULT_SIZE[b],[/b] GroupLayout[b].[/b]PREFERRED_SIZE) [b].[/b]addComponent(button)) [b].[/b]addPreferredGap(ComponentPlacement[b].[/b]RELATED) [b].[/b]addGroup(groupLayout[b].[/b]createParallelGroup(Alignment[b].[/b]TRAILING) [b].[/b]addGroup(groupLayout[b].[/b]createSequentialGroup() [b].[/b]addComponent(lblDestinationFolder_1) [b].[/b]addPreferredGap(ComponentPlacement[b].[/b]RELATED) [b].[/b]addComponent(textField_2[b],[/b] GroupLayout[b].[/b]PREFERRED_SIZE[b],[/b] GroupLayout[b].[/b]DEFAULT_SIZE[b],[/b] GroupLayout[b].[/b]PREFERRED_SIZE)) [b].[/b]addComponent(button_1)) [b].[/b]addPreferredGap(ComponentPlacement[b].[/b]RELATED[b],[/b] [color=FFFF77]38[/color][b],[/b] Short[b].[/b]MAX_VALUE) [b].[/b]addComponent(btnNewButton) [b].[/b]addContainerGap()) ); frame[b].[/b]getContentPane()[b].[/b]setLayout(groupLayout); } } [/code]
select language
jass
java
> delphi
C++
php
GSL
galaxy
visualBasic
wurst
Text
Markdown
select style
default
> bbcode - default
Jasscraft
jasscraft html
visual
lightweight
lightweightNr
goto line:
Compare with:
text copy window
edit this code
post new code
package systems.crigges.kamil; import java.awt.EventQueue; import javax.swing.JFrame; import javax.swing.GroupLayout; import javax.swing.GroupLayout.Alignment; import javax.swing.JButton; import javax.swing.JFileChooser; import javax.swing.JTextField; import javax.swing.LayoutStyle.ComponentPlacement; import javax.swing.UIManager; import javax.swing.UnsupportedLookAndFeelException; import javax.swing.JLabel; import javax.swing.JTextArea; import javax.swing.border.LineBorder; import javax.swing.plaf.FileChooserUI; import java.awt.Color; import java.awt.event.ActionListener; import java.io.File; import java.io.FileOutputStream; import java.nio.file.Files; import java.awt.event.ActionEvent; public class Kamil { private JFrame frame; private JTextField textField; private JTextField textField_1; private JTextField textField_2; /** * Launch the application. * @throws UnsupportedLookAndFeelException * @throws IllegalAccessException * @throws InstantiationException * @throws ClassNotFoundException */ public static void main(String[] args) throws ClassNotFoundException, InstantiationException, IllegalAccessException, UnsupportedLookAndFeelException { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); EventQueue.invokeLater(new Runnable() { public void run() { try { Kamil window = new Kamil(); window.frame.setVisible(true); } catch (Exception e) { e.printStackTrace(); } } }); } /** * Create the application. */ public Kamil() { initialize(); } /** * Initialize the contents of the frame. */ private void initialize() { frame = new JFrame(); frame.setBounds(100, 100, 729, 354); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JButton btnSelect = new JButton("Select..."); btnSelect.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { JFileChooser fc = new JFileChooser(); fc.setCurrentDirectory(new File(textField.getText().equals("") ? "." : textField.getText())); fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); fc.setAcceptAllFileFilterUsed(false); if (fc.showOpenDialog(frame) == JFileChooser.APPROVE_OPTION) { textField.setText(fc.getSelectedFile().getAbsolutePath()); } } }); textField = new JTextField(); textField.setEditable(false); textField.setColumns(10); JLabel lblSource = new JLabel("Source Folder"); textField_1 = new JTextField(); textField_1.setEditable(false); textField_1.setColumns(10); JLabel lblDestinationFolder = new JLabel("Destination Folder"); JButton button = new JButton("Select..."); button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { JFileChooser fc = new JFileChooser(); fc.setCurrentDirectory(new File(textField_1.getText().equals("") ? "." : textField_1.getText() )); fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); fc.setAcceptAllFileFilterUsed(false); if (fc.showOpenDialog(frame) == JFileChooser.APPROVE_OPTION) { textField_1.setText(fc.getSelectedFile().getAbsolutePath()); } } }); JButton btnNewButton = new JButton("Process"); btnNewButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { try{ File sourceFolder = new File(textField.getText()); File[] files = sourceFolder.listFiles(); for(File f : files){ String content = new String(Files.readAllBytes(f.toPath())); int index = content.lastIndexOf(";$ZYKART_ENDE"); String before = content.substring(0, index); String after = content.substring(index); String res = before + ";$ZYKLUS_ENDE\r\n" + after; FileOutputStream out = new FileOutputStream(new File(textField_1.getText() + "\\" + f.getName())); out.write(res.getBytes()); out.close(); if(!textField_2.getText().equals("")){ out = new FileOutputStream(new File(textField_2.getText() + "\\" + f.getName())); out.write(res.getBytes()); out.close(); } f.delete(); } }catch(Exception ec){ ec.printStackTrace();; } } }); JLabel lblDestinationFolder_1 = new JLabel("Destination Folder 2"); textField_2 = new JTextField(); textField_2.setEditable(false); textField_2.setColumns(10); JButton button_1 = new JButton("Select..."); button_1.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { JFileChooser fc = new JFileChooser(); fc.setCurrentDirectory(new File(textField_2.getText().equals("") ? "." : textField_2.getText() )); fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); fc.setAcceptAllFileFilterUsed(false); if (fc.showOpenDialog(frame) == JFileChooser.APPROVE_OPTION) { textField_2.setText(fc.getSelectedFile().getAbsolutePath()); } } }); GroupLayout groupLayout = new GroupLayout(frame.getContentPane()); groupLayout.setHorizontalGroup( groupLayout.createParallelGroup(Alignment.TRAILING) .addGroup(groupLayout.createSequentialGroup() .addContainerGap() .addGroup(groupLayout.createParallelGroup(Alignment.LEADING) .addComponent(lblSource) .addComponent(btnNewButton, Alignment.TRAILING, GroupLayout.PREFERRED_SIZE, 143, GroupLayout.PREFERRED_SIZE) .addGroup(Alignment.TRAILING, groupLayout.createSequentialGroup() .addGroup(groupLayout.createParallelGroup(Alignment.LEADING) .addComponent(textField_1, GroupLayout.DEFAULT_SIZE, 493, Short.MAX_VALUE) .addComponent(textField, Alignment.TRAILING, GroupLayout.DEFAULT_SIZE, 493, Short.MAX_VALUE)) .addPreferredGap(ComponentPlacement.RELATED) .addGroup(groupLayout.createParallelGroup(Alignment.LEADING, false) .addComponent(btnSelect, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(button, GroupLayout.DEFAULT_SIZE, 101, Short.MAX_VALUE))) .addGroup(Alignment.TRAILING, groupLayout.createSequentialGroup() .addComponent(textField_2, GroupLayout.DEFAULT_SIZE, 567, Short.MAX_VALUE) .addPreferredGap(ComponentPlacement.RELATED) .addComponent(button_1, GroupLayout.PREFERRED_SIZE, 101, GroupLayout.PREFERRED_SIZE)) .addComponent(lblDestinationFolder_1, GroupLayout.PREFERRED_SIZE, 182, GroupLayout.PREFERRED_SIZE) .addComponent(lblDestinationFolder, GroupLayout.PREFERRED_SIZE, 182, GroupLayout.PREFERRED_SIZE)) .addContainerGap()) ); groupLayout.setVerticalGroup( groupLayout.createParallelGroup(Alignment.LEADING) .addGroup(groupLayout.createSequentialGroup() .addContainerGap() .addComponent(lblSource) .addPreferredGap(ComponentPlacement.RELATED) .addGroup(groupLayout.createParallelGroup(Alignment.BASELINE) .addComponent(textField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) .addComponent(btnSelect)) .addPreferredGap(ComponentPlacement.RELATED) .addComponent(lblDestinationFolder) .addPreferredGap(ComponentPlacement.RELATED) .addGroup(groupLayout.createParallelGroup(Alignment.BASELINE) .addComponent(textField_1, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) .addComponent(button)) .addPreferredGap(ComponentPlacement.RELATED) .addGroup(groupLayout.createParallelGroup(Alignment.TRAILING) .addGroup(groupLayout.createSequentialGroup() .addComponent(lblDestinationFolder_1) .addPreferredGap(ComponentPlacement.RELATED) .addComponent(textField_2, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)) .addComponent(button_1)) .addPreferredGap(ComponentPlacement.RELATED, 38, Short.MAX_VALUE) .addComponent(btnNewButton) .addContainerGap()) ); frame.getContentPane().setLayout(groupLayout); } }