source: branches/1.1.x/examples/gui/awt/ActionListener.java

Last change on this file was 12731, checked in by Mark Evenson, 14 years ago

Move unused GUI code to examples hierarchy.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 2.8 KB
Line 
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
21package awt;
22
23import org.armedbear.lisp.JHandler;
24import java.awt.event.ActionEvent;
25import java.awt.Button;
26import java.awt.List;
27import java.awt.MenuItem;
28import java.awt.TextField;
29import javax.swing.AbstractButton;
30import javax.swing.JTextField;
31
32public class ActionListener implements java.awt.event.ActionListener 
33{
34    public void actionPerformed(ActionEvent actionevent) {
35        String 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 button) {
44        ActionListener actionlistener = new ActionListener();
45        actionlistener.handle = button;
46        button.addActionListener(actionlistener);
47    }
48
49    public static synchronized void addTo(List list) {
50        ActionListener actionlistener = new ActionListener();
51        actionlistener.handle = list;
52        list.addActionListener(actionlistener);
53    }
54
55    public static synchronized void addTo(MenuItem menuitem) {
56        ActionListener actionlistener = new ActionListener();
57        actionlistener.handle = menuitem;
58        menuitem.addActionListener(actionlistener);
59    }
60
61    public static synchronized void addTo(TextField 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 ab) {
71        ActionListener actionlistener = new ActionListener();
72        actionlistener.handle = ab;
73        ab.addActionListener(actionlistener);
74    }
75
76    public static synchronized void addTo(JTextField textfield) {
77        ActionListener actionlistener = new ActionListener();
78        actionlistener.handle = textfield;
79        textfield.addActionListener(actionlistener);
80    }
81
82    private Object handle;
83}
Note: See TracBrowser for help on using the repository browser.