KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > armedbear > lisp > java > awt > ActionListener


1 /*
2  * ActionListener.java
3  *
4  * Copyright (C) 2003 Peter Graves
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19  */

20
21 package org.armedbear.lisp.java.awt;
22
23 import org.armedbear.lisp.JHandler;
24 import java.awt.event.ActionEvent JavaDoc;
25 import java.awt.Button JavaDoc;
26 import java.awt.List JavaDoc;
27 import java.awt.MenuItem JavaDoc;
28 import java.awt.TextField JavaDoc;
29 import javax.swing.AbstractButton JavaDoc;
30 import javax.swing.JTextField JavaDoc;
31
32 public class ActionListener implements java.awt.event.ActionListener JavaDoc
33 {
34     public void actionPerformed(ActionEvent JavaDoc actionevent) {
35         String JavaDoc as[] = { actionevent.paramString(), actionevent.getActionCommand() };
36         int ai[] = { actionevent.getModifiers() };
37     long al[] = { actionevent.getWhen() }; // not yet used
38
JHandler.callLisp("ACTIONPERFORMED", handle, as, ai);
39     }
40
41     //AWT
42

43     public static synchronized void addTo(Button JavaDoc button) {
44         ActionListener actionlistener = new ActionListener();
45         actionlistener.handle = button;
46         button.addActionListener(actionlistener);
47     }
48
49     public static synchronized void addTo(List JavaDoc list) {
50         ActionListener actionlistener = new ActionListener();
51         actionlistener.handle = list;
52         list.addActionListener(actionlistener);
53     }
54
55     public static synchronized void addTo(MenuItem JavaDoc menuitem) {
56         ActionListener actionlistener = new ActionListener();
57         actionlistener.handle = menuitem;
58         menuitem.addActionListener(actionlistener);
59     }
60
61     public static synchronized void addTo(TextField JavaDoc textfield) {
62         ActionListener actionlistener = new ActionListener();
63         actionlistener.handle = textfield;
64         textfield.addActionListener(actionlistener);
65     }
66
67     //Swing
68

69     //takes care of JButton, JMenuItem, JToggleButton etc.
70
public static synchronized void addTo(AbstractButton JavaDoc ab) {
71         ActionListener actionlistener = new ActionListener();
72         actionlistener.handle = ab;
73         ab.addActionListener(actionlistener);
74     }
75
76     public static synchronized void addTo(JTextField JavaDoc textfield) {
77         ActionListener actionlistener = new ActionListener();
78         actionlistener.handle = textfield;
79         textfield.addActionListener(actionlistener);
80     }
81
82     private Object JavaDoc handle;
83 }
84
Popular Tags