home *** CD-ROM | disk | FTP | other *** search
- import java.applet.Applet;
- import java.awt.Container;
- import java.awt.Label;
- import java.awt.LayoutManager;
- import java.awt.Panel;
- import java.awt.TextField;
-
- public class Client extends Applet implements Runnable {
- Mediator myMediator;
- String label;
- String response;
- int theNumber;
- Thread clientThread;
- TextField clientTalk;
- Label client;
- Label top;
- Label developer;
- TextField developerTalk;
-
- public void init() {
- this.myMediator = new Mediator();
- ((Container)this).setLayout((LayoutManager)null);
- ((Panel)this).addNotify();
- ((Applet)this).resize(448, 110);
- this.clientTalk = new TextField(18);
- this.clientTalk.setEditable(false);
- this.clientTalk.reshape(170, 38, 268, 24);
- ((Container)this).add(this.clientTalk);
- this.client = new Label("Client says:");
- this.client.reshape(0, 35, 80, 24);
- ((Container)this).add(this.client);
- this.top = new Label("I'm a Client");
- this.top.reshape(0, 0, 89, 24);
- ((Container)this).add(this.top);
- this.developer = new Label("The Developer just said:");
- this.developer.reshape(0, 70, 153, 24);
- ((Container)this).add(this.developer);
- this.developerTalk = new TextField(17);
- this.developerTalk.setEditable(false);
- this.developerTalk.reshape(170, 68, 268, 24);
- ((Container)this).add(this.developerTalk);
- }
-
- public void start() {
- this.clientThread = new Thread(this);
- this.clientThread.start();
- }
-
- public void run() {
- Thread clientThread = Thread.currentThread();
-
- while(true) {
- try {
- Thread.sleep(2000L);
- } catch (Exception e) {
- System.out.println(e);
- }
-
- Mediator.oldNumber = Mediator.theNumber;
- Mediator.theNumber = this.myMediator.genRandom();
- this.checkWithMediator();
- this.takeAction();
- }
- }
-
- public synchronized void checkWithMediator() {
- int index = Mediator.theNumber;
- if (index < 10) {
- this.label = "Isn't Visual Café great?";
- } else if (index <= 20 && index >= 10) {
- this.label = "The Visual Café compiler is sooo FAST!";
- } else if (index <= 30 && index > 20) {
- this.label = "Check out the snazzy class editor.";
- } else if (index <= 40 && index > 30) {
- this.label = "Debugging in Visual Café is easy.";
- } else if (index <= 50 && index > 40) {
- this.label = "Visual Café is Great!";
- } else if (index <= 60 && index > 50) {
- this.label = "What do you mean by that?";
- } else if (index <= 70 && index > 60) {
- this.label = "I want to make sure you use Visual Café.";
- } else if (index <= 80 && index > 70) {
- this.label = "Isn't that the truth";
- } else if (index <= 90 && index > 80) {
- this.label = "Wow, really!!!";
- } else if (index <= 100 && index > 90) {
- this.label = "That's very cool";
- }
-
- this.myMediator.setClientTalk(this.label);
- this.response = this.myMediator.getDeveloperTalk();
- }
-
- public void takeAction() {
- this.clientTalk.setText(this.label);
- this.developerTalk.setText(this.response);
- }
- }
-