samples/trycatchredo/src/org/apidesign/exceptions/trycatchredo/api/SaveAction.java
author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
Thu, 30 Oct 2014 21:30:10 +0100
changeset 409 40cabcdcd2be
parent 312 0678c9589013
permissions -rw-r--r--
Updating to NBMs from NetBeans 8.0.1 as some of them are required to run on JDK8
     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         // BEGIN: trycatchredo.SaveAction
    28         try {
    29             OutputStream os = where.openConnection().getOutputStream();
    30             os.write(what.toString().getBytes());
    31             os.close();
    32         } catch (IOException ex) {
    33             JOptionPane.showMessageDialog(null, ex);
    34         }
    35         // END: trycatchredo.SaveAction
    36     }
    37 }