先上代码:
import java.awt.*;
import java.awt.event.*;
import java.io.*;
public class TextNot {
public static void main(String[] args) {
start();
}
static void start(){
final Frame f = new Frame("记事本");//我的问题就在这一行
MenuBar mb = new MenuBar();
Menu m = new Menu("文件");
Menu m1 = new Menu("编辑 ");
MenuItem open = new MenuItem("打开");
MenuItem esc = new MenuItem("退出");
final TextArea ta = new TextArea();//我的问题就在这一行
f.setVisible(true);
f.setBounds(400, 200, 500, 400);
f.addWindowListener(new MyWinLis());
f.setMenuBar(mb);
f.add(ta);
mb.add(m);
mb.add(m1);
m.add(open);
open.addActionListener(new ActionListener(){
public void actionPerformed (ActionEvent e) {
FileDialog fd = new FileDialog(f,"打开文件",FileDialog.LOAD);
//fd.setBounds(50, 50, 50, 50);
fd.show();
String fileName = fd.getFile();
String dir = fd.getDirectory();
System.out.println(fileName);
BufferedReader bf = null;
String tem ="";
try{
bf = new BufferedReader(new FileReader(dir+fileName));
ta.setText("");//在这一行提示的
while((tem = bf.readLine())!=null){
ta.append(tem+"\r\n");
}
} catch (Exception e1){
e1.printStackTrace();
}
}
});
}
}
class MyWinLis extends WindowAdapter{
public void windowClosing(WindowEvent e) {
System.exit(0);
}
}
问题:如果把Frame f和 TextArea ta声明前的final去掉以后为什么eclipse老是提示需要用final的变量?
|
|