Java Swing - O Reilly } public void mousePressed(MouseEvent (Sri lanka web server)
Java Swing - O Reilly } public void mousePressed(MouseEvent me) {} public void mouseReleased(MouseEvent me) {} public void mouseEntered(MouseEvent me) {} public void mouseExited(MouseEvent me) {} protected void fireActionPerformed(ActionEvent ae) { Object[] listeners = listenerList.getListenerList(); for (int i = listeners.length - 2; i >= 0; i–) { if (listeners[i] == ActionListener.class) { ((ActionListener)listeners[i+1]).actionPerformed(ae); } } } } Our addActionListener() and removeActionListener() methods just defer to a listener list to register and unregister listeners. We don’t have to do anything special to get an EventListenerList; we’re extending JLabel, and therefore inherit a listenerList field from JComponent. fireActionPerformed() does the actual work; it calls the actionPerformed() method of every action listener stored in the listener list. Note that we walk through the array of listeners two at a time; as we’ll see below, the elements in this array alternate between Class objects that tell us what kind of listener we have, and the actual listener objects themselves. Figure 27.4 shows how the array is set up. And here’s the application that creates the SecretLabel and hooks it up to the reporting label. We use the same addActionListener() that we would for things like buttons or lists: // SecretTest.java // A demonstration framework for the EventListenerList-enabled SecretLabel class. // import javax.swing.*; import java.awt.event.*; import java.awt.*; public class SecretTest extends JFrame { public SecretTest() { super(”EventListenerList Demo”); setSize(200, 100); addWindowListener(new BasicWindowMonitor()); SecretLabel secret = new SecretLabel(”Try Clicking Me”); final JLabel reporter = new JLabel(”Event reports will show here…”); secret.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { reporter.setText(”Got it: ” + ae.getActionCommand()); } } ); getContentPane().add(secret, BorderLayout.NORTH); getContentPane().add(reporter, BorderLayout.SOUTH); } public static void main(String args[]) { - 929
Please visit Domain Name Hosting services for high quality webhost to host and run your jsp applications.