KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > poker > presentation > main > PlaceBetPresentation


1 /*
2  * Poker
3  *
4  * Enhydra super-servlet presentation object
5  *
6  */

7
8 package poker.presentation.main;
9
10 // Enhydra SuperServlet imports
11
import com.lutris.appserver.server.httpPresentation.HttpPresentation;
12 import com.lutris.appserver.server.httpPresentation.HttpPresentationComms;
13 import org.w3c.dom.html.HTMLTextAreaElement;
14 import org.w3c.dom.html.HTMLInputElement;
15 import org.w3c.dom.html.HTMLImageElement;
16
17 import poker.Poker;
18 import poker.spec.PokerGame;
19 import poker.spec.GameManager;
20
21 import java.util.Vector JavaDoc;
22
23 public class PlaceBetPresentation implements HttpPresentation {
24
25   public void run(HttpPresentationComms comms)
26                         throws Exception JavaDoc {
27
28     PlaceBetHTML placeBet;
29     placeBet = (PlaceBetHTML)comms.xmlcFactory.create(PlaceBetHTML.class);
30 /*
31  * Catch Null pointer exception ( we canot make a instances of classes from business layer when we run poker_pres )
32  * We need to allow poker_pres to be dynamic , so if the requested url is /poker_pres/..... the response
33  * will be default HTML page
34  */

35    try{
36     this.initGame(comms, placeBet);
37 }catch (NullPointerException JavaDoc e){
38     placeBet.setTextMessage("This is a default HTML page");
39     }
40
41     comms.response.writeDOM(placeBet);
42
43   }
44
45    static public void initGame(HttpPresentationComms comms0, PlaceBetHTML placeBet0)
46                                                           throws Exception JavaDoc {
47     PokerGame game = (PokerGame)comms0.session.getSessionData().get("game");
48     Poker mainApp = (Poker)comms0.session.getSessionData().get("app");
49     GameManager gameManager = mainApp.getGameManager();
50       
51     game.setPlayRound(1);
52
53       Vector JavaDoc freshDrops = new Vector JavaDoc(0);
54       for (int i = 0; i < 5; i++) {
55         freshDrops.addElement("DROP");
56       }
57     game.setDropCards(freshDrops);
58
59     placeBet0.setTextCash(Integer.toString(game.getCash()));
60     placeBet0.setTextName(game.getName());
61     placeBet0.setTextRank(Integer.toString(gameManager.getRank(game.getCash())));
62     placeBet0.setTextWon(Integer.toString(game.getTotalWon()));
63     placeBet0.setTextHandsPlayed(Integer.toString(game.getTotalPlayed()));
64
65     HTMLImageElement image = null;
66     image = placeBet0.getElementDeck1();
67     image.setSrc("../media/" + game.getDeck() + ".jpg");
68     image = placeBet0.getElementDeck2();
69     image.setSrc("../media/" + game.getDeck() + ".jpg");
70     image = placeBet0.getElementDeck3();
71     image.setSrc("../media/" + game.getDeck() + ".jpg");
72     image = placeBet0.getElementDeck4();
73     image.setSrc("../media/" + game.getDeck() + ".jpg");
74     image = placeBet0.getElementDeck5();
75     image.setSrc("../media/" + game.getDeck() + ".jpg");
76
77     HTMLInputElement input = null;
78     input = placeBet0.getElementBetInput();
79     input.setValue( Integer.toString(game.getDefaultBet()) );
80
81     if (game.getDefaultBet() > 0) {
82       input = placeBet0.getElementCheckInput();
83       input.setChecked(true);
84       input.setValue("on");
85     }
86     else {
87       input = placeBet0.getElementCheckInput();
88       input.setChecked(false);
89       input.setValue("off");
90     }
91
92     if (game.getLastError() != "") {
93       placeBet0.setTextMessage(game.getLastError());
94       game.setLastError("");
95     }
96     else {
97       placeBet0.setTextMessage("");
98     }
99   }
100
101
102 }
103
Popular Tags