1 14 package wingset; 15 16 import org.wings.*; 17 18 import java.awt.event.ActionEvent ; 19 import java.awt.event.ActionListener ; 20 21 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 () { 33 public void actionPerformed(ActionEvent 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 comment = new ActionListener () { 41 public void actionPerformed(ActionEvent 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 () { 50 public void actionPerformed(ActionEvent 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 feedback = new ActionListener () { 59 public void actionPerformed(ActionEvent 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 () { 73 public void actionPerformed(ActionEvent 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 inputListener = new ActionListener () { 84 public void actionPerformed(ActionEvent 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 () { 93 public void actionPerformed(ActionEvent 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 |