Java Reference
In-Depth Information
}
return EmpNumCh;
}
public void itemStateChanged(ItemEvent arg0) {
empNum = EmpNumCh.getSelectedItem();
System.out.println("We are getting ready to " +
txType + " emp num " + empNum);
this .dispose();
}
}
Notice that EmpNumFrame's constructor is expecting a String variable. The function specified by the user
on EmpOptions (update or display) must be passed to EmpNumFrame. This is because if display is selected,
EmpNumFrame will create an EmployeeFrame object, but if update is specified, an EnterEmpInfo object will be
created. Later we will modify the itemStateChanged method to do this. For now, itemStateChanged will help us test by
simply displaying the employee number specified and the function.
In addition, notice that itemStateChanged deletes the EmpNumFrame object (the dispose statement does this).
This means that after the user has specified the employee number, the frame will disappear.
12.
Copy Tutorials/c10.AppOptions and name the new class EmpOptions.
13.
Open EmpOptions with the Visual Editor and change the name and text of the check boxes
to the following:
insEmpCB Insert Employee Information
dispEmpCB Display Employee Information
updEmpCB Update Employee Information
14.
Resize and reposition the check boxes so all the text is displayed and they appear as in
Figure 10-11 .
15.
Change the EmpOptions title to “ Employee Application Menu .”
16.
Change the EmpOptions ItemStateChanged method to the following:
if (insEmpCB.getState()) {
EnterEmpInfo eei = new EnterEmpInfo();}
else if (dispEmpCB.getState()){
EmpNumFrame enf = new EmpNumFrame ("display");}
else if (updEmpCB.getState()){
EmpNumFrame enf =
new EmpNumFrame ("update");}
Notice that EmpNumFrame is only created if the function display or update is chosen and that the function
is passed to EmpNumFrame. If insert is selected, the EnterEmpInfo frame is displayed. Now we need to change
AppOptions so that it will display EmpOptions.
17.
In the AppOptions ItemStateChanged method, change the following:
if (empAppCB.getState()) {
EnterEmpInfo eei = new EnterEmpInfo();}
 
Search WWH ::




Custom Search