samples/exceptions/src/org/apidesign/exceptions/trycatchredo/SaveActionWithQuery.java
1 package org.apidesign.exceptions.trycatchredo;
3 import java.awt.EventQueue;
4 import java.awt.event.ActionEvent;
5 import java.io.IOException;
6 import java.io.OutputStream;
8 import javax.swing.AbstractAction;
9 import javax.swing.JDialog;
10 import javax.swing.JOptionPane;
14 * @author Jaroslav Tulach
16 final class SaveActionWithQuery extends AbstractAction {
17 private final URL where;
18 private final CharSequence what;
20 SaveActionWithQuery(URL where, CharSequence what) {
26 public void actionPerformed(ActionEvent ev) {
27 assert EventQueue.isDispatchThread();
30 OutputStream os = where.openConnection().getOutputStream();
31 os.write(what.toString().getBytes());
33 } catch (UserQuestionException ex) {
34 JOptionPane p = ex.getQuestionPane();
35 JDialog d = p.createDialog(ex.getLocalizedMessage());
37 ex.confirm(p.getValue());
39 !p.getValue().equals(JOptionPane.CANCEL_OPTION) &&
40 !p.getValue().equals(JOptionPane.CLOSED_OPTION)
44 } catch (IOException ex) {
45 JOptionPane.showMessageDialog(null, ex);