Ewe*_*wen 4 java swing jframe actionlistener
继承人我想做的事情,其中一个类是包含所有JButtons的JFrame,我想要另一个类来监听在JFrame类上进行的操作.请参阅以下代码:
public class Frame extends JFrame{
//all the jcomponents in here
}
public class listener implements ActionListener{
//listen to the actions made by the Frame class
}
Run Code Online (Sandbox Code Playgroud)
谢谢你的时间.
只需将侦听器的新实例添加到要侦听的任何组件即可.任何实现的类ActionListener
都可以添加为组件的侦听器.
public class Frame extends JFrame {
JButton testButton;
public Frame() {
testButton = new JButton();
testButton.addActionListener(new listener());
this.add(testButton);
}
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
13017 次 |
最近记录: |