import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.*;
import java.util.Locale;
public class Main extends JFrame implements ActionListener {
private JPanel mainpanel;
private JScrollPane scrollPane;
private JTextArea textReader;
private JButton buttonReader;
private JButton buttonSaver;
private JButton resetButton;
private JButton textmanipulationButton;
private String text;
private String filesave;
public static void main(String[] args) {
new Main();
}
Main(){
this.setContentPane(mainpanel);
scrollPane.setViewportView(textReader);
buttonReader.setFocusable(false);
buttonReader.addActionListener(this);
textmanipulationButton.setFocusable(false);
textmanipulationButton.addActionListener(this);
buttonSaver.setFocusable(false);
buttonSaver.addActionListener(this);
resetButton.setFocusable(false);
resetButton.addActionListener(this);
this.setBounds(650,200,600,600);
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
this.setVisible(true);
}
@Override
public void actionPerformed(ActionEvent e) {
if(e.getSource() == buttonReader) {
JFileChooser chooser = new JFileChooser();
chooser.showOpenDialog(null);
File file = chooser.getSelectedFile();
filesave = file.getAbsolutePath();
try {
BufferedReader br = new BufferedReader(new FileReader(file));
textReader.read(br, null);
textReader.append("\n");
br.close();
}
catch (Exception exception) {
JOptionPane.showMessageDialog(null, exception);
}
}
if(e.getSource() == textmanipulationButton) {
text = textReader.getText();
text = text.replaceAll("[ö,Ö]","oe");
text = text.replaceAll("[ü,Ü]","ue");
text = text.replaceAll("[ä,Ä]","ae");
text = text.replaceAll("ß","ss");
text = text.replaceAll(" ","");
text = text.replaceAll("[^A-Z,a-z]","");
text = text.toUpperCase(Locale.ROOT);
textReader.append(text+"\n");
char [][] matrix = new char[5][5];
int length = text.length();
for(int y = 0; y < 5; y++) {
for(int x = 0; x < 5; x++)
{
int Index = x + y*5;
matrix[x][y] = text.charAt(Index);
System.out.print(matrix[x][y] + " ");
};
System.out.print("\n");
}
}
if(e.getSource() == buttonSaver){
try{
BufferedWriter bw = new BufferedWriter(new FileWriter(filesave));
text = textReader.getText();
bw.write(textReader.getText());
bw.close();
JOptionPane.showMessageDialog(null, "File successful saved");
} catch (Exception ex) {
JOptionPane.showMessageDialog(null, ex);
}
}
if(e.getSource() == resetButton){
textReader.setText("");
filesave = "";
}
}
}