samples/trycatchredo/src/org/apidesign/exceptions/trycatchredo/api/SaveAction.java
author Jaroslav Tulach <jtulach@netbeans.org>
Sun, 01 Feb 2009 16:29:46 +0100
changeset 312 0678c9589013
child 314 03a451fc2256
permissions -rw-r--r--
Renaming the project to 'Try Catch Redo'
     1 package org.apidesign.exceptions.trycatchredo.api;
     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 }