2-APL UPC project.
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

bbfizp 16bf282c 9607eb36

+621
+621
code/2apl_platform/environments/cardtable/Table.java
··· 1 + package mabriscola; 2 + 3 + import java.awt.*; 4 + import javax.swing.*; 5 + import java.util.*; 6 + 7 + 8 + 9 + public class Table{ 10 + //-----------CARD GAME STUFF--------------------- 11 + 12 + private Deck cardDeck = new Deck(); 13 + private Hand[] HandArray = new Hand[5]; 14 + private Hand myHand ; 15 + 16 + //----------GUI STUFF---------------------------- 17 + 18 + public JLabel[][] PlayerCards = new JLabel[8][5]; 19 + 20 + private JPanel CardDisplayPane; 21 + private JLayeredPane TablePane; 22 + private JSplitPane VerticalSplitPane; 23 + private JScrollPane GameInfo; 24 + private JSplitPane HorizontalSplitPlane; 25 + private JTextArea Info; 26 + 27 + public Table() { 28 + 29 + CardDisplayPane = new JPanel(); 30 + 31 + 32 + TablePane = new JLayeredPane(); 33 + TablePane.setBackground(Color.green); 34 + 35 + 36 + Info = new JTextArea(5,00); 37 + Info.setEditable(false); 38 + Info.append("Player1 has connected \n"); 39 + Info.append("Player2 has connected \n"); 40 + Info.append("Player3 has connected \n"); 41 + Info.append("Player4 has connected \n"); 42 + Info.append("Player5 has connected \n"); 43 + Info.append("Game Started! \n"); 44 + Info.append("Bidding Started! \n"); 45 + Info.append("Player 1 Bids.... \n"); 46 + Info.append("You get the point Fab \n"); 47 + 48 + GameInfo = new JScrollPane(Info); 49 + 50 + VerticalSplitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, 51 + TablePane,GameInfo); 52 + 53 + 54 + 55 + //AddPlayersGUI(); 56 + addComponentsToPane(CardDisplayPane); 57 + 58 + 59 + 60 + HorizontalSplitPlane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, 61 + CardDisplayPane,VerticalSplitPane ); 62 + 63 + //Provide a preferred size for the split pane. 64 + HorizontalSplitPlane.setPreferredSize(new Dimension(800,600)); 65 + } 66 + 67 + 68 + public static void addComponentsToPane(Container pane) { 69 + JButton button; 70 + pane.setLayout(new GridBagLayout()); 71 + GridBagConstraints c = new GridBagConstraints(); 72 + GridBagConstraints c1 = new GridBagConstraints(); 73 + GridBagConstraints c2 = new GridBagConstraints(); 74 + GridBagConstraints c3 = new GridBagConstraints(); 75 + GridBagConstraints c4 = new GridBagConstraints(); 76 + GridBagConstraints c5 = new GridBagConstraints(); 77 + GridBagConstraints c6 = new GridBagConstraints(); 78 + GridBagConstraints c7 = new GridBagConstraints(); 79 + GridBagConstraints c8 = new GridBagConstraints(); 80 + GridBagConstraints c9 = new GridBagConstraints(); 81 + 82 + 83 + ImageIcon Image = new ImageIcon("cards/3s.gif"); 84 + ImageIcon Image2 = new ImageIcon("cards/2c.gif"); 85 + ImageIcon Image3 = new ImageIcon("cards/7d.gif"); 86 + ImageIcon Image4 = new ImageIcon("cards/5s.gif"); 87 + 88 + //Fill in 1st Player 89 + 90 + //Player Name 91 + JButton P1NameTag = new JButton("Player1"); 92 + c.fill = GridBagConstraints.HORIZONTAL; 93 + c.gridx = 0; 94 + c.gridy = 0; 95 + c.gridwidth = 4; 96 + pane.add(P1NameTag, c); 97 + 98 + //Player Score 99 + JButton P1Score = new JButton("Score : X"); 100 + c.fill = GridBagConstraints.HORIZONTAL; 101 + c.gridx = 4; 102 + c.gridy = 0; 103 + c.gridwidth = 2; 104 + pane.add(P1Score, c); 105 + 106 + //Player Bid 107 + JButton P1Bid = new JButton("Bid : X"); 108 + c.fill = GridBagConstraints.HORIZONTAL; 109 + c.gridx = 6; 110 + c.gridy = 0; 111 + c.gridwidth = 2; 112 + pane.add(P1Bid, c); 113 + 114 + 115 + 116 + 117 + 118 + //1st Card 119 + JButton P1C1 = new JButton(Image); 120 + P1C1.setPreferredSize(new Dimension(55,80)); 121 + c1.fill = GridBagConstraints.HORIZONTAL; 122 + c1.gridx = 0; 123 + c1.gridy = 1; 124 + pane.add(P1C1, c1); 125 + 126 + //2nd Card 127 + JButton P1C2 = new JButton(Image); 128 + P1C2.setPreferredSize(new Dimension(55,80)); 129 + c1.fill = GridBagConstraints.HORIZONTAL; 130 + c1.gridx = 1; 131 + c1.gridy = 1; 132 + pane.add(P1C2, c1); 133 + 134 + //3rd Card 135 + JButton P1C3 = new JButton(Image); 136 + P1C3.setPreferredSize(new Dimension(55,80)); 137 + c1.fill = GridBagConstraints.HORIZONTAL; 138 + c1.gridx = 2; 139 + c1.gridy = 1; 140 + pane.add(P1C3, c1); 141 + 142 + //4th Card 143 + JButton P1C4 = new JButton(Image); 144 + P1C4.setPreferredSize(new Dimension(55,80)); 145 + c1.fill = GridBagConstraints.HORIZONTAL; 146 + c1.gridx = 3; 147 + c1.gridy = 1; 148 + pane.add(P1C4, c1); 149 + 150 + //5th Card 151 + JButton P1C5 = new JButton(Image); 152 + P1C5.setPreferredSize(new Dimension(55,80)); 153 + c1.fill = GridBagConstraints.HORIZONTAL; 154 + c1.gridx = 4; 155 + c1.gridy = 1; 156 + pane.add(P1C5, c1); 157 + 158 + //6th Card 159 + JButton P1C6 = new JButton(Image); 160 + P1C6.setPreferredSize(new Dimension(55,80)); 161 + c1.fill = GridBagConstraints.HORIZONTAL; 162 + c1.gridx = 5; 163 + c1.gridy = 1; 164 + pane.add(P1C6, c1); 165 + 166 + //7th Card 167 + JButton P1C7 = new JButton(Image); 168 + P1C7.setPreferredSize(new Dimension(55,80)); 169 + c1.fill = GridBagConstraints.HORIZONTAL; 170 + c1.gridx = 6; 171 + c1.gridy = 1; 172 + pane.add(P1C7, c1); 173 + 174 + //8th Card 175 + JButton P1C8 = new JButton(Image); 176 + P1C8.setPreferredSize(new Dimension(55,80)); 177 + c1.fill = GridBagConstraints.HORIZONTAL; 178 + c1.gridx = 7; 179 + c1.gridy = 1; 180 + pane.add(P1C8, c1); 181 + 182 + 183 + //Fill in 2nd Player 184 + 185 + //Player Name 186 + JButton P2NameTag = new JButton("Player2"); 187 + c2.fill = GridBagConstraints.HORIZONTAL; 188 + c2.gridx = 0; 189 + c2.gridy = 2; 190 + c2.gridwidth = 4; 191 + pane.add(P2NameTag, c2); 192 + 193 + //Player Score 194 + JButton P2Score = new JButton("Score : X"); 195 + c2.fill = GridBagConstraints.HORIZONTAL; 196 + c2.gridx = 4; 197 + c2.gridy = 2; 198 + c2.gridwidth = 2; 199 + pane.add(P2Score, c2); 200 + 201 + //Player Bid 202 + JButton P2Bid = new JButton("Bid : X"); 203 + c2.fill = GridBagConstraints.HORIZONTAL; 204 + c2.gridx = 6; 205 + c2.gridy = 2; 206 + c2.gridwidth = 2; 207 + pane.add(P2Bid, c2); 208 + 209 + 210 + //1st Card 211 + JButton P2C1 = new JButton(Image); 212 + P2C1.setPreferredSize(new Dimension(55,80)); 213 + c3.fill = GridBagConstraints.HORIZONTAL; 214 + c3.gridx = 0; 215 + c3.gridy = 3; 216 + pane.add(P2C1, c3); 217 + 218 + //2nd Card 219 + JButton P2C2 = new JButton(Image); 220 + P2C2.setPreferredSize(new Dimension(55,80)); 221 + c3.fill = GridBagConstraints.HORIZONTAL; 222 + c3.gridx = 1; 223 + c3.gridy = 3; 224 + pane.add(P2C2, c3); 225 + 226 + //3rd Card 227 + JButton P2C3 = new JButton(Image); 228 + P2C3.setPreferredSize(new Dimension(55,80)); 229 + c3.fill = GridBagConstraints.HORIZONTAL; 230 + c3.gridx = 2; 231 + c3.gridy = 3; 232 + pane.add(P2C3, c3); 233 + 234 + //4th Card 235 + JButton P2C4 = new JButton(Image); 236 + P2C4.setPreferredSize(new Dimension(55,80)); 237 + c3.fill = GridBagConstraints.HORIZONTAL; 238 + c3.gridx = 3; 239 + c3.gridy = 3; 240 + pane.add(P2C4, c3); 241 + 242 + //5th Card 243 + JButton P2C5 = new JButton(Image); 244 + P2C5.setPreferredSize(new Dimension(55,80)); 245 + c3.fill = GridBagConstraints.HORIZONTAL; 246 + c3.gridx = 4; 247 + c3.gridy = 3; 248 + pane.add(P2C5, c3); 249 + 250 + //6th Card 251 + JButton P2C6 = new JButton(Image); 252 + P2C6.setPreferredSize(new Dimension(55,80)); 253 + c3.fill = GridBagConstraints.HORIZONTAL; 254 + c3.gridx = 5; 255 + c3.gridy = 3; 256 + pane.add(P2C6, c3); 257 + 258 + //7th Card 259 + JButton P2C7 = new JButton(Image); 260 + P2C7.setPreferredSize(new Dimension(55,80)); 261 + c3.fill = GridBagConstraints.HORIZONTAL; 262 + c3.gridx = 6; 263 + c3.gridy = 3; 264 + pane.add(P2C7, c3); 265 + 266 + //8th Card 267 + JButton P2C8 = new JButton(Image); 268 + P2C8.setPreferredSize(new Dimension(55,80)); 269 + c3.fill = GridBagConstraints.HORIZONTAL; 270 + c3.gridx = 7; 271 + c3.gridy = 3; 272 + pane.add(P2C8, c3); 273 + 274 + 275 + //Fill in 3rd Player 276 + 277 + //Player Name 278 + JButton P3NameTag = new JButton("Player3"); 279 + c4.fill = GridBagConstraints.HORIZONTAL; 280 + c4.gridx = 0; 281 + c4.gridy = 4; 282 + c4.gridwidth = 4; 283 + pane.add(P3NameTag, c4); 284 + 285 + //Player Score 286 + JButton P3Score = new JButton("Score : X"); 287 + c4.fill = GridBagConstraints.HORIZONTAL; 288 + c4.gridx = 4; 289 + c4.gridy = 4; 290 + c4.gridwidth = 2; 291 + pane.add(P3Score, c4); 292 + 293 + //Player Bid 294 + JButton P3Bid = new JButton("Bid : X"); 295 + c4.fill = GridBagConstraints.HORIZONTAL; 296 + c4.gridx = 6; 297 + c4.gridy = 4; 298 + c4.gridwidth = 2; 299 + pane.add(P3Bid, c4); 300 + 301 + 302 + //1st Card 303 + JButton P3C1 = new JButton(Image); 304 + P3C1.setPreferredSize(new Dimension(55,80)); 305 + c5.fill = GridBagConstraints.HORIZONTAL; 306 + c5.gridx = 0; 307 + c5.gridy = 5; 308 + pane.add(P3C1, c5); 309 + 310 + //2nd Card 311 + JButton P3C2 = new JButton(Image); 312 + P3C2.setPreferredSize(new Dimension(55,80)); 313 + c5.fill = GridBagConstraints.HORIZONTAL; 314 + c5.gridx = 1; 315 + c5.gridy = 5; 316 + pane.add(P3C2, c5); 317 + 318 + //3rd Card 319 + JButton P3C3 = new JButton(Image); 320 + P3C3.setPreferredSize(new Dimension(55,80)); 321 + c5.fill = GridBagConstraints.HORIZONTAL; 322 + c5.gridx = 2; 323 + c5.gridy = 5; 324 + pane.add(P3C3, c5); 325 + 326 + //4th Card 327 + JButton P3C4 = new JButton(Image); 328 + P3C4.setPreferredSize(new Dimension(55,80)); 329 + c5.fill = GridBagConstraints.HORIZONTAL; 330 + c5.gridx = 3; 331 + c5.gridy = 5; 332 + pane.add(P3C4, c5); 333 + //5th Card 334 + JButton P3C5 = new JButton(Image); 335 + P3C5.setPreferredSize(new Dimension(55,80)); 336 + c5.fill = GridBagConstraints.HORIZONTAL; 337 + c5.gridx = 4; 338 + c5.gridy = 5; 339 + pane.add(P3C5, c5); 340 + 341 + //6th Card 342 + JButton P3C6 = new JButton(Image); 343 + P3C6.setPreferredSize(new Dimension(55,80)); 344 + c5.fill = GridBagConstraints.HORIZONTAL; 345 + c5.gridx = 5; 346 + c5.gridy = 5; 347 + pane.add(P3C6, c5); 348 + 349 + //7th Card 350 + JButton P3C7 = new JButton(Image); 351 + P3C7.setPreferredSize(new Dimension(55,80)); 352 + c5.fill = GridBagConstraints.HORIZONTAL; 353 + c5.gridx = 6; 354 + c5.gridy = 5; 355 + pane.add(P3C7, c5); 356 + 357 + //8th Card 358 + JButton P3C8 = new JButton(Image); 359 + P3C8.setPreferredSize(new Dimension(55,80)); 360 + c5.fill = GridBagConstraints.HORIZONTAL; 361 + c5.gridx = 7; 362 + c5.gridy = 5; 363 + pane.add(P3C8, c5); 364 + 365 + 366 + 367 + //Fill in 4th Player 368 + 369 + //Player Name 370 + JButton P4NameTag = new JButton("Player4"); 371 + c6.fill = GridBagConstraints.HORIZONTAL; 372 + c6.gridx = 0; 373 + c6.gridy = 6; 374 + c6.gridwidth = 4; 375 + pane.add(P4NameTag, c6); 376 + 377 + //Player Score 378 + JButton P4Score = new JButton("Score : X"); 379 + c6.fill = GridBagConstraints.HORIZONTAL; 380 + c6.gridx = 4; 381 + c6.gridy = 6; 382 + c6.gridwidth = 2; 383 + pane.add(P4Score, c6); 384 + 385 + //Player Bid 386 + JButton P4Bid = new JButton("Bid : X"); 387 + c6.fill = GridBagConstraints.HORIZONTAL; 388 + c6.gridx = 6; 389 + c6.gridy = 6; 390 + c6.gridwidth = 2; 391 + pane.add(P4Bid, c6); 392 + 393 + 394 + //1st Card 395 + JButton P4C1 = new JButton(Image); 396 + P4C1.setPreferredSize(new Dimension(55,80)); 397 + c7.fill = GridBagConstraints.HORIZONTAL; 398 + c7.gridx = 0; 399 + c7.gridy = 7; 400 + pane.add(P4C1, c7); 401 + 402 + //2nd Card 403 + JButton P4C2 = new JButton(Image); 404 + P4C2.setPreferredSize(new Dimension(55,80)); 405 + c7.fill = GridBagConstraints.HORIZONTAL; 406 + c7.gridx = 1; 407 + c7.gridy = 7; 408 + pane.add(P4C2, c7); 409 + 410 + //3rd Card 411 + JButton P4C3 = new JButton(Image); 412 + P4C3.setPreferredSize(new Dimension(55,80)); 413 + c7.fill = GridBagConstraints.HORIZONTAL; 414 + c7.gridx = 2; 415 + c7.gridy = 7; 416 + pane.add(P4C3, c7); 417 + 418 + //4th Card 419 + JButton P4C4 = new JButton(Image); 420 + P4C4.setPreferredSize(new Dimension(55,80)); 421 + c7.fill = GridBagConstraints.HORIZONTAL; 422 + c7.gridx = 3; 423 + c7.gridy = 7; 424 + pane.add(P4C4, c7); 425 + //5th Card 426 + JButton P4C5 = new JButton(Image); 427 + P4C5.setPreferredSize(new Dimension(55,80)); 428 + c7.fill = GridBagConstraints.HORIZONTAL; 429 + c7.gridx = 4; 430 + c7.gridy = 7; 431 + pane.add(P4C5, c7); 432 + 433 + //6th Card 434 + JButton P4C6 = new JButton(Image); 435 + P4C6.setPreferredSize(new Dimension(55,80)); 436 + c7.fill = GridBagConstraints.HORIZONTAL; 437 + c7.gridx = 5; 438 + c7.gridy = 7; 439 + pane.add(P4C6, c7); 440 + 441 + //7th Card 442 + JButton P4C7 = new JButton(Image); 443 + P4C7.setPreferredSize(new Dimension(55,80)); 444 + c7.fill = GridBagConstraints.HORIZONTAL; 445 + c7.gridx = 6; 446 + c7.gridy = 7; 447 + pane.add(P4C7, c7); 448 + 449 + //8th Card 450 + JButton P4C8 = new JButton(Image); 451 + P4C8.setPreferredSize(new Dimension(55,80)); 452 + c7.fill = GridBagConstraints.HORIZONTAL; 453 + c7.gridx = 7; 454 + c7.gridy = 7; 455 + pane.add(P4C8, c7); 456 + 457 + 458 + 459 + 460 + //Fill in 5th Player 461 + 462 + //Player Name 463 + JButton P5NameTag = new JButton("Player5"); 464 + c8.fill = GridBagConstraints.HORIZONTAL; 465 + c8.gridx = 0; 466 + c8.gridy = 8; 467 + c8.gridwidth = 4; 468 + pane.add(P5NameTag, c8); 469 + 470 + //Player Score 471 + JButton P5Score = new JButton("Score : X"); 472 + c8.fill = GridBagConstraints.HORIZONTAL; 473 + c8.gridx = 4; 474 + c8.gridy = 8; 475 + c8.gridwidth = 2; 476 + pane.add(P5Score, c8); 477 + 478 + //Player Bid 479 + JButton P5Bid = new JButton("Bid : X"); 480 + c8.fill = GridBagConstraints.HORIZONTAL; 481 + c8.gridx = 6; 482 + c8.gridy = 8; 483 + c8.gridwidth = 2; 484 + pane.add(P5Bid, c8); 485 + 486 + 487 + //1st Card 488 + JButton P5C1 = new JButton(Image); 489 + P5C1.setPreferredSize(new Dimension(55,80)); 490 + c9.fill = GridBagConstraints.HORIZONTAL; 491 + c9.gridx = 0; 492 + c9.gridy = 9; 493 + pane.add(P5C1, c9); 494 + 495 + //2nd Card 496 + JButton P5C2 = new JButton(Image); 497 + P5C2.setPreferredSize(new Dimension(55,80)); 498 + c9.fill = GridBagConstraints.HORIZONTAL; 499 + c9.gridx = 1; 500 + c9.gridy = 9; 501 + pane.add(P5C2, c9); 502 + 503 + //3rd Card 504 + JButton P5C3 = new JButton(Image); 505 + P5C3.setPreferredSize(new Dimension(55,80)); 506 + c9.fill = GridBagConstraints.HORIZONTAL; 507 + c9.gridx = 2; 508 + c9.gridy = 9; 509 + pane.add(P5C3, c9); 510 + 511 + //4th Card 512 + JButton P5C4 = new JButton(Image); 513 + P5C4.setPreferredSize(new Dimension(55,80)); 514 + c9.fill = GridBagConstraints.HORIZONTAL; 515 + c9.gridx = 3; 516 + c9.gridy = 9; 517 + pane.add(P5C4, c9); 518 + //5th Card 519 + JButton P5C5 = new JButton(Image); 520 + P5C5.setPreferredSize(new Dimension(55,80)); 521 + c9.fill = GridBagConstraints.HORIZONTAL; 522 + c9.gridx = 4; 523 + c9.gridy = 9; 524 + pane.add(P5C5, c9); 525 + 526 + //6th Card 527 + JButton P5C6 = new JButton(Image); 528 + P5C6.setPreferredSize(new Dimension(55,80)); 529 + c9.fill = GridBagConstraints.HORIZONTAL; 530 + c9.gridx = 5; 531 + c9.gridy = 9; 532 + pane.add(P5C6, c9); 533 + //7th Card 534 + JButton P5C7 = new JButton(Image); 535 + P5C7.setPreferredSize(new Dimension(55,80)); 536 + c9.fill = GridBagConstraints.HORIZONTAL; 537 + c9.gridx = 6; 538 + c9.gridy = 9; 539 + pane.add(P5C7, c9); 540 + 541 + //8th Card 542 + JButton P5C8 = new JButton(Image); 543 + P5C8.setPreferredSize(new Dimension(55,80)); 544 + c9.fill = GridBagConstraints.HORIZONTAL; 545 + c9.gridx = 7; 546 + c9.gridy = 9; 547 + pane.add(P5C8, c9); 548 + 549 + 550 + 551 + 552 + 553 + /* 554 + button = new JButton("5"); 555 + c.fill = GridBagConstraints.HORIZONTAL; 556 + c.ipady = 0; //reset to default 557 + c.weighty = 1.0; //request any extra vertical space 558 + c.anchor = GridBagConstraints.PAGE_END; //bottom of space 559 + c.insets = new Insets(10,0,0,0); //top padding 560 + c.gridx = 1; //aligned with button 2 561 + c.gridwidth = 2; //2 columns wide 562 + c.gridy = 2; //third row 563 + pane.add(button, c); 564 + * */ 565 + 566 + } 567 + 568 + 569 + /* Old add cards method 570 + 571 + 572 + public void AddPlayersGUI(){ 573 + for (int i=0; i<8; i++){ 574 + for (int j=0; j<5; j++){ 575 + PlayerCards[i][j] = new JLabel(); 576 + PlayerCards[i][j].setBackground(java.awt.Color.green); 577 + PlayerCards[i][j].setBounds(100 + i*56,12 + j*110,55,80); 578 + 579 + CardDisplayPane.add(PlayerCards[i][j]); 580 + Card c = cardDeck.dealCard(); 581 + PlayerCards[i][j].setIcon( c.getCardImage() ); 582 + 583 + 584 + } 585 + 586 + } 587 + 588 + 589 + } 590 + */ 591 + 592 + public JSplitPane getSplitPane() { 593 + return HorizontalSplitPlane; 594 + } 595 + 596 + private static void createAndShowGUI() { 597 + 598 + //Create and set up the window. 599 + JFrame frame = new JFrame("Briscola"); 600 + frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 601 + Table GameObject = new Table(); 602 + GameObject.getSplitPane().setBackground(java.awt.Color.green); 603 + frame.getContentPane().add(GameObject.getSplitPane()); 604 + frame.getContentPane().setBackground(java.awt.Color.green); 605 + 606 + //Display the window. 607 + frame.pack(); 608 + frame.setPreferredSize(new Dimension(800,600)); 609 + frame.setVisible(true); 610 + } 611 + 612 + public static void main(String[] args) { 613 + //Schedule a job for the event-dispatching thread: 614 + //creating and showing this application's GUI. 615 + createAndShowGUI(); 616 + 617 + javax.swing.SwingUtilities.invokeLater(new Runnable() { public void run() {} }); 618 + } 619 + 620 + 621 + }