呵呵,越学越糊涂了,关于内部类访问外部对象不是要声明为final但是下面的程序却能
import javax.swing.*;import java.awt.*;
import java.awt.event.*;
class X{
StringBuffer x=StringBuffer("sdfsdklfjsadklfjsdklj");
public X(){
JFrame f=new JFrame();
JTextArea t=new JTextArea(10,20);
JButton b=new JButton("连接");
JScrollPane s=new JScrollPane(t);
t.setText("ljfklsdjfkl");
t.setLineWrap(true);
s.getVerticalScrollBar().setValue(s.getVerticalScrollBar().getMinimum());
System.out.println(s.getVerticalScrollBar().getMaximum());
b.requestFocus(true);
b.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
System.out.println(x);
}
}
);
f.getContentPane().add(s);
f.getContentPane().add(b,BorderLayout.SOUTH);
f.setSize(100,200);
f.setVisible(true);
}
public static void main(String[] args){
new X();
}
}