一个关于event.getActionCommand 的问题。
下面的一段程序中,if ("comboBoxChanged".equals(event.getActionCommand())) 中的comBoBoxChanged 是什么啊?为什么API中查不到?是一个事件吗?在什么地方能查到呢?如果是一个事件的话,就是说event.getActionCommand()返回的是一个string是吗?返回的是固定的string吗?预定义的?什么地方能找到关于这个的详细说明?谢谢。
// Create and the widgets to select and display the phases of the moon.
private void addWidgets() {
// Get the images and put them into an array of ImageIcon.
for (int i = 0; i < NUM_IMAGES; i++) {
String imageName = "images/image" + i + ".jpg";
System.out.println("getting image: " + imageName);
URL iconURL = ClassLoader.getSystemResource(imageName);
ImageIcon icon = new ImageIcon(iconURL);
images[i] = icon;
}
// Create label for displaying moon phase images and put a border around it.
phaseIconLabel = new JLabel();
phaseIconLabel.setHorizontalAlignment(JLabel.CENTER);
phaseIconLabel.setVerticalAlignment(JLabel.CENTER);
phaseIconLabel.setVerticalTextPosition(JLabel.CENTER);
phaseIconLabel.setHorizontalTextPosition(JLabel.CENTER);
phaseIconLabel.setBorder(BorderFactory.createCompoundBorder(
BorderFactory.createLoweredBevelBorder(),
BorderFactory.createEmptyBorder(5,5,5,5)));
phaseIconLabel.setBorder(BorderFactory.createCompoundBorder(
BorderFactory.createEmptyBorder(0,0,10,0),
phaseIconLabel.getBorder()));
// Create combo box with lunar phase choices.
String[] phases = { "New", "Waxing Crescent", "First Quarter",
"Waxing Gibbous", "Full", "Waning Gibbous",
"Third Quarter", "Waning Crescent" };
phaseChoices = new JComboBox(phases);
phaseChoices.setSelectedIndex(START_INDEX);
// Display the first image.
phaseIconLabel.setIcon(images[START_INDEX]);
phaseIconLabel.setText("");
// Add border around the select panel.
selectPanel.setBorder(BorderFactory.createCompoundBorder(
BorderFactory.createTitledBorder("Select Phase"),
BorderFactory.createEmptyBorder(5,5,5,5)));
// Add border around the display panel.
displayPanel.setBorder(BorderFactory.createCompoundBorder(
BorderFactory.createTitledBorder("Display Phase"),
BorderFactory.createEmptyBorder(5,5,5,5)));
// Add moon phases combo box to select panel and image label to displayPanel.
selectPanel.add(phaseChoices);
displayPanel.add(phaseIconLabel);
// Listen to events from combo box.
phaseChoices.addActionListener(this); // 问题在这里
}
// Implementation of ActionListener interface.
public void actionPerformed(ActionEvent event) {
if ("comboBoxChanged".equals(event.getActionCommand())) { //问题在这里
// update the icon to display the new phase
phaseIconLabel.setIcon(images[phaseChoices.getSelectedIndex()]);
}
}