有谁能告诉我最后一句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();
}
}