在Java代碼:的Java:創建時括號類名稱對象實例
// Define ActionListener
ActionListener actionListener = new ActionListener() {
public void actionPerformed(ActionEvent actionEvent) {
JButton button = **(JButton)actionEvent.getSource();**
int red = random.nextInt(255);
int green = random.nextInt(255);
int blue = random.nextInt(255);
button.setBackground(new Color(red, green, blue));
}
};
什麼是突出(**
和**
之間)的代碼嗎?
我發現很難研究這個問題,因爲我不知道使用什麼搜索術語。 :o
希望任何人都可以提供幫助。 TIA
你讀過['ActionEvent' javadoc](http://download.oracle.com/javase/6/docs/api/java/awt/event/ActionEvent.html)? 'getSource'上的javadoc表示它返回「事件最初發生的對象」。這似乎很清楚。你不明白的是什麼? – MarcoS 2011-05-31 09:28:03