《Java2图形设计卷II:Swing》配套光盘源码
源代码在线查看: test.java
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Test extends JApplet {
private JButton button = new JButton("show dialog ...");
private String message = "Please Enter Your Name";
public Test() {
Container contentPane = getContentPane();
contentPane.setLayout(new FlowLayout());
contentPane.add(button);
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String s = JOptionPane.showInputDialog(message);
if(s == null)
showStatus("cancel button activated");
else
showStatus("Name: " + s);
}
});
}
}