好的,首先......是的,这是一个功课问题.我被卡住了.我已经能够创建.txt文件并从GUI文本字段中保存数据.只要我不退出GUI,它就会继续添加到文件中.一旦我再次启动它,下次保存任何内容时整个文件都会被覆盖(单击GUI上的保存按钮).我想要做的是:
- 从GUI文本字段输入数据 - 单击保存按钮(创建文件并将数据附加到.txt文件) - 能够从文件读回到面板 - 能够关闭并重新打开GUI和根据需要附加.txt文件
我很亲近,但我担心我会做一些愚蠢的事情.下面是我的GUI,CreateTextFile和ReadTextFile的java代码
import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.SQLException;
import javax.swing.*;
public class DonorGUI extends JFrame
{
// Components
private JPanel panel;
private JTextArea results;
private JButton entryButton;
private JButton exitButton;
private JButton clearButton;
private JButton saveButton;
private JButton openButton;
private JTextField donorField;
private JTextField charityField;
private JTextField pledgeField;
//create variables
String[] donorName = new String[20];
String[] charityName = new String[20];
double[] donationAmt = new double[20];
int i = …Run Code Online (Sandbox Code Playgroud)