在JAVA中如何获取文本框中输入的值,并保存在一个文件之中。具体代码如下:
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.ERR