Problems with GUI working properly
Message for Riaan,
I'm getting the same results.
Here is the top where I added the array list:
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.util.*;
import java.io.*;
import java.util.List;
public class FVolume extends JFrame implements ActionListener{
private JTabbedPane jtabbedPane;
private JPanel Customers;
private List<Customer> customers = new ArrayList开发者_如何学JAVA<Customer>();
JTextArea NameTextCustomers, ExistTextCustomers, NameTextContractors, ExistTextContractors;
Now here is where I changed the actionListener
AddCustomers.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
Customers.add(new Customer("Customer"));
}
});
The simplest option would probably be to add a List field:
public class FVolume extends JFrame implements ActionListener{
private JTabbedPane jtabbedPane;
private JPanel Customers;
private List<Customer> customers = new ArrayList<Customer>();
...
Then change your actionListener to this:
AddCustomers.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
customers.add(new Customer("Customer"));
}
});
With this list you can now simply clear the text area and display the customers from this list when the refresh button is pressed.
A better way would be to use a JDialog for the customer popup (and not to pop it up from the Customer constructor) and then register a listener on the dialog to just notify the main app when a new customer has been saved. Then just add the new customer to the text area (No refresh button needed then). This is a bit more involved though, as you'd need to fire a PropertyChangeEventfrom the Customer dialog on saving (Among other changes you'd need to make).
精彩评论