swing2.l (799B)
1 # http://www.java2s.com/Code/Java/Language-Basics/InvokemethodthroughJavaReflectionAPI.htm 2 3 (load "swing.l") 4 5 (setq F (jnew JFrame "Command Test")) 6 (setq B1 (jnew JButton "Tick")) 7 (setq B2 (jnew JButton "Tock")) 8 (setq B3 (jnew JButton "Quit")) 9 (setq L (jnew JLabel "Hello world")) 10 (setq C (F 'getContentPane)) 11 12 (C 'setLayout (jnew BorderLayout)) 13 (C 'add B1 (jfield BorderLayout 'WEST)) 14 (C 'add B2 (jfield BorderLayout 'EAST)) 15 (C 'add B3 (jfield BorderLayout 'NORTH)) 16 (C 'add L (jfield BorderLayout 'SOUTH)) 17 18 (de b1 @ (L 'setText (pack "tick " (str (rest))))) 19 (de b2 @ (L 'setText (pack "tock " (str (rest))))) 20 21 (B1 'addActionListener (jproxy NIL 'b1 ActionListener)) 22 (B2 'addActionListener (jproxy T 'b2 ActionListener)) 23 (B3 'addActionListener (jproxy NIL 'bye ActionListener)) 24 25 (F 'pack) 26 (F 'show)