|
|
@ -8,7 +8,7 @@ import javax.swing.JFrame; |
|
|
|
|
|
|
|
public class Notizbuch extends JFrame implements ActionListener { |
|
|
|
|
|
|
|
private JTextArea textArea; |
|
|
|
JTextArea textArea; |
|
|
|
private JButton saveButton; |
|
|
|
private JButton loadButton; |
|
|
|
|
|
|
@ -18,8 +18,8 @@ public class Notizbuch extends JFrame implements ActionListener { |
|
|
|
setDefaultCloseOperation(EXIT_ON_CLOSE); |
|
|
|
setLayout(new BorderLayout()); |
|
|
|
|
|
|
|
textArea = new JTextArea(); |
|
|
|
add(new JScrollPane(textArea), BorderLayout.CENTER); |
|
|
|
setTextArea(new JTextArea()); |
|
|
|
add(new JScrollPane(getTextArea()), BorderLayout.CENTER); |
|
|
|
|
|
|
|
saveButton = new JButton("Speichern"); |
|
|
|
saveButton.addActionListener(this); |
|
|
@ -43,23 +43,23 @@ public class Notizbuch extends JFrame implements ActionListener { |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
private void saveNote() { |
|
|
|
public void saveNote() { |
|
|
|
try (PrintWriter writer = new PrintWriter(new FileWriter("notizen.txt"))) { |
|
|
|
writer.print(textArea.getText()); |
|
|
|
writer.print(getTextArea().getText()); |
|
|
|
JOptionPane.showMessageDialog(this, "Notiz erfolgreich gespeichert!"); |
|
|
|
} catch (IOException e) { |
|
|
|
JOptionPane.showMessageDialog(this, "Fehler beim Speichern der Notiz: " + e.getMessage()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private void loadNote() { |
|
|
|
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"); |
|
|
|
} |
|
|
|
textArea.setText(noteText.toString()); |
|
|
|
getTextArea().setText(noteText.toString()); |
|
|
|
} catch (IOException e) { |
|
|
|
JOptionPane.showMessageDialog(this, "Fehler beim Laden der Notiz: " + e.getMessage()); |
|
|
|
} |
|
|
@ -71,4 +71,12 @@ public class Notizbuch extends JFrame implements ActionListener { |
|
|
|
notizbuch.setVisible(true); |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
public JTextArea getTextArea() { |
|
|
|
return textArea; |
|
|
|
} |
|
|
|
|
|
|
|
public void setTextArea(JTextArea textArea) { |
|
|
|
this.textArea = textArea; |
|
|
|
} |
|
|
|
} |