LBoogie
asked on
JList List Selection Listener
Hello all,
I am working on a project for my java class that is GUI based. Its basically a bank application. There are two JLists on the GUI, one holds customers, and the other holds the accounts associated with the customer that is selected in the customer JList. I know I have to have the ListSelectionListener, and I need it on both of the JLists. I have to keep track of the current customer selected, and the current account that is selected. So I do need the listeners for both of these JLists correct? But when I have both of the JLists have listeners, I just got a bunch of dispatch errors and it looks like it selects an account item in some kind of loop and then terminates my program. I am confused. I have written the valueChanged(ListSelection Event e) as the following:
public void valueChanged(ListSelection Event e)
{
Object selectedData = ((JList)e.getSource()).get SelectedVa lue();
if(selectedData != null)
{
//Get the number of the customer selected in the list
StringTokenizer st = new StringTokenizer(selectedDa ta.toStrin g());
int custNum = Integer.parseInt(st.nextTo ken());
//Set the current customer and show their accounts
currentCustomer = theBank.getCustomer(custNu m);
accountList.setListData(cu rrentCusto mer.getTot alAccountI nfo());
accountList.setSelectedInd ex(0);
if(accountList.getModel(). getSize() > 0)
{
//Get the account number of the account selected in the list
StringTokenizer st2 = new StringTokenizer(accountLis t.getSelec tedValue() .toString( ));
int acctNum = Integer.parseInt(st2.nextT oken());
currentAccount = currentCustomer.locateAcco unt(acctNu m);
}
else
{
currentAccount = null;
}
}
System.out.println(current Customer);
System.out.println(current Account);
}
So my problem is that I need to get the current selected account. The current customer part works fine, but when I added the account list listener, it went crazy. I can send the whole code as well, but I think the problem lies within this code.
Thanks in advance!
I am working on a project for my java class that is GUI based. Its basically a bank application. There are two JLists on the GUI, one holds customers, and the other holds the accounts associated with the customer that is selected in the customer JList. I know I have to have the ListSelectionListener, and I need it on both of the JLists. I have to keep track of the current customer selected, and the current account that is selected. So I do need the listeners for both of these JLists correct? But when I have both of the JLists have listeners, I just got a bunch of dispatch errors and it looks like it selects an account item in some kind of loop and then terminates my program. I am confused. I have written the valueChanged(ListSelection
public void valueChanged(ListSelection
{
Object selectedData = ((JList)e.getSource()).get
if(selectedData != null)
{
//Get the number of the customer selected in the list
StringTokenizer st = new StringTokenizer(selectedDa
int custNum = Integer.parseInt(st.nextTo
//Set the current customer and show their accounts
currentCustomer = theBank.getCustomer(custNu
accountList.setListData(cu
accountList.setSelectedInd
if(accountList.getModel().
{
//Get the account number of the account selected in the list
StringTokenizer st2 = new StringTokenizer(accountLis
int acctNum = Integer.parseInt(st2.nextT
currentAccount = currentCustomer.locateAcco
}
else
{
currentAccount = null;
}
}
System.out.println(current
System.out.println(current
}
So my problem is that I need to get the current selected account. The current customer part works fine, but when I added the account list listener, it went crazy. I can send the whole code as well, but I think the problem lies within this code.
Thanks in advance!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Or just use different listeners for easch list
ASKER
jimmack,
That is what I needed. Thanks =)
That is what I needed. Thanks =)