KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > wingset > OptionPaneExample


1 /*
2  * $Id: OptionPaneExample.java,v 1.7 2005/01/11 17:41:18 hengels Exp $
3  * Copyright 2000,2005 wingS development team.
4  *
5  * This file is part of wingS (http://www.j-wings.org).
6  *
7  * wingS is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU Lesser General Public License
9  * as published by the Free Software Foundation; either version 2.1
10  * of the License, or (at your option) any later version.
11  *
12  * Please see COPYING for the complete licence.
13  */

14 package wingset;
15
16 import org.wings.*;
17
18 import java.awt.event.ActionEvent JavaDoc;
19 import java.awt.event.ActionListener JavaDoc;
20
21 /**
22  * @author <a HREF="mailto:haaf@mercatis.de">Armin Haaf</a>
23  * @version $Revision: 1.7 $
24  */

25 public class OptionPaneExample
26         extends WingSetPane
27 {
28     protected SComponent createExample() {
29         SToolbar toolbar = new SToolbar();
30
31         SButton msg = new SButton("show Message");
32         msg.addActionListener(new ActionListener JavaDoc() {
33             public void actionPerformed(ActionEvent JavaDoc e) {
34                 SOptionPane.showMessageDialog(null, "This is a simple message", "A Message");
35             }
36         });
37         toolbar.add(msg);
38
39         SButton question = new SButton("show Question");
40         final ActionListener JavaDoc comment = new ActionListener JavaDoc() {
41             public void actionPerformed(ActionEvent JavaDoc e) {
42                 if (e.getActionCommand() == SOptionPane.OK_ACTION)
43                     SOptionPane.showMessageDialog(null, "Fine !");
44                 else
45                     SOptionPane.showMessageDialog(null, "No Problem, just look at another site");
46             }
47         };
48
49         question.addActionListener(new ActionListener JavaDoc() {
50             public void actionPerformed(ActionEvent JavaDoc e) {
51                 SOptionPane.showQuestionDialog(null, "Continue this example?",
52                         "A Question", comment);
53             }
54         });
55         toolbar.add(question);
56
57         SButton yesno = new SButton("show Yes No");
58         final ActionListener JavaDoc feedback = new ActionListener JavaDoc() {
59             public void actionPerformed(ActionEvent JavaDoc e) {
60                 if (e.getActionCommand() == SOptionPane.NO_ACTION) {
61                     SPanel p = new SPanel(new SFlowDownLayout());
62                     p.add(new SLabel("That's sad!"));
63                     SAnchor sendMail = new SAnchor("mailto:haaf@mercatis.de");
64                     sendMail.add(new SLabel("Please send my why!"));
65                     p.add(sendMail);
66                     SOptionPane.showMessageDialog(null, p);
67                 } else
68                     SOptionPane.showMessageDialog(null, "Fine, so do we!");
69             }
70         };
71
72         yesno.addActionListener(new ActionListener JavaDoc() {
73             public void actionPerformed(ActionEvent JavaDoc e) {
74                 SOptionPane.showYesNoDialog(null,
75                         "Do you like wingS",
76                         "A Yes No Question", feedback);
77             }
78         });
79
80         toolbar.add(yesno);
81
82         final SLabel label = new SLabel();
83         final ActionListener JavaDoc inputListener = new ActionListener JavaDoc() {
84             public void actionPerformed(ActionEvent JavaDoc e) {
85                 SOptionPane optionPane = (SOptionPane) e.getSource();
86                 STextField inputValue = (STextField) optionPane.getInputValue();
87                 label.setText("" + inputValue.getText());
88             }
89         };
90
91         SButton input = new SButton("show Input");
92         input.addActionListener(new ActionListener JavaDoc() {
93             public void actionPerformed(ActionEvent JavaDoc e) {
94                 SOptionPane.showInputDialog(null, "What's your profession?", "A Message", new STextField(), inputListener);
95             }
96         });
97         toolbar.add(input);
98         toolbar.add(label);
99
100         SForm c = new SForm(new SBorderLayout());
101         c.add(toolbar, SBorderLayout.NORTH);
102         return c;
103     }
104 }
105
Popular Tags