Hello.
I'm using TreeMap for a collection.
In a single source file named App.java, there is an Employee class to encapsulate employee data and an App class defining an
applet to maintain a collection of Employee objects.
private instance variables for name(
string) and pay rate (double) are in the Employee class.
There is an Add button.
I want to triggers the construction of an Employee object having the currently displayed name and pay rate and the addition of the object to the collection when clicking 'Add' button.
The following is the part of my code.
<CODE>
SortedMap m = new TreeMap();
addBtn = new Button ("Add");
addBtn.setBackground(Color.red);
addBtn.setForeground(Color.black);
addBtn.addActionListener(
new ActionListener() {
public void actionPerformed (ActionEvent e){
// check to see if name field is empty or not.
if (e.getSource().equals(nameField)){
if ((nameField.getText()).equals("")){
msg.setText ("Please Enter an Employee Name");
}}
// check to see if name field is empty or not.
if (e.getSource().equals(payRateField)){
if ((payRateField.getText()).equals("")){
msg.setText ("Please Enter a Pay Rate");
}}
// check to see if the name is already in the collection or not.
// If it's not in the collection, add the record.
if (m.containsKey(nameField.getText())){
msg.setText ("The employee is already in our collection");
}
else {
// add the employee record.
m.put(name, new String(setName));
}
</CODE>
This is not working at all.
I would appreciate any suggestion/help/advice.
Thank you very much in advance.