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
jtulach@307
     1
package org.apidesign.exceptions.trycatchredo;
jtulach@307
     2
jtulach@307
     3
import java.awt.EventQueue;
jtulach@307
     4
import java.awt.event.ActionEvent;
jtulach@307
     5
import java.io.IOException;
jtulach@307
     6
import java.io.OutputStream;
jtulach@307
     7
import java.net.URL;
jtulach@307
     8
import javax.swing.AbstractAction;
jtulach@307
     9
import javax.swing.JOptionPane;
jtulach@307
    10
jtulach@307
    11
/**
jtulach@307
    12
 *
jtulach@307
    13
 * @author Jaroslav Tulach
jtulach@307
    14
 */
jtulach@307
    15
final class SaveAction extends AbstractAction {
jtulach@307
    16
    private final URL where;
jtulach@307
    17
    private final CharSequence what;
jtulach@307
    18
    
jtulach@307
    19
    SaveAction(URL where, CharSequence what) {
jtulach@307
    20
        this.where = where;
jtulach@307
    21
        this.what = what;
jtulach@307
    22
    }
jtulach@307
    23
    
jtulach@307
    24
    
jtulach@307
    25
    public void actionPerformed(ActionEvent ev) {
jtulach@307
    26
        assert EventQueue.isDispatchThread();
jtulach@307
    27
        try {
jtulach@307
    28
            OutputStream os = where.openConnection().getOutputStream();
jtulach@307
    29
            os.write(what.toString().getBytes());
jtulach@307
    30
            os.close();
jtulach@307
    31
        } catch (IOException ex) {
jtulach@307
    32
            JOptionPane.showMessageDialog(null, ex);
jtulach@307
    33
        }
jtulach@307
    34
    }
jtulach@307
    35
}