日期:2014-05-20  浏览次数:20884 次

有谁能告诉我最后一句是什么意思啊?谢谢大哥们了
有谁能告诉我最后一句w.validate();是什么意思啊,以前没遇上过?谢谢大哥们了
import   java.io.*;
import   java.awt.*;
import   java.awt.event.*;
class   EWindow   extends   Frame   implements   ActionListener
{
TextArea   text;
Button   buttonRead,buttonWrite;
BufferedReader   bufferIn;
FileReader   in;
BufferedWriter   bufferOut;
FileWriter   out;
EWindow   ()
{
super( "流的读取 ");
text=new   TextArea(10,10);
buttonRead=new   Button( "读取 ");
buttonRead.addActionListener(this);
buttonWrite=new   Button( "写出 ");
buttonWrite.addActionListener(this);
setLayout(new   BorderLayout());
setSize(340,340);
setVisible(true);
add(text,BorderLayout.CENTER);
Panel   pNorth=new   Panel();
pNorth.add(buttonRead);
pNorth.add(buttonWrite);
pNorth.validate();
add(BorderLayout.NORTH,pNorth);
addWindowListener(new   WindowAdapter()
{
public   void   windowClosing(WindowEvent   e)
{
System.exit(0);
}
});
}
public   void   actionPerformed(ActionEvent   e)
{
String   s;
if(e.getSource()==buttonRead)
{
try{
text.setText(null);
File   f=new   File( "F:\\java ", "file.txt ");
in=new   FileReader(f);
bufferIn=new   BufferedReader(in);
while((s=bufferIn.readLine())!=null)
{
text.append(s);
}
bufferIn.close();
in.close();
}
catch(IOException   exp)
{
System.out.println(exp);
}
}
if(e.getSource()==buttonWrite)
{
try{
File   f=new   File( "F:\\java ", "file.txt ");
out=new   FileWriter(f);
bufferOut=new   BufferedWriter(out);
bufferOut.write(text.getText(),0,(text.getText()).length());
bufferOut.flush();
bufferOut.close();
out.close();
}
catch(IOException   exp)
{
System.out.println(exp);
}
}
}
}
public   class   file10
{
public   static   void   main(String   args[])
{
EWindow   w=new   EWindow();
w.validate();
}
}

------解决方案--------------------
public void validate() 窗口调用该方法可以确保当前窗口中添加的组件能显示出来。窗口初始出现时有可能看不到窗口中的组件,当用户调整窗口大小时才能看到这些组件。调用了这个方法就不会发生这种情况