Java:创建对象实例时带括号的类名

1 java class object instance parentheses

在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));

    }
};
Run Code Online (Sandbox Code Playgroud)

突出显示的(之间****)代码有什么作用?

我发现研究这个主题非常困难,因为我不知道要使用哪些搜索术语.:○

希望有人可以提供帮助 TIA

Kev*_*vin 6

它的铸造返回的对象actionEvent.getSource()JButton.

您可以在这里这里阅读一些信息.