《Java2图形设计卷II:Swing》配套光盘源码
源代码在线查看: test.java
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Test extends JApplet {
int clickDuration = 68;
public Test() {
Container contentPane = getContentPane();
JPanel controlPanel = new JPanel();
JPanel buttonPanel = new JPanel();
JButton doClick = new JButton("do click");
final JButton clickMe = new JButton("click me");
final JComboBox comboBox = new JComboBox(new Object[] {
"68", "250", "500", "750", "1000"
});
controlPanel.add(new JLabel("Click Duration:"));
controlPanel.add(comboBox);
buttonPanel.add(doClick);
buttonPanel.add(clickMe);
contentPane.add(controlPanel, BorderLayout.NORTH);
contentPane.add(buttonPanel, BorderLayout.CENTER);
getRootPane().setDefaultButton(doClick);
doClick.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
clickMe.doClick(clickDuration);
}
});
comboBox.addItemListener(new ItemListener() {
public void itemStateChanged(ItemEvent e) {
if(e.getStateChange() == ItemEvent.SELECTED) {
clickDuration = Integer.parseInt((String)
comboBox.getSelectedItem());
}
}
});
}
}