1 24 package dotcom; 25 26 import javax.swing.* ; 27 import java.awt.* ; 28 import java.awt.event.* ; 29 30 43 class GUI { 44 45 Servers server ; 47 48 JFrame mainWindow ; 50 JPanel mainPane ; 51 JPanel topPane ; 52 JPanel middlePane ; 53 JPanel bottomPane ; 54 55 JLabel idLabel1 ; 56 JLabel idLabel2 ; 57 JLabel itemLabel1 ; 58 JLabel itemLabel2 ; 59 JLabel infoLabel ; 60 61 JRadioButton shoesButton ; 63 JRadioButton socksButton ; 64 JRadioButton trousersButton ; 65 JRadioButton shirtButton ; 66 JRadioButton hatButton ; 67 ButtonGroup buttonGroup ; 68 69 JButton otherButton ; 71 JButton sendButton ; 72 JButton cancelButton ; 73 JButton quitButton ; 74 JButton okButton ; 75 JButton noButton ; 76 JButton closeButton ; 77 78 86 GUI(String title, Servers ser, int x, int y) { 87 88 this.server = ser ; 89 90 idLabel1 = new JLabel("Order number: ", SwingConstants.CENTER) ; 92 idLabel2 = new JLabel("1", SwingConstants.CENTER) ; 93 94 shoesButton = new JRadioButton("Shoes") ; 95 shoesButton.setMnemonic(KeyEvent.VK_1) ; 96 shoesButton.setActionCommand("Shoes") ; 97 shoesButton.setSelected(true) ; 98 socksButton = new JRadioButton("Socks") ; 99 socksButton.setMnemonic(KeyEvent.VK_2) ; 100 socksButton.setActionCommand("Socks") ; 101 trousersButton = new JRadioButton("Trousers") ; 102 trousersButton.setMnemonic(KeyEvent.VK_3) ; 103 trousersButton.setActionCommand("Trousers") ; 104 shirtButton = new JRadioButton("Shirt") ; 105 shirtButton.setMnemonic(KeyEvent.VK_4) ; 106 shirtButton.setActionCommand("Shirt") ; 107 hatButton = new JRadioButton("Hat") ; 108 hatButton.setMnemonic(KeyEvent.VK_5) ; 109 hatButton.setActionCommand("Hat") ; 110 111 buttonGroup = new ButtonGroup() ; 112 buttonGroup.add(shoesButton) ; 113 buttonGroup.add(socksButton) ; 114 buttonGroup.add(trousersButton) ; 115 buttonGroup.add(shirtButton) ; 116 buttonGroup.add(hatButton) ; 117 118 otherButton = new JButton("Other order") ; 119 sendButton = new JButton("Send order(s)") ; 120 cancelButton = new JButton("Cancel order(s)") ; 121 quitButton = new JButton("Quit") ; 122 123 mainPane = new JPanel() ; 124 topPane = new JPanel() ; 125 middlePane = new JPanel() ; 126 bottomPane = new JPanel() ; 127 128 mainPane.setLayout(new GridLayout(3,1)) ; 129 topPane.setLayout(new GridLayout(1,2)) ; 130 middlePane.setLayout(new GridLayout(1,5)) ; 131 bottomPane.setLayout(new GridLayout(1,4)) ; 132 133 topPane.add(idLabel1) ; 134 topPane.add(idLabel2) ; 135 middlePane.add(shoesButton) ; 136 middlePane.add(socksButton) ; 137 middlePane.add(trousersButton) ; 138 middlePane.add(shirtButton) ; 139 middlePane.add(hatButton) ; 140 bottomPane.add(otherButton) ; 141 bottomPane.add(sendButton); 142 bottomPane.add(cancelButton) ; 143 bottomPane.add(quitButton) ; 144 mainPane.add(topPane) ; 145 mainPane.add(middlePane) ; 146 mainPane.add(bottomPane) ; 147 148 mainWindow = new JFrame(title) ; 149 mainWindow.getContentPane().add(mainPane) ; 150 151 RadioButtonListener radioBListener = new RadioButtonListener(server) ; 153 shoesButton.addActionListener(radioBListener) ; 154 socksButton.addActionListener(radioBListener) ; 155 trousersButton.addActionListener(radioBListener) ; 156 shirtButton.addActionListener(radioBListener) ; 157 hatButton.addActionListener(radioBListener) ; 158 159 160 otherButton.addActionListener(new ActionListener() { 161 public void actionPerformed(ActionEvent e) { 162 server.otherMethod() ; 163 } 164 }) ; 165 166 167 sendButton.addActionListener(new ActionListener() { 168 public void actionPerformed(ActionEvent e) { 169 server.sendMethod() ; 170 } 171 }) ; 172 173 174 cancelButton.addActionListener(new ActionListener() { 175 public void actionPerformed(ActionEvent e) { 176 server.cancelMethod() ; 177 } 178 }) ; 179 180 181 quitButton.addActionListener(new ActionListener() { 182 public void actionPerformed(ActionEvent e) { 183 server.quitMethod() ; 184 } 185 }) ; 186 187 mainWindow.pack() ; 189 mainWindow.setLocation(x,y); 190 } 191 192 203 GUI(String title, String okBut, String noBut, Servers ser, int x, int y) { 204 205 this.server = ser ; 206 207 idLabel1 = new JLabel("ORDER ID: ", SwingConstants.CENTER) ; 209 idLabel2 = new JLabel(); 210 itemLabel1 = new JLabel("ITEM: ", SwingConstants.CENTER) ; 211 itemLabel2 = new JLabel(); 212 okButton = new JButton(okBut) ; 213 noButton = new JButton(noBut) ; 214 215 mainPane = new JPanel() ; 216 topPane = new JPanel() ; 217 middlePane = new JPanel() ; 218 bottomPane = new JPanel() ; 219 220 mainPane.setLayout(new GridLayout(3,1)) ; 221 topPane.setLayout(new GridLayout(1,4)) ; 222 middlePane.setLayout(new GridLayout(1,1)) ; 223 bottomPane.setLayout(new GridLayout(1,2)) ; 224 225 topPane.add(idLabel1) ; 226 topPane.add(idLabel2) ; 227 topPane.add(itemLabel1) ; 228 topPane.add(itemLabel2) ; 229 bottomPane.add(okButton); 230 bottomPane.add(noButton); 231 mainPane.add(topPane) ; 232 mainPane.add(middlePane) ; 233 mainPane.add(bottomPane) ; 234 235 mainWindow = new JFrame(title) ; 236 mainWindow.getContentPane().add(mainPane) ; 237 238 239 okButton.addActionListener(new ActionListener() { 240 public void actionPerformed(ActionEvent e) { 241 server.okMethod() ; 242 } 243 }) ; 244 245 246 noButton.addActionListener(new ActionListener() { 247 public void actionPerformed(ActionEvent e) { 248 server.noMethod() ; 249 } 250 }) ; 251 252 mainWindow.pack() ; 254 mainWindow.setLocation(x,y); 255 } 256 257 258 259 269 GUI(String title, String info, Servers ser, int x, int y) { 270 271 this.server = ser ; 272 273 idLabel1 = new JLabel("ORDER ID: ", SwingConstants.CENTER) ; 275 idLabel2 = new JLabel() ; 276 itemLabel1 = new JLabel("ITEM: ", SwingConstants.CENTER) ; 277 itemLabel2 = new JLabel() ; 278 infoLabel = new JLabel(info, SwingConstants.CENTER) ; 279 closeButton = new JButton("Close") ; 280 281 mainPane = new JPanel() ; 282 topPane = new JPanel() ; 283 middlePane = new JPanel() ; 284 bottomPane = new JPanel() ; 285 286 mainPane.setLayout(new GridLayout(3,1)) ; 287 topPane.setLayout(new GridLayout(1,4)) ; 288 middlePane.setLayout(new GridLayout(1,1)) ; 289 bottomPane.setLayout(new GridLayout(1,1)) ; 290 291 topPane.add(idLabel1) ; 292 topPane.add(idLabel2) ; 293 topPane.add(itemLabel1) ; 294 topPane.add(itemLabel2) ; 295 middlePane.add(infoLabel) ; 296 bottomPane.add(closeButton) ; 297 mainPane.add(topPane) ; 298 mainPane.add(middlePane) ; 299 mainPane.add(bottomPane) ; 300 301 mainWindow = new JFrame(title) ; 302 mainWindow.getContentPane().add(mainPane) ; 303 304 305 closeButton.addActionListener(new ActionListener() { 306 public void actionPerformed(ActionEvent e) { 307 server.closeMethod() ; 308 } 309 }) ; 310 311 mainWindow.pack() ; 313 mainWindow.setLocation(x,y); 314 } 315 316 321 public void setVisible(boolean bool) { 322 mainWindow.setVisible(bool) ; 323 } 324 325 330 public void updateId(int id) { 331 idLabel2.setText(Integer.toString(id)) ; 332 } 333 334 339 public void updateItem(String item) { 340 itemLabel2.setText(item) ; 341 } 342 } 343 344 345 354 class RadioButtonListener implements ActionListener { 355 356 Servers server ; 357 358 363 RadioButtonListener(Servers ser) { 364 this.server = ser ; 365 } 366 367 370 public void actionPerformed(ActionEvent e) { 371 server.choiceMethod(e.getActionCommand()) ; 372 } 373 } 374 | Popular Tags |