åèä¸é¢ä»£ç ï¼
import java.io.*;
import javax.swing.*;
import java.awt.FlowLayout;
import java.awt.event.*;
public class WriterTo extends JFrame implements ActionListener{
JButton b;JTextField t;
public WriterTo(){
super("ææ¬æ¡å
容åå
¥æ件");
JLabel l=new JLabel("请è¾å
¥å
容ï¼");
t=new JTextField(20);
b=new JButton("åå
¥");
b.addActionListener(this);
this.add(l);
this.add(t);
this.add(b);
this.setLayout(new FlowLayout());
this.pack();
this.setVisible(true);
}
public void actionPerformed(ActionEvent e) {
if(e.getSource()==b){
if(t.getText().equals("")){
JOptionPane.showMessageDialog(null,"请è¾å
¥å
容~","é误",JOptionPane.ERROR_MESSAGE);
t.grabFocus();
}else{
write(t.getText());
JOptionPane.showMessageDialog(null,"åå
¥æå","æ示",JOptionPane.INFORMATION_MESSAGE);
}
}
}
public void write(String line){
try{
File f=new File("c:/ææ¬æ¡.txt");//åæå®ææ¬æ¡å
åå
¥
FileWriter fw=new FileWriter(f);
fw.write(line);
fw.close();
}catch(Exception e){
}
}
public static void main(String[] args) {
new WriterTo();
}
}