2-APL UPC project.
0
fork

Configure Feed

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

bug fixed updatebid

fdesan f9a2d338 3d0586f3

+35 -39
+2 -2
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 168 return wrapBoolean(true); 168 169 } 169 170 ··· 177 178 178 179 public Term updateBid(String sAgent, APLNum bid) throws ExternalActionFailedException { 179 180 Agent agent = getAgent(sAgent); 180 - table.updateScore(agent.getName(), agent._position, bid.toInt()); 181 + table.updateBid(agent.getName(), agent._position, bid.toInt()); 181 182 return wrapBoolean(true); 182 183 } 183 184 ··· 386 387 { 387 388 //try {Thread.sleep(500);} catch(Exception e) {} 388 389 table.doLayout(); 389 - table.repaint(); 390 390 391 391 /*if (!m_window.isVisible()) 392 392 {
+33 -37
code/2apl_platform/environments/cardtable/Table.java
··· 10 10 private JPanel leftDisplayPane; 11 11 private JPanel[] playersPane, cardsPane; 12 12 13 - private JLayeredPane TablePane; 13 + private JLayeredPane layeredTablePane; 14 14 private JSplitPane VerticalSplitPane; 15 15 private JScrollPane GameInfo; 16 16 private JSplitPane HorizontalSplitPlane; ··· 31 31 32 32 setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 33 33 34 - TablePane = new JLayeredPane(); 34 + layeredTablePane = new JLayeredPane(); 35 35 Point origin = new Point(50, 20); 36 36 Color[] layerColors = { Color.yellow, Color.magenta, 37 37 Color.cyan, Color.red, 38 38 Color.green }; 39 - //This is the offset for computing the origin for the next label. 39 + 40 40 int offset = 35; 41 - //Add several overlapping, colored labels to the layered pane 42 - //using absolute positioning/sizing. 43 41 for (int i = 0; i < 5; i++) { 44 - JLabel label = createColoredLabel("card", layerColors[i], origin); 45 - TablePane.add(label, new Integer(i)); 42 + JLabel label = new JLabel(); 43 + 46 44 origin.x += offset; 47 45 origin.y += offset; 46 + 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); 54 + 55 + layeredTablePane.add(label, new Integer(i)); 48 56 } 49 57 50 58 infoTextArea = new JTextArea(5,00); 51 59 infoTextArea.setEditable(false); 52 60 GameInfo = new JScrollPane(infoTextArea); 53 61 54 - VerticalSplitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, TablePane,GameInfo); 62 + VerticalSplitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, layeredTablePane,GameInfo); 55 63 VerticalSplitPane.setPreferredSize(new Dimension(150,150)); 56 64 VerticalSplitPane.setOneTouchExpandable(false); 57 65 VerticalSplitPane.setDividerLocation(400); ··· 65 73 setVisible( true ); 66 74 } 67 75 68 - private JLabel createColoredLabel(String text, Color color, Point origin) { 69 - JLabel label = new JLabel(text); 70 - label.setVerticalAlignment(JLabel.TOP); 71 - label.setHorizontalAlignment(JLabel.CENTER); 72 - label.setOpaque(true); 73 - label.setBackground(color); 74 - label.setForeground(Color.black); 75 - label.setBorder(BorderFactory.createLineBorder(Color.black)); 76 - label.setBounds(origin.x, origin.y, 140, 140); 77 - 78 - pack(); 79 - setSize( 1024, 768 ); 80 - setVisible( true ); 81 - 82 - return label; 83 - } 76 + public void playCard(String name, int position) { 77 + 78 + java.net.URL imgURL = getClass().getResource("cards/b.gif"); 79 + ImageIcon cardBack = new ImageIcon(imgURL); 80 + 81 + cardsPane[position].add(new JLabel(cardBack), position); 82 + } 84 83 85 84 86 85 public void addPlayer(String name, int position, int score, int bid) { ··· 90 89 java.net.URL imgURL = getClass().getResource("cards/b.gif"); 91 90 ImageIcon cardBack = new ImageIcon(imgURL); 92 91 93 - 94 92 playersPane[position].add(new JLabel("Player: "+name)); 95 93 playersPane[position].add(new JLabel("Bid: "+bidInt.toString())); 96 94 playersPane[position].add(new JLabel(new String("Points: points here"))); 97 95 playersPane[position].add(new JLabel("Score: "+scoreInt.toString())); 98 96 99 - cardsPane[position].add(new JButton(cardBack)); 100 - cardsPane[position].add(new JButton(cardBack)); 101 - cardsPane[position].add(new JButton(cardBack)); 102 - cardsPane[position].add(new JButton(cardBack)); 103 - cardsPane[position].add(new JButton(cardBack)); 104 - cardsPane[position].add(new JButton(cardBack)); 105 - cardsPane[position].add(new JButton(cardBack)); 106 - cardsPane[position].add(new JButton(cardBack)); 107 - setVisible(true); 108 - repaint(); 97 + cardsPane[position].add(new JLabel(cardBack)); 98 + cardsPane[position].add(new JLabel(cardBack)); 99 + cardsPane[position].add(new JLabel(cardBack)); 100 + cardsPane[position].add(new JLabel(cardBack)); 101 + cardsPane[position].add(new JLabel(cardBack)); 102 + cardsPane[position].add(new JLabel(cardBack)); 103 + cardsPane[position].add(new JLabel(cardBack)); 104 + cardsPane[position].add(new JLabel(cardBack)); 109 105 } 110 106 111 107 public void updateScore(String name, int position, int score) { 112 108 Integer scoreInt = new Integer(score); 113 - JLabel scoreLab = (JLabel) cardsPane[position].getComponent(4); 109 + JLabel scoreLab = (JLabel) playersPane[position].getComponent(4); 114 110 scoreLab.setText(scoreInt.toString()); 115 111 } 116 112 117 113 public void updateBid(String name, int position, int bid) { 118 114 Integer bidInt = new Integer(bid); 119 - JLabel bidLab = (JLabel) cardsPane[position].getComponent(2); 115 + JLabel bidLab = (JLabel) playersPane[position].getComponent(2); 120 116 bidLab.setText(bidInt.toString()); 121 117 } 122 118