I am making an inventory system that has the ability of saving the data in .txt format. The GUI has a delete button that gives one the ability of deleting a selected row in a jTable but fails to do so in the .txt file that the credentials were saved before the user deleted the selected row. The save button has successfully been able to replicate data from the JTable to the .txt file. Below is the save button and delete button codes respectively:-
//save button
JButton btnNewButton = new JButton("Save");
btnNewButton.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
}
});
btnNewButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.out.println("Clicked");
ProductObject prouct = new ProductObject(textField.getText(), textField_1.getText(),
Double.valueOf(textField_2.getText()), textField_3.getText());
products.add(prouct);
String id = textField.getText();
String Name = textField_1.getText();
String Quality = textField_2.getText();
String Cost = textField_3.getText();
populateTable();
try {
FileWriter Writer = new FileWriter("Product.txt", true);
Writer.write(""+id+""+Name+""+Quality+""+Cost);
Writer.write(System.getProperty("line.separator"));
Writer.close();
JOptionPane.showMessageDialog(null, "success");
}
catch(Exception r) {
JOptionPane.showMessageDialog(null, "Error");
}
}
});
//Delete Button
JButton btnNewButton_7 = new JButton("Delete");
btnNewButton_7.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
int i = table.getSelectedRow();
tableModel.removeRow(i);
}
});
btnNewButton_7.setBounds(10, 405, 114, 23);
contentPane.add(btnNewButton_7);
What additional code do I need to add to make the delete button to have the ability of reading the .txt file and make the necessary adjustments?