Java从嵌套类返回
我有这个测试代码,我希望该方法在按下按钮时返回一个值。最好的办法是什么
public String test(){
JFrame frame=new JFrame();
frame.setSize(800,600);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
JButton button=new JButton("Click Me!");
frame.add(button);
}
我已经尝试添加一个ActionListener
,但是我看不到从父方法返回值的方法
button.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
//A return here would not work
}
});
# 1 楼答案
局部变量必须是
final
,但没有什么可以阻止它成为Collection
,然后可以修改它请看下面的代码