1 35 36 39 package demo.swingset; 40 41 import swingwtx.swing.*; 42 import swingwtx.swing.event.*; 43 import swingwtx.swing.text.*; 44 import swingwtx.swing.border.*; 45 import swingwtx.swing.colorchooser.*; 46 import swingwtx.swing.filechooser.*; 47 import javax.accessibility.*; 48 49 import swingwt.awt.*; 50 import swingwt.awt.event.*; 51 import java.beans.*; 52 import java.util.*; 53 import java.io.*; 54 import java.applet.*; 55 import java.net.*; 56 57 63 public class OptionPaneDemo extends DemoModule { 64 65 68 public static void main(String [] args) { 69 OptionPaneDemo demo = new OptionPaneDemo(null); 70 demo.mainImpl(); 71 } 72 73 76 public OptionPaneDemo(SwingSet2 swingset) { 77 super(swingset, "OptionPaneDemo", "toolbar/JOptionPane.gif"); 80 81 JPanel demo = getDemoPanel(); 82 83 demo.setLayout(new BoxLayout(demo, BoxLayout.X_AXIS)); 84 85 JPanel bp = new JPanel() { 86 public Dimension getMaximumSize() { 87 return new Dimension(getPreferredSize().width, super.getMaximumSize().height); 88 } 89 }; 90 bp.setLayout(new BoxLayout(bp, BoxLayout.Y_AXIS)); 91 92 bp.add(Box.createRigidArea(VGAP30)); 93 bp.add(Box.createRigidArea(VGAP30)); 94 95 bp.add(createInputDialogButton()); bp.add(Box.createRigidArea(VGAP15)); 96 bp.add(createWarningDialogButton()); bp.add(Box.createRigidArea(VGAP15)); 97 bp.add(createMessageDialogButton()); bp.add(Box.createRigidArea(VGAP15)); 98 bp.add(createComponentDialogButton()); bp.add(Box.createRigidArea(VGAP15)); 99 bp.add(createConfirmDialogButton()); bp.add(Box.createVerticalGlue()); 100 101 demo.add(Box.createHorizontalGlue()); 102 demo.add(bp); 103 demo.add(Box.createHorizontalGlue()); 104 } 105 106 public JButton createWarningDialogButton() { 107 Action a = new AbstractAction(getString("OptionPaneDemo.warningbutton")) { 108 public void actionPerformed(ActionEvent e) { 109 JOptionPane.showMessageDialog( 110 getDemoPanel(), 111 getString("OptionPaneDemo.warningtext"), 112 getString("OptionPaneDemo.warningtitle"), 113 JOptionPane.WARNING_MESSAGE 114 ); 115 } 116 }; 117 return createButton(a); 118 } 119 120 public JButton createMessageDialogButton() { 121 Action a = new AbstractAction(getString("OptionPaneDemo.messagebutton")) { 122 URL img = getClass().getResource("/resources/images/optionpane/bottle.gif"); 123 String imagesrc = "<img SRC=\"" + img + "\" width=\"284\" height=\"100\">"; 124 String message = getString("OptionPaneDemo.messagetext"); 125 public void actionPerformed(ActionEvent e) { 126 JOptionPane.showMessageDialog( 127 getDemoPanel(), 128 "<html>" + imagesrc + "<br><center>" + message + "</center><br></html>" 129 ); 130 } 131 }; 132 return createButton(a); 133 } 134 135 public JButton createConfirmDialogButton() { 136 Action a = new AbstractAction(getString("OptionPaneDemo.confirmbutton")) { 137 public void actionPerformed(ActionEvent e) { 138 int result = JOptionPane.showConfirmDialog(getDemoPanel(), getString("OptionPaneDemo.confirmquestion")); 139 if(result == JOptionPane.YES_OPTION) { 140 JOptionPane.showMessageDialog(getDemoPanel(), getString("OptionPaneDemo.confirmyes")); 141 } else if(result == JOptionPane.NO_OPTION) { 142 JOptionPane.showMessageDialog(getDemoPanel(), getString("OptionPaneDemo.confirmno")); 143 } 144 } 145 }; 146 return createButton(a); 147 } 148 149 public JButton createInputDialogButton() { 150 Action a = new AbstractAction(getString("OptionPaneDemo.inputbutton")) { 151 public void actionPerformed(ActionEvent e) { 152 String result = JOptionPane.showInputDialog(getDemoPanel(), getString("OptionPaneDemo.inputquestion")); 153 JOptionPane.showMessageDialog(getDemoPanel(), getString("OptionPaneDemo.inputresponse")); 154 } 155 }; 156 return createButton(a); 157 } 158 159 public JButton createComponentDialogButton() { 160 Action a = new AbstractAction(getString("OptionPaneDemo.componentbutton")) { 161 public void actionPerformed(ActionEvent e) { 162 165 Object [] message = new Object [4]; 167 message[0] = getString("OptionPaneDemo.componentmessage"); 168 message[1] = new JTextField(getString("OptionPaneDemo.componenttextfield")); 169 170 JComboBox cb = new JComboBox(); 171 cb.addItem(getString("OptionPaneDemo.component_cb1")); 172 cb.addItem(getString("OptionPaneDemo.component_cb2")); 173 cb.addItem(getString("OptionPaneDemo.component_cb3")); 174 message[2] = cb; 175 176 message[3] = getString("OptionPaneDemo.componentmessage2"); 177 178 String [] options = { 180 getString("OptionPaneDemo.component_op1"), 181 getString("OptionPaneDemo.component_op2"), 182 getString("OptionPaneDemo.component_op3"), 183 getString("OptionPaneDemo.component_op4"), 184 getString("OptionPaneDemo.component_op5") 185 }; 186 int result = JOptionPane.showOptionDialog( 187 getDemoPanel(), message[3], getString("OptionPaneDemo.componenttitle"), JOptionPane.DEFAULT_OPTION, JOptionPane.INFORMATION_MESSAGE, null, options, options[3] ); 196 switch(result) { 197 case 0: JOptionPane.showMessageDialog(getDemoPanel(), getString("OptionPaneDemo.component_r1")); 199 break; 200 case 1: JOptionPane.showMessageDialog(getDemoPanel(), getString("OptionPaneDemo.component_r2")); 202 break; 203 case 2: JOptionPane.showMessageDialog(getDemoPanel(), getString("OptionPaneDemo.component_r3")); 205 break; 206 case 3: JOptionPane.showMessageDialog(getDemoPanel(), getString("OptionPaneDemo.component_r4")); 208 break; 209 default: 210 break; 211 } 212 213 } 214 }; 215 return createButton(a); 216 } 217 218 public JButton createButton(Action a) { 219 JButton b = new JButton() { 220 public Dimension getMaximumSize() { 221 int width = Short.MAX_VALUE; 222 int height = super.getMaximumSize().height; 223 return new Dimension(width, height); 224 } 225 }; 226 b.putClientProperty("displayActionText", Boolean.TRUE); 230 b.setAction(a); 231 return b; 233 } 234 235 } 236 | Popular Tags |