您的位置:寻梦网首页编程乐园Java天地Core JavaJava Lecture Notes

previous.gif
 (3087 bytes)

next.gif
 (2959 bytes)


Extend Index

Extend Page # 24

Listing of Listener1.java

// Swing implementation

import java.applet.Applet;

import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

public class Listener1 extends Applet implements ActionListener

{

public Listener1()

{

  super();

  Button myButton = new Button ("Click me!");

  add(myButton);

  myButton.addActionListener(this);

}

public void actionPerformed (ActionEvent e)

{

  // Do something here when the user clicks the button

  // display a window saying "ouch"

  // (JoptionPane is a 'Swing' component)

  JOptionPane.showMessageDialog(null, "ouch!");

}

} // class

Back to top

basicline.gif (170 bytes)