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.TextField;
-
- public class Developer extends Applet implements Runnable {
- Mediator myMediator;
- String label;
- String response;
- int theNumber;
- Thread developerThread;
- Label top;
- Label developer;
- TextField developerTalk;
- Label client;
- TextField clientTalk;
-
- public void init() {
- this.myMediator = new Mediator();
- ((Container)this).setLayout((LayoutManager)null);
- ((Applet)this).resize(452, 110);
- this.top = new Label("I'm a Developer");
- this.top.reshape(0, 0, 113, 24);
- ((Container)this).add(this.top);
- this.developer = new Label("Developer says:");
- this.developer.reshape(0, 35, 109, 24);
- ((Container)this).add(this.developer);
- this.developerTalk = new TextField(18);
- this.developerTalk.setEditable(false);
- this.developerTalk.reshape(130, 36, 307, 24);
- ((Container)this).add(this.developerTalk);
- this.client = new Label("The Client just said:");
- this.client.reshape(0, 70, 126, 24);
- ((Container)this).add(this.client);
- this.clientTalk = new TextField(18);
- this.clientTalk.setEditable(false);
- this.clientTalk.reshape(130, 68, 309, 24);
- ((Container)this).add(this.clientTalk);
- }
-
- public void start() {
- this.developerThread = new Thread(this);
- this.developerThread.start();
- }
-
- public void run() {
- Thread developerThread = 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 = "Have you seen Visual Café?";
- } else if (index <= 20 && index >= 10) {
- this.label = "What's that?";
- } else if (index <= 30 && index > 20) {
- this.label = "Visual Café is Great!";
- } else if (index <= 40 && index > 30) {
- this.label = "Visual Café really helps.";
- } else if (index <= 50 && index > 40) {
- this.label = "I can make anything with Visual Café.";
- } else if (index <= 60 && index > 50) {
- this.label = "The Visual Café compiler is sooo FAST!";
- } else if (index <= 70 && index > 60) {
- this.label = "Debugging in Visual Café is easy.";
- } else if (index <= 80 && index > 70) {
- this.label = "I see where you're going";
- } else if (index <= 90 && index > 80) {
- this.label = "Check out the snazzy class editor.";
- } else if (index <= 100 && index > 90) {
- this.label = "Thank you!";
- }
-
- this.myMediator.setDeveloperTalk(this.label);
- this.response = this.myMediator.getClientTalk();
- }
-
- public void takeAction() {
- this.developerTalk.setText(this.label);
- this.clientTalk.setText(this.response);
- }
- }
-