import javax.swing.*;
import javax.swing.event.*;
public class NewGUIStuff{
public static void main(String args[]){
NewGUIStuff gui = new NewGUIStuff();
gui.go();
}
class handlesListListeners implements ListSelectionListener{
public void valueChanged(ListSelectionEvent lse){
list.setVisibleRowCount(4);
}
}
public void valueChanged(ListSelectionEvent lse){
}
public void go(){
JFrame frame = new JFrame();
JPanel panel = new JPanel();
JList list;
String[] aList = {"alpha","beta","gamma","delta","epsilon","zeta","eta","theta"};
list = new JList(aList);
list.addListSelectionListener(new handlesListListeners());
JScrollPane scroller = new JScrollPane(list);
scroller.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
scroller.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
frame.setContentPane(scroller);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(300,300);
frame.setVisible(true);
}
}
所以我的问题是如果内部类可以看到它们的外部类变量和对象,为什么内部类不能handlesListListeners
看到list
我在NewGUIStuff
外部类中创建的对象?