pushbuttonapplet.java

来自「Java the UML Way 书中所有源码」· Java 代码 · 共 26 行

JAVA
26
字号
/*
 * PushbuttonApplet.java  E.L. 2001-08-18
 *
 */
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class PushbuttonApplet extends JApplet {
  public void init() {
    Container guiContainer = getContentPane();
    LayoutManager layout = new FlowLayout();
    guiContainer.setLayout(layout);

    JButton myButton = new JButton("Push here!!");  // creates the button
    guiContainer.add(myButton);  // puts it in the container
    ButtonListener theButtonListener = new ButtonListener(); // creates a listener
    myButton.addActionListener(theButtonListener); // links the listener to the button
  }
}

class ButtonListener implements ActionListener {
  public void actionPerformed(ActionEvent event) {
    System.out.println("You pushed the button!");
  }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?