Browse Source

Zeilensortierung

remotes/origin/server
Marc Dimmerling 11 months ago
parent
commit
ad1a16fe26
  1. 45
      src/main/java/Notizbuch.java

45
src/main/java/Notizbuch.java

@ -6,12 +6,6 @@ import java.awt.event.*;
import java.io.*;
import javax.swing.JFrame;
public class Notizbuch extends JFrame implements ActionListener {
private JTextArea textArea;
@ -34,39 +28,40 @@ public class Notizbuch extends JFrame implements ActionListener {
JPanel buttonPanel = new JPanel();
buttonPanel.add(saveButton);
buttonPanel.add(loadButton);
buttonPanel.add(loadButton);
add(buttonPanel, BorderLayout.SOUTH);
add(buttonPanel, BorderLayout.SOUTH);
}
@Override
public void actionPerformed(ActionEvent e) {
if (e.getSource() == saveButton) {
saveNote();
} else if (e.getSource() == loadButton) {
loadNote();
}
saveNote();
} else if (e.getSource() == loadButton) {
loadNote();
}
}
private void saveNote() {
try (PrintWriter writer = new PrintWriter(new FileWriter("notizen.txt"))) {
writer.print(textArea.getText());
JOptionPane.showMessageDialog(this, "Notiz erfolgreich gespeichert!");
} catch (IOException e) {
JOptionPane.showMessageDialog(this, "Fehler beim Speichern der Notiz: " + e.getMessage());
}
writer.print(textArea.getText());
JOptionPane.showMessageDialog(this, "Notiz erfolgreich gespeichert!");
} catch (IOException e) {
JOptionPane.showMessageDialog(this, "Fehler beim Speichern der Notiz: " + e.getMessage());
}
}
private void loadNote() {
try (BufferedReader reader = new BufferedReader(new FileReader("notizen.txt"))) {
StringBuilder noteText = new StringBuilder();
String line;
while ((line = reader.readLine()) != null) {
noteText.append(line).append("\n");
}
textArea.setText(noteText.toString());
} catch (IOException e) {
JOptionPane.showMessageDialog(this, "Fehler beim Laden der Notiz: " + e.getMessage());
}
String line;
while ((line = reader.readLine()) != null) {
noteText.append(line).append("\n");
}
textArea.setText(noteText.toString());
} catch (IOException e) {
JOptionPane.showMessageDialog(this, "Fehler beim Laden der Notiz: " + e.getMessage());
}
}
}
Loading…
Cancel
Save