import java.awt.*; 
import java.awt.event.*; 
import java.io.*; 

public class MyApplication extends Frame implements ActionListener, WindowListener 
{ 
  static MyApplication myapp; 
  static Label label; 
  static TextArea text; 
  static Button save; 

  public static void main(String[] args) 
  { 
    myapp = new MyApplication(); 
    myapp.setLayout(new BorderLayout()); 
    myapp.setSize(500, 400); 
    label = new Label(); 
    myapp.add(label, BorderLayout.NORTH); 
    text = new TextArea(); 
    myapp.add(text, BorderLayout.CENTER); 
    save = new Button("Text speichern"); 
    save.addActionListener(myapp); 
    myapp.add(save, BorderLayout.SOUTH); 
    myapp.addWindowListener(myapp); 
    myapp.setVisible(true); 
  } 

  public void actionPerformed(ActionEvent ev) 
  { 
    try 
    { 
      FileWriter file = new FileWriter("brief.txt"); 
      String message = text.getText(); 
      file.write(message, 0, message.length()); 
      file.close(); 
      label.setText("Datei wurde erfolgreich gespeichert."); 
    } 
    catch (IOException ex) 
    { 
      label.setText("Fehler: " + ex.getMessage()); 
    } 
  } 

  public void windowClosing(WindowEvent ev) 
  { 
    myapp.setVisible(false); 
    myapp.dispose(); 
    System.exit(1); 
  } 

  public void windowActivated(WindowEvent ev) { } 
  public void windowClosed(WindowEvent ev) { } 
  public void windowDeactivated(WindowEvent ev) { } 
  public void windowDeiconified(WindowEvent ev) { } 
  public void windowIconified(WindowEvent ev) { } 
  public void windowOpened(WindowEvent ev) { } 
} 