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