home *** CD-ROM | disk | FTP | other *** search
/ The Net: Ultimate Internet Guide / WWLCD1.ISO / pc / java / in4wjcxu / src / como / commlet / nicnacnoe / gamecontrols.java < prev    next >
Encoding:
Java Source  |  1996-08-14  |  2.6 KB  |  110 lines

  1. /*
  2. * @(#)GameCanvas.java    1.0 95/11/09 Ulrich Gall & Jan Kautz
  3. *
  4. * Copyright (c) 1996 Ulrich Gall & Jan Kautz
  5. * uhgall@cip.informatik.uni-erlangen.de
  6. * Hofmannstr. 48, D-91052 Erlangen, Germany, Fax: +49-9131-201358
  7. *
  8. * Permission to use, copy, and distribute this software
  9. * and its documentation for NON-COMMERCIAL purposes and without
  10. * fee is hereby granted provided that this copyright notice
  11. * appears in all copies. Please contact us for  further copyright
  12. * and licensing information.
  13. *
  14. * WE MAKE NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF
  15. * THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
  16. * TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
  17. * PARTICULAR PURPOSE, OR NON-INFRINGEMENT. WE SHALL NOT BE LIABLE FOR
  18. * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
  19. * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
  20. */
  21.  
  22. package como.commlet.nicnacnoe;
  23.  
  24. import java.util.*;
  25. import java.applet.*;
  26. import java.awt.*;
  27. import java.io.*;
  28. import java.awt.image.*;
  29.  
  30. import como.sys.*;
  31. import como.util.*;
  32. import como.awt.*;
  33. import como.io.*;
  34.  
  35.  
  36. public class GameControls extends Panel {
  37.  
  38. Hashtable sk;
  39.  
  40. public GameControls(Hashtable players) {
  41. sk = new Hashtable(); // playernum -> scorekeeper
  42. setLayout(new VertLayout(VertLayout.STRETCH));
  43. Enumeration e = players.keys();
  44. while (e.hasMoreElements()) {
  45.     Object k = e.nextElement();
  46.     User u = (User)players.get(k);
  47.     ScoreKeeper s = new ScoreKeeper(u);
  48.     s.disable();
  49.     sk.put(k,s);
  50.     add(s);
  51. }
  52. }
  53. public void enable(int id) {
  54. ScoreKeeper s = (ScoreKeeper)sk.get(new Integer(id));
  55. if (s != null) s.enable();
  56. }
  57. public void disable(int id) {
  58. ScoreKeeper s = (ScoreKeeper)sk.get(new Integer(id));
  59. if (s != null) s.disable();
  60. }
  61. public void update(User u) {
  62. ScoreKeeper s = (ScoreKeeper)sk.get(new Integer(u.getID()));
  63. if (s != null) s.update(u);
  64. }
  65. public void update(int id) {
  66. ScoreKeeper s = (ScoreKeeper)sk.get(new Integer(id));
  67. if (s != null) s.update();
  68. }
  69. }
  70. class ScoreKeeper extends Panel {
  71.  
  72. TextField nameTF;
  73. TextField scoreTF;
  74. Canvas colorshow;
  75. User user;
  76.  
  77. public ScoreKeeper(User u) {
  78. super();
  79. user = u;
  80. nameTF = new TextField(25);
  81. nameTF.setEditable(false);
  82. scoreTF = new TextField(8);
  83. scoreTF.setEditable(false);
  84. colorshow = new Canvas();
  85. colorshow.resize(30,30);
  86. colorshow.setBackground((Color)u.get(u.COLOR));
  87. add(colorshow);
  88. add(nameTF);
  89. add(scoreTF);
  90. update();
  91. }
  92. public void update(User u) {
  93. user = u;
  94. update();
  95. }
  96. public void update() {
  97. colorshow.setBackground((Color)user.get(user.COLOR));
  98. nameTF.setText(user.getName());
  99. scoreTF.setText("Score: "+user.get(user.SCORE));
  100. }
  101. public void enable() {
  102. scoreTF.enable();
  103. nameTF.enable();
  104. }
  105. public void disable() {
  106. scoreTF.disable();
  107. nameTF.disable();
  108. }
  109. }
  110.