简体   繁体   English

GUI正常工作的问题

[英]Problems with GUI working properly

Message for Riaan, 给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<Customer>();
    JTextArea NameTextCustomers, ExistTextCustomers, NameTextContractors, ExistTextContractors;

Now here is where I changed the actionListener 现在这是我更改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: 最简单的选择可能是添加一个List字段:

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: 然后将您的actionListener更改为:

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. 更好的方法是将JDialog用于客户弹出窗口(而不是从Customer构造函数弹出),然后在对话框中注册一个侦听器,以在保存新客户时通知主应用程序。 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). 但是,这涉及的更多,因为您需要在保存时从“客户”对话框中触发PropertyChangeEvent(在其他更改中)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM