import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.*;
import javax.swing.*;
public class Ftest extends Jframe {
private static final long serialVersionUID=1L;
private JPanel jContentPane=null;
private Jtextarea jtextarea=null;
private JPanel controlPanel=null;
private JButton openButton=null;
private JButton closeButton =null;
private JButton getOpenButton(){
if(openButton==null){
openButton=new JButton();
openButton.addActionListener(new ActionListener(){
public void actionPerformed (ActionEvent e){
File file =new File("word.txt");
try{
FileWriter out =new FileWriter(file);
String s=jtextarea.getText();
out.write(s);
out.close();
}catch (Exception e1){
e1.printStackTrace();
}
}
});
}
return openButton;
}
private JButton getCloseButton(){
if(closeButton==null){
closeButton=new JButton();
closeButton.setText("读取文件");
closeButton.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
File file =new File("word.txt");
try{
FileReader in =new FileReader(file);
char byt[]=new char[1024];
int len =in.read(byt);
jtextarea.setText(new String(byt,0,len));
in.close();
}catch(Exception e1){
e1.printStackTrace();
}
}
});
}
return closeButton;
}
public Ftest(){
super();
initialize();
}
private void initialize(){
this.setSize(300,200);
this.setContentPane(getContentPane());
this.setTitle("Jframe");
}
private JPanel getJContentPane(){
if(jContentPane==null){
jContentPane=new JPanel();
jContentPane.setLayout(new BorderLayout());
jContentPane.add(getJtextarea(),BorderLayout.CENTER);
jContentPane.add(getControlPanel(),BorderLayout.SOUTH);
}
return jContentPane;
}
private Component getControlPanel() {
// TODO 自动生成的方法存根
return null;
}
private Component getJtextarea() {
// TODO 自动生成的方法存根
return null;
}
public static void main(String[] args) {
// TODO 自动生成的方法存根
Ftest thisClass=new Ftest();
thisClass.setDefaultCloseOperation(Jframe.EXIT_ON_CLOSE);
thisClass.setVisible(true);
}
}