home *** CD-ROM | disk | FTP | other *** search
/ The Net: Ultimate Internet Guide / WWLCD1.ISO / pc / java / in4wjcxu / src / como / commlet / classroom / classroom.java
Encoding:
Java Source  |  1996-08-14  |  3.9 KB  |  141 lines

  1. /*
  2. * @(#)ClassRoom.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. package como.commlet.classroom;
  22.  
  23. import java.util.*;
  24. import java.awt.*;
  25. import java.io.*;
  26.  
  27. import como.sys.*;
  28. import como.util.*;
  29. import como.awt.*;
  30. import como.commlet.*;
  31. import como.commlet.draw.*;
  32. import como.commlet.superchat.*;
  33. import como.commlet.messagelog.*;
  34. import como.commlet.userlist.*;
  35.  
  36. /**
  37. * This is an example how to program a MetaCommlet.
  38. */
  39. public class ClassRoom extends MetaCommlet {
  40.  
  41. static final int MSG_TEXT_CHANGED = 10001;
  42. // Pick any numbers >10000 if your Commlet is derived from any of our classes
  43. // All MSG numbers should be within an interval of 1000 for each class, thus,
  44. // a class derived from this one should start at 11000 etc.
  45.  
  46. TextArea myText;
  47. Button myButton;
  48.  
  49. // This is a TextArea we will place in the MetaCommlets window and let the
  50. // user edit.
  51.  
  52. public String getCommletName()
  53.        {
  54.        String s = "ClassRoom";
  55.        if (getTopicTextField() != null) s = s + " with topic ='"+ getTopicTextField().getText()+"'";
  56.        return s;
  57.        }
  58.  
  59. public String getCommletInfo()
  60.        {
  61.        return("ClassRoom, demo Commlet, V 1.0, (c) Jan Kautz & Ulrich Gall");
  62.        }
  63.  
  64. /**
  65. * Commlets must have an empty constructor.
  66. */
  67. public ClassRoom()
  68.        {
  69.        }
  70.  
  71. public void init()
  72.      {
  73.      super.init();
  74.      setTitle("Como ClassRoom Commlet");        
  75.      // include some basic Commlets in the menu
  76.      SuperChat c = new SuperChat();
  77.      addCommlet(c,"Class room");
  78.      c.setTitle("Como ClassRoom Commlet: class room window");
  79.  
  80.      Draw d = new Draw();
  81.      addCommlet(d,"Board");
  82.      d.setTitle("Como ClassRoom Commlet: Board");
  83.  
  84.      UserList ul = new UserList();
  85.      addCommlet(ul,"Students");
  86.      ul.setTitle("Como ClassRoom Commlet: Student list");
  87.  
  88.      String s = "\n\n    Welcome to todays _________ class.\n";
  89.      myText=new TextArea(s);
  90.  
  91.      add("Center",myText);
  92.     myButton = new Button("Update This Text On The Students' Screens");
  93.      add("South",myButton);
  94.      pack();
  95.     if (com.iAmMaster()) myButton.show(); else myButton.hide();
  96.     myText.setEditable(com.iAmMaster());
  97.      }
  98. /**
  99. * This is called whenever a new user joins.
  100. */
  101. public void addUser(int who) {
  102.     if (com.iAmMaster()) 
  103.         com.sendTo(new Msg(MSG_TEXT_CHANGED,who,myText.getText()));
  104.     }
  105.  
  106. public boolean handleEvent(Event evt)
  107.        {
  108.        if (super.handleEvent(evt)) return true;
  109.        if (evt.target == myButton)
  110.           {
  111.           com.sendToOthers(new Msg(MSG_TEXT_CHANGED,myText.getText()));
  112.           // It may be better style to call sendToAll, but here it doesnÃ…t
  113.           // matter at all.
  114.       myText.requestFocus();
  115.           return true;
  116.           }
  117.        return false;
  118.        }
  119.  
  120. /**
  121. * Handle an incoming message. This is called by the ComObj.
  122. */
  123. public boolean handleMsg(Msg msg)
  124.        {
  125.        if (msg.type == Msg.NEW_MASTER)
  126.           {
  127.         int m = ((Integer)msg.arg).intValue();
  128.         myText.setEditable(com.iAmMaster());
  129.         if (m == com.getMyID())
  130.             myButton.show();
  131.         else
  132.             myButton.hide();
  133.           }
  134.        if (msg.type == MSG_TEXT_CHANGED)
  135.           {
  136.           myText.setText(msg.arg.toString());
  137.           }
  138.        return (super.handleMsg(msg));
  139.        }
  140. }
  141.