下面的程序,显示一个按钮和一个标签。每次点击按钮时,标签都将更新。
package hustspy;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class hello implements ActionListener {
private static String labelPrefix = "Number of button clicks: ";
private int numClicks = 0;
final JLabel label = new JLabel(labelPrefix + "0 ");
//Specify the look and feel to use. Valid values:
//null (use the default), "Metal", "System", "Motif", "GTK+"
final static String LOOKANDFEEL = "System";
public Component createComponents() {
JButton button = new JButton("I'm a Swing button!");
button.setMnemonic(KeyEvent.VK_I);
button.addActionListener(this);
label.setLabelFor(button);
/*
* An easy way to put spac