01: // Copyright 2007 The Apache Software Foundation
02: //
03: // Licensed under the Apache License, Version 2.0 (the "License");
04: // you may not use this file except in compliance with the License.
05: // You may obtain a copy of the License at
06: //
07: // http://www.apache.org/licenses/LICENSE-2.0
08: //
09: // Unless required by applicable law or agreed to in writing, software
10: // distributed under the License is distributed on an "AS IS" BASIS,
11: // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12: // See the License for the specific language governing permissions and
13: // limitations under the License.
14:
15: package org.apache.tapestry.tutorial.pages;
16:
17: import org.apache.tapestry.annotations.InjectPage;
18: import org.apache.tapestry.annotations.Persist;
19:
20: public class Guess {
21: @Persist
22: private int _target;
23:
24: private int _guess;
25:
26: @Persist
27: private String _message;
28:
29: @Persist
30: private int _count;
31:
32: public String getMessage() {
33: return _message;
34: }
35:
36: @InjectPage
37: private GameOver _gameOver;
38:
39: Object onActionFromLink(int guess) {
40: _count++;
41:
42: if (guess == _target) {
43: _gameOver.setup(_count);
44: return _gameOver;
45: }
46:
47: if (guess < _target)
48: _message = String.format("%d is too low.", guess);
49: else
50: _message = String.format("%d is too high.", guess);
51:
52: return null;
53: }
54:
55: public int getGuess() {
56: return _guess;
57: }
58:
59: public void setGuess(int guess) {
60: _guess = guess;
61: }
62:
63: void setup(int target) {
64: _target = target;
65: _count = 0;
66: }
67:
68: public int getTarget() {
69: return _target;
70: }
71: }
|