2-APL UPC project.
0
fork

Configure Feed

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

acceptable GUI finally

fdesan 351469e5 14096417

+62 -37
+2 -1
code/2apl_platform/environments/cardtable/Env.java
··· 164 164 public Term playCard(String sAgent, APLIdent suit, APLIdent rank) throws ExternalActionFailedException { 165 165 Agent agent = getAgent(sAgent); 166 166 notifyEvent("cardPlayed", suit, rank, agent); 167 - //table.playCard(agent.getName(), agent._position); 167 + Card played_card = deck.getCard(suit.toString(), rank.toString()); 168 + table.playedCard(agent.getName(), agent._position, played_card); 168 169 return wrapBoolean(true); 169 170 } 170 171
+60 -36
code/2apl_platform/environments/cardtable/Table.java
··· 18 18 19 19 public Table( ){ 20 20 super( "Briscola Chiamata" ); 21 - leftDisplayPane = new JPanel(new GridLayout(5,2)); 21 + leftDisplayPane = new JPanel(new GridBagLayout()); 22 22 playersPane = new JPanel[5]; 23 23 cardsPane = new JPanel[5]; 24 24 25 25 for(int i=0; i<5; i++) { 26 - playersPane[i] = new JPanel(new GridLayout(4,1)); 27 - cardsPane[i] = new JPanel(new GridLayout(1,8)); 28 - leftDisplayPane.add(playersPane[i]); 29 - leftDisplayPane.add(cardsPane[i]); 26 + playersPane[i] = new JPanel(new GridBagLayout()); 27 + cardsPane[i] = new JPanel(new GridBagLayout()); 28 + GridBagConstraints c = new GridBagConstraints(); 29 + c.fill = GridBagConstraints.HORIZONTAL; 30 + c.anchor = GridBagConstraints.CENTER; 31 + c.gridx = 0; 32 + c.gridy = i; 33 + leftDisplayPane.add(playersPane[i], c); 34 + c.gridx = 1; 35 + leftDisplayPane.add(cardsPane[i], c); 30 36 } 31 37 32 38 setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 33 39 34 40 layeredTablePane = new JLayeredPane(); 35 - Point origin = new Point(50, 20); 41 + Point origin = new Point(10, 20); 36 42 Color[] layerColors = { Color.yellow, Color.magenta, 37 43 Color.cyan, Color.red, 38 44 Color.green }; ··· 44 50 origin.x += offset; 45 51 origin.y += offset; 46 52 47 - label.setVerticalAlignment(JLabel.TOP); 48 - label.setHorizontalAlignment(JLabel.CENTER); 49 - label.setOpaque(true); 50 - label.setBackground(Color.red); 51 - label.setForeground(Color.black); 52 - label.setBorder(BorderFactory.createLineBorder(Color.black)); 53 - label.setBounds(origin.x, origin.y, 140, 140); 53 + label.setVerticalAlignment(JLabel.TOP); 54 + label.setHorizontalAlignment(JLabel.CENTER); 55 + label.setOpaque(true); 56 + label.setBackground(Color.gray); 57 + label.setForeground(Color.black); 58 + label.setBorder(BorderFactory.createLineBorder(Color.black)); 59 + label.setBounds(origin.x, origin.y, 73, 97); 54 60 55 61 layeredTablePane.add(label, new Integer(i)); 56 62 } ··· 60 66 GameInfo = new JScrollPane(infoTextArea); 61 67 62 68 VerticalSplitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, layeredTablePane,GameInfo); 63 - VerticalSplitPane.setPreferredSize(new Dimension(150,150)); 69 + //VerticalSplitPane.setPreferredSize(new Dimension(150,50)); 64 70 VerticalSplitPane.setOneTouchExpandable(false); 65 - VerticalSplitPane.setDividerLocation(400); 71 + VerticalSplitPane.setDividerLocation(450); 66 72 67 73 HorizontalSplitPlane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, leftDisplayPane,VerticalSplitPane ); 68 - HorizontalSplitPlane.setPreferredSize(new Dimension(150,150)); 74 + //HorizontalSplitPlane.setPreferredSize(new Dimension(150,150)); 69 75 HorizontalSplitPlane.setOneTouchExpandable(false); 70 - HorizontalSplitPlane.setDividerLocation(600); 76 + HorizontalSplitPlane.setDividerLocation(900); 71 77 72 78 getContentPane().add(HorizontalSplitPlane); 73 79 pack(); 74 - setSize( 1024, 768 ); 80 + setSize( 1280, 768 ); 75 81 setVisible( true ); 76 82 } 77 83 78 84 public void displayHand(String name, int position, Card[] cards) { 79 - 80 - java.net.URL imgURL = getClass().getResource("cards/b.gif"); 81 - ImageIcon cardBack = new ImageIcon(imgURL); 82 - 83 85 for(int i=0; i<8; i++) { 84 86 cardsPane[position].add(new JLabel(cards[i].getCardImage()), i); 85 - // writeLog(cards[i].getRank()+cards[i].getSuit()); 86 87 } 87 - 88 88 setVisible( true ); 89 89 } 90 90 91 + public void playedCard(String name, int position, Card card) { 92 + JLabel label = (JLabel) layeredTablePane.getComponent(position); 93 + label.setIcon(card.getCardImage()); 94 + setVisible( true ); 95 + } 91 96 92 97 public void addPlayer(String name, int position, int score, int bid) { 93 98 Integer scoreInt = new Integer(score); ··· 96 101 java.net.URL imgURL = getClass().getResource("cards/b.gif"); 97 102 ImageIcon cardBack = new ImageIcon(imgURL); 98 103 99 - playersPane[position].add(new JLabel("Player: "+name)); 100 - playersPane[position].add(new JLabel("Bid: "+bidInt.toString())); 101 - playersPane[position].add(new JLabel(new String("Points: points here"))); 102 - playersPane[position].add(new JLabel("Score: "+scoreInt.toString())); 104 + GridBagConstraints c = new GridBagConstraints(); 105 + c.fill = GridBagConstraints.HORIZONTAL; 106 + c.anchor = GridBagConstraints.CENTER; 107 + c.gridx = 0; 108 + c.gridy = 0; 109 + playersPane[position].add(new JLabel("Player: "+name), c); 110 + c.gridy = 1; 111 + playersPane[position].add(new JLabel("Bid: "+bidInt.toString()), c); 112 + c.gridy = 2; 113 + playersPane[position].add(new JLabel(new String("Points: -")), c); 114 + c.gridy = 3; 115 + playersPane[position].add(new JLabel("Score: "+scoreInt.toString()), c); 103 116 104 - cardsPane[position].add(new JLabel(cardBack)); 105 - cardsPane[position].add(new JLabel(cardBack)); 106 - cardsPane[position].add(new JLabel(cardBack)); 107 - cardsPane[position].add(new JLabel(cardBack)); 108 - cardsPane[position].add(new JLabel(cardBack)); 109 - cardsPane[position].add(new JLabel(cardBack)); 110 - cardsPane[position].add(new JLabel(cardBack)); 111 - cardsPane[position].add(new JLabel(cardBack)); 117 + c.fill = GridBagConstraints.VERTICAL; 118 + c.anchor = GridBagConstraints.CENTER; 119 + c.gridx = 0; 120 + c.gridy = 0; 121 + cardsPane[position].add(new JLabel(cardBack), c); 122 + c.gridx = 1; 123 + cardsPane[position].add(new JLabel(cardBack), c); 124 + c.gridx = 2; 125 + cardsPane[position].add(new JLabel(cardBack), c); 126 + c.gridx = 3; 127 + cardsPane[position].add(new JLabel(cardBack), c); 128 + c.gridx = 4; 129 + cardsPane[position].add(new JLabel(cardBack), c); 130 + c.gridx = 5; 131 + cardsPane[position].add(new JLabel(cardBack), c); 132 + c.gridx = 6; 133 + cardsPane[position].add(new JLabel(cardBack), c); 134 + c.gridx = 7; 135 + cardsPane[position].add(new JLabel(cardBack), c); 112 136 113 137 setVisible( true ); 114 138 }