
October 3rd, 2006, 01:51 PM
|
|
Contributing User
|
|
Join Date: Nov 2005
Posts: 91
Time spent in forums: 1 Day 1 h 27 m 20 sec
Reputation Power: 3
|
|
|
ActionListener + ItemListener ?
i have a JComboBox along with buttons.addActionListener.
i have the action listener attatched to two buttons already and i am trying to attatch an item listener to my JComboBox, is this possible when i already have an action listner ?.. when i try to implement them both it gives me a missing open curly bracket bug '{'
Code:
class Payroll extends JPanel implements ActionListener implements ItemListener
{
......
}
would i be able to implement both in the class ?
or can i attatch the JComboBox with the actionlistener and just code it in the Actionperformed method ?
Code:
JComboBox cb = new JComboBox();
cb.addActionListener();
public void ActionPerformed(ActionEven evt)
{
if (evt.getSource() == compute)
{
hours_worked = ((Number)hourField.getValue()).intValue();
payRate = ((Number)payfield.getValue()).doubleValue();
dependants = ((Number)depField.getValue()).intValue();
double grossPay = computeGross(payRate, hours_worked, over_time);
GrossField.setValue(new Double(grossPay));
double fed = computeFed(grossPay,fedRate);
fedField.setValue(new Double(fed));
double heal = computeHealth(grossPay, dependants);
healthField.setValue(new Double(heal));
double fc = computeFica(grossPay, max_tax);
ficaField.setValue(new Double(fc));
double nf = computeNetPay(grossPay, fed, heal, fc);
netField.setValue(new Double(nf));
}
else if(evt.getSource() == clear)
{
nameField.setValue(" ");
hourField.setValue(0);
payfield.setValue(0);
depField.setValue(0);
GrossField.setValue(0);
fedField.setValue(0);
healthField.setValue(0);
ficaField.setValue(0);
netField.setValue(0);
}
else if(evt.getSource() == NoPanel)
{
dependants = 0;
depField.setEditable(false);
}
}
}
my question is can i use cb.addActionListener(this);
and write an if statement inside there that recognizes the JComboBox status change ? or do i need another event method ?
|