2-APL UPC project.
0
fork

Configure Feed

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

at main 230 lines 7.0 kB view raw
1package cardtable; 2 3import javax.swing.*; 4import java.awt.*; 5import java.lang.Integer; 6 7 8 9public class Table extends JFrame{ 10 11 private JPanel leftDisplayPane; 12 private JPanel[] playersPane, cardsPane; 13 14 private JLayeredPane layeredPane; 15 private JSplitPane VerticalSplitPane; 16 private JScrollPane GameInfo; 17 private JSplitPane HorizontalSplitPlane; 18 private JTextArea infoTextArea; 19 private int round; 20 private Hand[] hands; 21 22 public Table( ){ 23 super( "Briscola Chiamata" ); 24 round = 0; 25 hands = new Hand[5]; 26 27 leftDisplayPane = new JPanel(new GridBagLayout()); 28 playersPane = new JPanel[5]; 29 cardsPane = new JPanel[5]; 30 31 for(int i=0; i<5; i++) { 32 playersPane[i] = new JPanel(new GridBagLayout()); 33 cardsPane[i] = new JPanel(new GridBagLayout()); 34 GridBagConstraints c = new GridBagConstraints(); 35 c.fill = GridBagConstraints.HORIZONTAL; 36 c.anchor = GridBagConstraints.CENTER; 37 c.gridx = 0; 38 c.gridy = i; 39 leftDisplayPane.add(playersPane[i], c); 40 c.gridx = 1; 41 leftDisplayPane.add(cardsPane[i], c); 42 } 43 44 setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 45 46 layeredPane = new JLayeredPane(); 47 Point origin = new Point(10, 20); 48 int offset = 35; 49 for (int i = 0; i < 5; i++) { 50 JLabel label = new JLabel(); 51 52 origin.x += offset; 53 origin.y += offset; 54 55 label.setVerticalAlignment(JLabel.TOP); 56 label.setHorizontalAlignment(JLabel.CENTER); 57 label.setOpaque(true); 58 label.setBackground(Color.gray); 59 label.setForeground(Color.black); 60 label.setBorder(BorderFactory.createLineBorder(Color.black)); 61 label.setBounds(origin.x, origin.y, 73, 97); 62 63 layeredPane.add(label, new Integer(i)); 64 } 65 JLabel label = new JLabel("Player : -"); 66 origin.x = 73; 67 origin.y += offset+97; 68 label.setBounds(origin.x, origin.y, 150, 20); 69 layeredPane.add(label, 5); 70 label = new JLabel("Round : -"); 71 origin.x += 150; 72 origin.y += 0; 73 label.setBounds(origin.x, origin.y, 150, 20); 74 layeredPane.add(label, 6); 75 label = new JLabel("Briscola : -"); 76 origin.x = 73; 77 origin.y += 40; 78 label.setBounds(origin.x, origin.y, 300, 20); 79 layeredPane.add(label, 7); 80 81 infoTextArea = new JTextArea(5,00); 82 infoTextArea.setEditable(false); 83 GameInfo = new JScrollPane(infoTextArea); 84 85 VerticalSplitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, layeredPane,GameInfo); 86 VerticalSplitPane.setOneTouchExpandable(false); 87 VerticalSplitPane.setDividerLocation(450); 88 89 HorizontalSplitPlane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, leftDisplayPane,VerticalSplitPane ); 90 HorizontalSplitPlane.setOneTouchExpandable(false); 91 HorizontalSplitPlane.setDividerLocation(900); 92 93 getContentPane().add(HorizontalSplitPlane); 94 pack(); 95 setSize( 1280, 768 ); 96 setVisible( true ); 97 } 98 99 public void addPlayer(String name, int position, int score, int bid) { 100 Integer scoreInt = new Integer(score); 101 Integer bidInt = new Integer(bid); 102 103 java.net.URL imgURL = getClass().getResource("cards/b.gif"); 104 ImageIcon cardBack = new ImageIcon(imgURL); 105 106 GridBagConstraints c = new GridBagConstraints(); 107 c.fill = GridBagConstraints.HORIZONTAL; 108 c.anchor = GridBagConstraints.CENTER; 109 c.gridx = 0; 110 c.gridy = 0; 111 playersPane[position].add(new JLabel("Player: "+name), c); 112 c.gridy = 1; 113 playersPane[position].add(new JLabel("Bid: "+bidInt.toString()), c); 114 c.gridy = 2; 115 playersPane[position].add(new JLabel(new String("Points: -")), c); 116 c.gridy = 3; 117 playersPane[position].add(new JLabel("Score: "+scoreInt.toString()), c); 118 119 c.fill = GridBagConstraints.VERTICAL; 120 c.anchor = GridBagConstraints.CENTER; 121 c.gridx = 0; 122 c.gridy = 0; 123 cardsPane[position].add(new JLabel(cardBack), c); 124 c.gridx = 1; 125 cardsPane[position].add(new JLabel(cardBack), c); 126 c.gridx = 2; 127 cardsPane[position].add(new JLabel(cardBack), c); 128 c.gridx = 3; 129 cardsPane[position].add(new JLabel(cardBack), c); 130 c.gridx = 4; 131 cardsPane[position].add(new JLabel(cardBack), c); 132 c.gridx = 5; 133 cardsPane[position].add(new JLabel(cardBack), c); 134 c.gridx = 6; 135 cardsPane[position].add(new JLabel(cardBack), c); 136 c.gridx = 7; 137 cardsPane[position].add(new JLabel(cardBack), c); 138 139 setVisible( true ); 140 } 141 142 public void displayHand(String name, int position, Hand hand) { 143 hands[position] = hand; 144 for(int i=0; i<8; i++) { 145 cardsPane[position].add(new JLabel(hand.getCard(i).getCardImage()), i); 146 } 147 setVisible( true ); 148 } 149 150 public void playedCard(String name, int position, Card card) { 151 java.net.URL imgURL = getClass().getResource("cards/b.gif"); 152 ImageIcon cardBack = new ImageIcon(imgURL); 153 154 int pos = hands[position].findCard(card); 155 JLabel imgLab = (JLabel) cardsPane[position].getComponent(pos); 156 imgLab.setIcon(cardBack); 157 158 JLabel label = (JLabel) layeredPane.getComponent(position); 159 label.setIcon(card.getCardImage()); 160 JLabel player = (JLabel) layeredPane.getComponent(5); 161 player.setText("Player : "+name); 162 if(round==0) { 163 JLabel roundLab = (JLabel) layeredPane.getComponent(6); 164 roundLab.setText("Round : 1"); 165 round++; 166 } 167 setVisible( true ); 168 } 169 170 public void briscolaDeclared(String name, int position, Card card) { 171 JLabel briscolaLab = (JLabel) layeredPane.getComponent(7); 172 briscolaLab.setText("Briscola : "+card.getRank().getName()+" of "+card.getSuit().getName()+" by "+name); 173 JLabel declarer = (JLabel) playersPane[position].getComponent(0); 174 declarer.setForeground(Color.blue); 175 for(int i=0;i<5;i++) { 176 if(hands[i].findCard(card)!=-1) { 177 int pos = hands[i].findCard(card); 178 JLabel teammate = (JLabel) playersPane[i].getComponent(0); 179 teammate.setForeground(Color.blue); 180 } 181 } 182 setVisible( true ); 183 } 184 185 public void updateScore(String name, int position, int score) { 186 Integer scoreInt = new Integer(score); 187 JLabel scoreLab = (JLabel) playersPane[position].getComponent(3); 188 scoreLab.setText("Score: "+scoreInt.toString()); 189 setVisible( true ); 190 } 191 192 public void updatePoints(String name, int position, int points) { 193 java.net.URL imgURL = getClass().getResource("cards/b.gif"); 194 ImageIcon cardBack = new ImageIcon(imgURL); 195 196 Integer pointsInt = new Integer(points); 197 JLabel pointsLab = (JLabel) playersPane[position].getComponent(2); 198 pointsLab.setText("Points: "+pointsInt.toString()); 199 JLabel roundLab = (JLabel) layeredPane.getComponent(6); 200 round++; 201 if(round<9) { 202 Integer roundInt = new Integer(round); 203 roundLab.setText("Round : "+roundInt.toString()); 204 } 205 for (int i = 0; i < 5; i++) { 206 JLabel cardLab = (JLabel) layeredPane.getComponent(i); 207 cardLab.setIcon(cardBack); 208 } 209 setVisible( true ); 210 } 211 212 public void updateBid(String name, int position, int bid) { 213 Integer bidInt = new Integer(bid); 214 JLabel bidLab = (JLabel) playersPane[position].getComponent(1); 215 bidLab.setText("Bid: "+bidInt.toString()); 216 setVisible( true ); 217 } 218 219 public void writeLog(String text) { 220 infoTextArea.append(text+"\n"); 221 infoTextArea.setCaretPosition(infoTextArea.getDocument().getLength()); 222 } 223} 224 225 226 227 228 229 230