What is the name of the method that receives ActionEvents when a Button is clicked?

Eine gute Antwort könnte sein:

actionPerformed( ActionEvent e )

More on actionPerformed( )

Here the actionPerformed() method from the example program:

public class ButtonDemo2 extends JFrame implements ActionListener
{
  . . . .

  public void actionPerformed( ActionEvent evt)
  {
    getContentPane().setBackground( Color.blue );
    repaint();
  }

  . . . .
}

The parameter evt is a reference to an ActionEvent object. When the button is clicked, an event object is sent to the method. Our method does not use the information in the ActionEvent object it receives, but the information is available.

Usually actionPerformed() does something more significant than it does in this program. Most useful programs have some application code (as well as GUI components and event listeners.) Often various sections of the application code are activated with button clicks. In a real application, the method might look something like this:

  public void actionPerformed( ActionEvent evt)
  {

    // look at information in the ActionEvent

    // invoke a method depending on the information

    // send the results of that method to another GUI component
  }

FRAGE 17:

Is it clear how...

... are all related?

Inhaltsverzeichnis