interface ICommand { void execute(int x); } class Client { ICommand c; void setCommand(ICommand c) { this.c = c; } void run(int i){ // Math.random() returns a double between >=0.0 and < 1.0 int j = (int) (10.0*Math.random()); if(i > j) { System.out.println(i+" > "+j); c.execute(j); } else { System.out.println(i+" < "+j); } } } class Command1 implements ICommand { public void execute(int x) { System.out.println("Yahoo! " + x); } } class Command2 implements ICommand { public void execute(int x) { System.out.println("Mamma mia!" + x); } } class CommandFrame extends javax.swing.JFrame implements ICommand { public void execute(int x) { int y = 100*x; // will need this value many times setTitle("The frame is "+y+" x "+y+" pixels"); // sets the title of the frame setSize(y,y); // sets the size of the square frame show(); // show the frame if not visible } } class PhraseMaker { void phrase1() { System.out.println("Java: More fun under the Sun."); } void phrase2() { System.out.println("C#: Bill G's vision when he gets old?"); } } class Command3 implements ICommand { ICommand c1, c2; Command3(ICommand c1, ICommand c2) { this.c1 = c1; this.c2 = c2; } public void execute(int x) { c1.execute(x); c2.execute(x); } } class Command4 implements ICommand { PhraseMaker p; Command4(PhraseMaker p) { this.p = p; } public void execute(int x) { p.phrase1(); } } class Command5 implements ICommand { PhraseMaker p; Command5(PhraseMaker p) { this.p = p; } public void execute(int x) { p.phrase2(); } }