1 public class Application extends tkjava.Frame { 2 private tkjava.Button QUIT, hiThere; 3 4 public Application() { 5 super(); 6 this.pack(); 7 this.createWidgets(); 8 } 9 10 public void sayHello() { 11 System.out.println("hi there, everyone!"); 12 } 13 14 public void createWidgets() { 15 16 // Instead of just getting tkjava.Frame.quit or even this.quit... 17 18 Class[] empty = new Class[0]; 19 java.lang.reflect.Method quit = null, sayHello = null; 20 try { 21 quit = this.getClass().getMethod("quit", empty); 22 sayHello = this.getClass().getMethod("sayHello", empty); 23 } catch (NoSuchMethodException exc) { 24 // Methods remain as null -> None and will cause runtime errors. 25 } 26 27 this.QUIT = new tkjava.Button(this); 28 this.QUIT.__setitem__("text", "QUIT"); 29 this.QUIT.__setitem__("fg", "red"); 30 this.QUIT.__setitem__("command", quit); 31 this.QUIT.pack(); 32 this.hiThere = new tkjava.Button(this); 33 this.hiThere.__setitem__("text", "Hello"); 34 this.hiThere.__setitem__("command", sayHello); 35 this.hiThere.pack(); 36 } 37 38 public static void main(String[] args) { 39 Application app = new Application(); 40 app.mainloop(); 41 } 42 }