Browse Source

Merge branch 'JSrollBar' into 'main'

J sroll bar

See merge request fdai7332/java-chat!15
remotes/origin/hotfix/client/improve-chat-window-appearence
fdai7579 11 months ago
parent
commit
b120ad3b2e
  1. 15
      src/main/java/Notizbuch.java

15
src/main/java/Notizbuch.java

@ -21,11 +21,13 @@ public class Notizbuch extends JFrame implements ActionListener {
setTextArea(new JTextArea());
add(new JScrollPane(getTextArea()), BorderLayout.CENTER);
// Erstellen der Speichern- und Laden-Buttons
saveButton = new JButton("Speichern");
saveButton.addActionListener(this);
loadButton = new JButton("Laden");
loadButton.addActionListener(this);
// Erstellen eines Panels für die Buttons und Hinzufügen der Buttons
JPanel buttonPanel = new JPanel();
buttonPanel.add(saveButton);
buttonPanel.add(loadButton);
@ -35,6 +37,7 @@ public class Notizbuch extends JFrame implements ActionListener {
@Override
public void actionPerformed(ActionEvent e) {
// ActionListener-Methode für Button-Events
if (e.getSource() == saveButton) {
saveNote();
} else if (e.getSource() == loadButton) {
@ -42,7 +45,7 @@ public class Notizbuch extends JFrame implements ActionListener {
}
}
// Methode zum Speichern von Notizen
public void saveNote() {
try (PrintWriter writer = new PrintWriter(new FileWriter("notizen.txt"))) {
writer.print(getTextArea().getText());
@ -51,27 +54,27 @@ public class Notizbuch extends JFrame implements ActionListener {
JOptionPane.showMessageDialog(this, "Fehler beim Speichern der Notiz: " + e.getMessage());
}
}
// Methode zum Laden von Notizen
public 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");
noteText.append(line).append("\n"); // Zeilen aus der Datei lesen und StringBuilder hinzufügen
}
getTextArea().setText(noteText.toString());
} catch (IOException e) {
JOptionPane.showMessageDialog(this, "Fehler beim Laden der Notiz: " + e.getMessage());
}
}
// Hauptmethode zum Starten des Programms
public static void main(String[] args) {
SwingUtilities.invokeLater(() -> {
Notizbuch notizbuch = new Notizbuch();
notizbuch.setVisible(true);
notizbuch.setVisible(true); // Das Notizbuch-Fenster anzeigen
});
}
// Getter und Setter für die TextArea
public JTextArea getTextArea() {
return textArea;
}

Loading…
Cancel
Save