samples/trycatchredo/src/org/apidesign/exceptions/trycatchredo/api/SaveAction.java
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/samples/trycatchredo/src/org/apidesign/exceptions/trycatchredo/api/SaveAction.java Sun Feb 01 16:29:46 2009 +0100
1.3 @@ -0,0 +1,35 @@
1.4 +package org.apidesign.exceptions.trycatchredo.api;
1.5 +
1.6 +import java.awt.EventQueue;
1.7 +import java.awt.event.ActionEvent;
1.8 +import java.io.IOException;
1.9 +import java.io.OutputStream;
1.10 +import java.net.URL;
1.11 +import javax.swing.AbstractAction;
1.12 +import javax.swing.JOptionPane;
1.13 +
1.14 +/**
1.15 + *
1.16 + * @author Jaroslav Tulach
1.17 + */
1.18 +final class SaveAction extends AbstractAction {
1.19 + private final URL where;
1.20 + private final CharSequence what;
1.21 +
1.22 + SaveAction(URL where, CharSequence what) {
1.23 + this.where = where;
1.24 + this.what = what;
1.25 + }
1.26 +
1.27 +
1.28 + public void actionPerformed(ActionEvent ev) {
1.29 + assert EventQueue.isDispatchThread();
1.30 + try {
1.31 + OutputStream os = where.openConnection().getOutputStream();
1.32 + os.write(what.toString().getBytes());
1.33 + os.close();
1.34 + } catch (IOException ex) {
1.35 + JOptionPane.showMessageDialog(null, ex);
1.36 + }
1.37 + }
1.38 +}