
October 29th, 2006, 07:12 AM
|
Registered User
|
|
Join Date: Oct 2006
Posts: 1
Time spent in forums: 48 m 20 sec
Reputation Power: 0
|
|
A Way to use an ItemEvent inside an ActionEvent?
Is there a way I can use an ItemEvent inside an ActionEvent?
so i can ahve an if statement in there suhc as;
if ((aPsource == btnRaise)&&(newcomboList == "Employee 1"))
WHat I am trying to do is give the 2 different Employees in the combo box raises. I want it so IF i select Employee 1 from combo box and hit raise it will give that employee a raise, then IF I select Employee 2 from the combobox it will give them a raise and set that value to the textbox.
===========
public void actionPerformed(ActionEvent aP){
Object aPsource = aP.getSource();
if (aPsource == btnRaise){
///// Employee 1 Raise //////
if ((Emp1.raisecnt == 0)&&(2006 - Emp1.getHireYear()) > 3){
hireYear = Emp1.getHireYear();
Emp1numsal = Emp1.getSalary();
Emp1newnumsal = Emp1.raiseSalary(Emp1numsal,hireYear);
Emp1Salary = twodp.format(Emp1newnumsal);
txtSalary.setText(Emp1Salary);
JOptionPane.showMessageDialog(null,"50% Raise Given","Raise",JOptionPane.WARNING_MESSAGE);
}
else if (((Emp1.raisecnt == 0)&&(2006 - Emp1.getHireYear()) < 3)){
JOptionPane.showMessageDialog(null,"No Raise Needed","No Raise",JOptionPane.WARNING_MESSAGE);
}
if (Emp1.raisecnt > 0){
JOptionPane.showMessageDialog(null,"Already Had Raise","No Cheating",JOptionPane.WARNING_MESSAGE);
}
Emp1.raisecnt++;
}
The code above is for an Action Event for a button called "btnRaise"
===============================
public void itemStateChanged(ItemEvent e){
Object source = e.getSource();
if(source == empList){
Object newempList = e.getItem();
if (newempList == "Martin Trebacz"){
txtHireYear.setText(Integer.toString(Emp1.getHireY ear()));
txtSalary.setText(Double.toString(Emp1.getSalary() ));
}
else if (newempList == "Sarah Madison"){
txtHireYear.setText(Integer.toString(Emp2.getHireY ear()));
txtSalary.setText(Double.toString(Emp2.getSalary() ));
}
that code above is for an Item Event, so if i select a particular employee it will set certain values to the txtBox.
New to Java so hope what I explained above is clear =/
|