Java Reference
In-Depth Information
Figure 5-11.
You should note a couple of things about this tutorial. The EnterEmpInfo's main method has been used as a
means to test the frame. Currently there is still no way to access the frame from the Employee application. Second,
the formatting of the gross salary value was very “coarse.” By this, we mean that manipulating a String object is very
limited, and only simple formatting can be done easily. For instance, if the number had been over a thousand dollars,
inserting the comma would have been much more difficult. Later in the text, we will cover some easier methods for
formatting common numeric information such as currency, dates, and times.
The “resultLbl code” in the initialize method should look like the following:
resultLbl = new Label();
resultLbl.setText("Label");
resultLbl.setAlignment(Label. CENTER );
resultLbl.setBounds( new Rectangle(75, 332, 250, 23));
The actionPerformed method should look like the following:
public void actionPerformed(ActionEvent e) {
String empPayRate = empPRTF.getText();
double doubleEmpPR, doubleGross;
doubleEmpPR = Double. parseDouble (empPayRate);
doubleGross = doubleEmpPR * 40;
this .add(resultLbl, null );
resultLbl.setText("The Gross Salary is: $" +
doubleGross + "0");
System. out .println(doubleGross);
}
Search WWH ::




Custom Search