samples/exceptions/src/org/apidesign/exceptions/trycatchredo/SaveAction.java
author Jaroslav Tulach <jtulach@netbeans.org>
Wed, 28 Jan 2009 08:06:41 +0100
changeset 307 52f941f090cd
permissions -rw-r--r--
Initial attempt to provide sample for trycatchredo
     1 package org.apidesign.exceptions.trycatchredo;
     2 
     3 import java.awt.EventQueue;
     4 import java.awt.event.ActionEvent;
     5 import java.io.IOException;
     6 import java.io.OutputStream;
     7 import java.net.URL;
     8 import javax.swing.AbstractAction;
     9 import javax.swing.JOptionPane;
    10 
    11 /**
    12  *
    13  * @author Jaroslav Tulach
    14  */
    15 final class SaveAction extends AbstractAction {
    16     private final URL where;
    17     private final CharSequence what;
    18     
    19     SaveAction(URL where, CharSequence what) {
    20         this.where = where;
    21         this.what = what;
    22     }
    23     
    24     
    25     public void actionPerformed(ActionEvent ev) {
    26         assert EventQueue.isDispatchThread();
    27         try {
    28             OutputStream os = where.openConnection().getOutputStream();
    29             os.write(what.toString().getBytes());
    30             os.close();
    31         } catch (IOException ex) {
    32             JOptionPane.showMessageDialog(null, ex);
    33         }
    34     }
    35 }