home *** CD-ROM | disk | FTP | other *** search
/ Symantec Visual Cafe for Java 2.5 / symantec-visual-cafe-2.5-database-dev-edition.iso / VCafe / VCSAMPL.BIN / Client.class (.txt) < prev    next >
Encoding:
Java Class File  |  1997-09-08  |  3.2 KB  |  99 lines

  1. import java.applet.Applet;
  2. import java.awt.Container;
  3. import java.awt.Label;
  4. import java.awt.LayoutManager;
  5. import java.awt.Panel;
  6. import java.awt.TextField;
  7.  
  8. public class Client extends Applet implements Runnable {
  9.    Mediator myMediator;
  10.    String label;
  11.    String response;
  12.    int theNumber;
  13.    Thread clientThread;
  14.    TextField clientTalk;
  15.    Label client;
  16.    Label top;
  17.    Label developer;
  18.    TextField developerTalk;
  19.  
  20.    public void init() {
  21.       this.myMediator = new Mediator();
  22.       ((Container)this).setLayout((LayoutManager)null);
  23.       ((Panel)this).addNotify();
  24.       ((Applet)this).resize(448, 110);
  25.       this.clientTalk = new TextField(18);
  26.       this.clientTalk.setEditable(false);
  27.       this.clientTalk.reshape(170, 38, 268, 24);
  28.       ((Container)this).add(this.clientTalk);
  29.       this.client = new Label("Client says:");
  30.       this.client.reshape(0, 35, 80, 24);
  31.       ((Container)this).add(this.client);
  32.       this.top = new Label("I'm a Client");
  33.       this.top.reshape(0, 0, 89, 24);
  34.       ((Container)this).add(this.top);
  35.       this.developer = new Label("The Developer just said:");
  36.       this.developer.reshape(0, 70, 153, 24);
  37.       ((Container)this).add(this.developer);
  38.       this.developerTalk = new TextField(17);
  39.       this.developerTalk.setEditable(false);
  40.       this.developerTalk.reshape(170, 68, 268, 24);
  41.       ((Container)this).add(this.developerTalk);
  42.    }
  43.  
  44.    public void start() {
  45.       this.clientThread = new Thread(this);
  46.       this.clientThread.start();
  47.    }
  48.  
  49.    public void run() {
  50.       Thread clientThread = Thread.currentThread();
  51.  
  52.       while(true) {
  53.          try {
  54.             Thread.sleep(2000L);
  55.          } catch (Exception e) {
  56.             System.out.println(e);
  57.          }
  58.  
  59.          Mediator.oldNumber = Mediator.theNumber;
  60.          Mediator.theNumber = this.myMediator.genRandom();
  61.          this.checkWithMediator();
  62.          this.takeAction();
  63.       }
  64.    }
  65.  
  66.    public synchronized void checkWithMediator() {
  67.       int index = Mediator.theNumber;
  68.       if (index < 10) {
  69.          this.label = "Isn't Visual Caf├⌐ great?";
  70.       } else if (index <= 20 && index >= 10) {
  71.          this.label = "The Visual Caf├⌐ compiler is sooo FAST!";
  72.       } else if (index <= 30 && index > 20) {
  73.          this.label = "Check out the snazzy class editor.";
  74.       } else if (index <= 40 && index > 30) {
  75.          this.label = "Debugging in Visual Caf├⌐ is easy.";
  76.       } else if (index <= 50 && index > 40) {
  77.          this.label = "Visual Caf├⌐ is Great!";
  78.       } else if (index <= 60 && index > 50) {
  79.          this.label = "What do you mean by that?";
  80.       } else if (index <= 70 && index > 60) {
  81.          this.label = "I want to make sure you use Visual Caf├⌐.";
  82.       } else if (index <= 80 && index > 70) {
  83.          this.label = "Isn't that the truth";
  84.       } else if (index <= 90 && index > 80) {
  85.          this.label = "Wow, really!!!";
  86.       } else if (index <= 100 && index > 90) {
  87.          this.label = "That's very cool";
  88.       }
  89.  
  90.       this.myMediator.setClientTalk(this.label);
  91.       this.response = this.myMediator.getDeveloperTalk();
  92.    }
  93.  
  94.    public void takeAction() {
  95.       this.clientTalk.setText(this.label);
  96.       this.developerTalk.setText(this.response);
  97.    }
  98. }
  99.