473,405 Members | 2,300 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

code GUI class to add record to table

Hey all. My program reads from a file which contains information about employees(ID, name, address, salary, HourlyRate, etc...). It then stores them in an array of objects and writes and displays the info in a GUI where the ID is listed in a listbox, and the corresponding info about the employee is displayed when an ID is selected. I have a few problems but I will try to solve 1 at a time rather than posting em all at once.
My 1st problem is that I've created an initial method for the add employee button in a seperate class called EmployeeList but I'm still alittle confused as what to write in the GUI class. I will post the relevant code. Any help would be much appreciated as this is my last assignment of the semester and I have exams which reduce the amount of time I can dedicate to this assignment.I'm a little nervy as I need to complete this to pass the unit. Thanks.
Jun 5 '07 #1
14 4592
Expand|Select|Wrap|Line Numbers
  1.  
  2. import java.io.*; 
  3. import java.util.*;
  4.  
  5.  
  6. public class EmployeeList
  7. {
  8. public static int MaxEmp=100; 
  9. private EmpFileReader fileReader;
  10. private Employee[] employee;
  11. private int noOfemp;
  12. private int index; 
  13.  
  14.  
  15.  
  16. public EmployeeList() throws FileNotFoundException, IOException
  17. {
  18. employee = new Employee[MaxEmp];
  19. fileReader = new EmpFileReader(employee);
  20. noOfemp = fileReader.getRecCount();
  21. sort();
  22. }
  23.  
  24. public void addEmployee(Employee employeeType)
  25. {
  26. employee[noOfemp] = employeeType;
  27. noOfemp++;
  28. }
  29.  
  30. public void addVol(String name, String address, String empId)
  31. {
  32. Volunteer vol = new Volunteer(name, address, empId);
  33. vol.setName(name);
  34. vol.setAddress(address);
  35. vol.setEmpId(empId);
  36.  
  37. employee[noOfemp] = vol;
  38.  
  39. }
  40.  
  41. public void addPartSal(String name, String address, String empId, float noOfHours, float hourlyRate )
  42. {
  43. PartTimeEmp part = new PartTimeEmp(name, address, empId, noOfHours, hourlyRate);
  44. part.setName(name);
  45. part.setAddress(address);
  46. part.setEmpId(empId);
  47. part.calcPay(noOfHours, hourlyRate);
  48. employee[noOfemp] = part;
  49.  
  50. }
  51.  
  52. public void addSal(String name,String address, String empId, float salary, String date)
  53. {
  54. SalariedEmp sal = new SalariedEmp(name, address, empId, salary, date);
  55. sal.setName(name);
  56. sal.setAddress(address);
  57. sal.setEmpId(empId);
  58. sal.toSal();
  59. sal.toDate();
  60. employee[noOfemp] = sal;
  61. }
  62.  
NB: Sorry I forgot to mention this but the employees are separated into 3 types and only contain certain information:
Part Time Employee
(Name, address, employee ID, pay rate, number of hrs worked)

Salaried Employee
(Name, address, employee ID, salary, start date (dayNO, monthNo, year))

Volunteer Employee
(Name, address, employeeID)
Jun 5 '07 #2
Expand|Select|Wrap|Line Numbers
  1.  
  2. import javax.swing.*; 
  3. import java.awt.*;
  4. import java.awt.event.*;
  5. import java.io.*;
  6. import java.util.*;
  7. import javax.swing.event.*;
  8.  
  9. public class View extends JFrame 
  10. private EmployeeList empList;
  11. private JLabel Heading;
  12. private JLabel Nll; 
  13. private DefaultListModel listModel;
  14. private JList NameList; 
  15. private int NameListPrevVal=-999; 
  16. private JScrollPane ScrollPanel; 
  17. private JLabel Namel;
  18. private JTextField Name;
  19. private JLabel Eidl;
  20. private JTextField Eid;
  21. private JLabel Typel;
  22. private JTextField Type; 
  23. private JComboBox TypeCB;
  24. private JLabel Addressl; 
  25. private JTextField Address;
  26. private JLabel Hrl;
  27. private JTextField Hr;
  28. private JLabel Nohwl;
  29. private JTextField Nohw;
  30. private JLabel Sall;
  31. private JTextField Sal; 
  32. private JLabel Dojl;
  33. private JTextField Doj;
  34. private JButton Exit;
  35. private JButton Add;
  36. private JButton Clear;
  37. private JButton Save;
  38. private JButton Delete;
  39. private JTextField FindID;
  40. private JButton Find;
  41. private JButton WSummary;
  42. private JPanel contentPane; 
  43.  
  44.  
  45. public View() throws FileNotFoundException, IOException
  46. empList = new EmployeeList();
  47. getContentPane().setLayout(null);
  48. getContentPane().setBackground(Color.black);
  49. setTitle("Employee Information System ");
  50. setSize(new Dimension(600, 600));
  51.  
  52. Heading = new JLabel(); 
  53. Heading.setBounds(250,60,130,50);
  54. Heading.setForeground(Color.yellow); 
  55. Heading.setText("Employee Database");
  56. getContentPane().add(Heading); 
  57.  
  58. Nll = new JLabel(); 
  59. Nll.setBounds(84,133,115,18);
  60. Nll.setForeground(Color.red); 
  61. Nll.setText("Employee ID List:");
  62. getContentPane().add(Nll); 
  63.  
  64. listModel = new DefaultListModel();
  65. for (int i = 0; i < empList.getSize();i++)
  66. {
  67. String empId = empList.getEmployee(i).getEmpId(); 
  68. listModel.addElement(empId);
  69. empList.sort();
  70. }
  71.  
  72. NameList = new JList(listModel);
  73. NameList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
  74. NameList.setSelectedIndex(0);
  75. NameList.setBounds(20,150,230,246);
  76. getContentPane().add(NameList);
  77. NameList.addListSelectionListener(new Ell());
  78.  
  79.  
  80.  
  81. ScrollPanel = new JScrollPane(NameList); 
  82. ScrollPanel.setViewportView(NameList);
  83. ScrollPanel.setBounds (20,150,230,246);
  84. getContentPane().add(ScrollPanel);
  85.  
  86.  
  87. Namel = new JLabel(); 
  88. Namel.setBounds(285,140,60,18);
  89. Namel.setForeground(Color.red);
  90. Namel.setText("Name:");
  91. Namel.setVisible(true);
  92. getContentPane().add(Namel); 
  93.  
  94. Name = new JTextField(empList.getEmployee(0).getName());
  95. Name.setBounds(285,160,258,22);
  96. Name.setVisible(true);
  97. Name.setEditable(false);
  98. getContentPane().add(Name);
  99.  
  100. Eidl = new JLabel(); 
  101. Eidl.setBounds(285,194,60,18);
  102. Eidl.setForeground(Color.red);
  103. Eidl.setText("Emp.ID:");
  104. Eidl.setVisible(true);
  105. getContentPane().add(Eidl); 
  106.  
  107. Eid = new JTextField(empList.getEmployee(0).getEmpId());
  108. Eid.setBounds(285,214,100,22);
  109. Eid.setEditable(false);
  110. Eid.setVisible(true);
  111. getContentPane().add(Eid);
  112.  
  113. Typel = new JLabel(); 
  114. Typel.setBounds(442,195,65,18);
  115. Typel.setForeground(Color.red); 
  116. Typel.setText("Emp. Type:");
  117. getContentPane().add(Typel); 
  118.  
  119. Type = new JTextField(empList.getEmployee(0).toEmpType());
  120. Type.setBounds(442,214,100,22);
  121. getContentPane().add(Type);
  122. Type.setEditable(false);
  123.  
  124. TypeCB = new JComboBox();
  125. TypeCB.setBounds(442,214,90,27);
  126. TypeCB.addItem("Salaried");
  127. TypeCB.addItem("Part Time");
  128. TypeCB.addItem("Volunteer");
  129. TypeCB.setVisible(false);
  130. getContentPane().add(TypeCB);
  131. TypeCB.addActionListener(new TypeCB());
  132.  
  133.  
  134. Addressl = new JLabel();
  135. Addressl.setBounds(285,250,60,18);
  136. Addressl.setForeground(Color.red);
  137. Addressl.setText("Address:");
  138. getContentPane().add(Addressl);
  139.  
  140. Address = new JTextField(empList.getEmployee(0).getAddress());
  141. Address.setBounds(285,268,258,22);
  142. getContentPane().add(Address);
  143. Address.setEditable(false);
  144.  
  145. Hrl = new JLabel();
  146. Hrl.setBounds(286,305,75,18);
  147. Hrl.setForeground(Color.red);
  148. Hrl.setText("Hourly Rate:");
  149. getContentPane().add(Hrl);
  150.  
  151.  
  152. Hr = new JTextField(empList.getEmployee(0).toHour());
  153. Hr.setBounds(286,324,100,22);
  154. getContentPane().add(Hr);
  155. Hr.setEditable(false); 
  156.  
  157. Nohwl = new JLabel();
  158. Nohwl.setBounds(442,306,106,17);
  159. Nohwl.setForeground(Color.red);
  160. Nohwl.setText("Hours Worked:");
  161. getContentPane().add(Nohwl);
  162.  
  163. Nohw = new JTextField(empList.getEmployee(0).toRate());
  164. Nohw.setBounds(442,326,100,22);
  165. Nohw.setEditable(false); 
  166. getContentPane().add(Nohw);
  167.  
  168. Sall = new JLabel();
  169. Sall.setBounds(286,355,106,17);
  170. Sall.setForeground(Color.red);
  171. Sall.setText("Salary:");
  172. getContentPane().add(Sall);
  173.  
  174. Sal = new JTextField(empList.getEmployee(0).toSal());
  175. Sal.setBounds(286,375,100,22);
  176. getContentPane().add(Sal);
  177. Sal.setEditable(false); 
  178.  
  179.  
  180. Dojl = new JLabel();
  181. Dojl.setBounds(442,355,100,22);
  182. Dojl.setForeground(Color.red);
  183. Dojl.setText("D.O.J");
  184. getContentPane().add(Dojl);
  185.  
  186. Doj = new JTextField(empList.getEmployee(0).toDate());
  187. Doj.setBounds(442,375,100,22);
  188. getContentPane().add(Doj);
  189. Doj.setEditable(false);
  190.  
  191. Exit = new JButton(); 
  192. Exit.setText("Save & Exit");
  193. Exit.setBounds(450,30,100,28);
  194. getContentPane().add(Exit);
  195. Exit.addActionListener(new Exit());
  196.  
  197. Add = new JButton(); 
  198. Add.setText("Add");
  199. Add.setBounds(70,500,83,28);
  200. getContentPane().add(Add);
  201. Add.addActionListener(new Add());
  202.  
  203. Clear = new JButton();
  204. Clear.setText("Clear");
  205. Clear.setBounds(430, 400, 83, 28);
  206. getContentPane().add(Clear);
  207. Clear.addActionListener(new Clear());
  208.  
  209. Save = new JButton(); 
  210. Save.setText("Save");
  211. Save.setBounds(370,410,83,28);
  212. Save.setVisible(false);
  213. getContentPane().add(Save);
  214. Save.addActionListener(new Save());
  215.  
  216. Delete = new JButton(); 
  217. Delete.setText("Delete"); 
  218. Delete.setBounds(190,500,83,28);
  219. getContentPane().add(Delete);
  220. Delete.addActionListener(new Delete());
  221.  
  222.  
  223. FindID = new JTextField();
  224. FindID.setBounds(307,470,90,27);
  225. getContentPane().add(FindID);
  226. Find = new JButton();
  227. Find.setText("Find"); 
  228. Find.setBounds(310,500,83,28);
  229. getContentPane().add(Find);
  230.  
  231. WSummary = new JButton();
  232. WSummary.setText("Summary"); 
  233. WSummary.setBounds(430,500,90,28);
  234. getContentPane().add(WSummary);
  235. // WSummary.addActionListener(new WSummary());
  236.  
  237.  
  238. setResizable(false);
  239. setVisible(true);
  240.  
  241. class Exit implements ActionListener
  242. {
  243. public void actionPerformed(ActionEvent e)
  244. {
  245. try
  246. {
  247. empList.writeFile();
  248. System.exit(0);
  249. }
  250. catch (IOException f) 
  251. {
  252. System.out.println("Error opening the file");
  253.  
  254. }
  255.  
  256. class Clear implements ActionListener
  257. {
  258. public void actionPerformed(ActionEvent e)
  259. {
  260. Nohw.setText(" "); 
  261. Name.setText(" ");
  262. Sal.setText(" ");
  263. Hr.setText(" ");
  264. Address.setText(" ");
  265. Eid.setText(" ");
  266. Doj.setText(" ");
  267.  
  268. Nohw.setEditable(true); 
  269. Name.setEditable(true);
  270. Sal.setEditable(true); 
  271. Hr.setEditable(true); 
  272. Address.setEditable(true); 
  273. Eid.setEditable(true);
  274. Doj.setEditable(true);
  275.  
  276. TypeCB.setVisible(true);
  277. Type.setVisible(false);
  278. }
  279.  
  280. class Add implements ActionListener
  281. {
  282. public void actionPerformed(ActionEvent e)
  283. {
  284.  
  285.  
  286. }
  287. }
  288.  
  289.  
  290. class Save implements ActionListener
  291. {
  292. public void actionPerformed(ActionEvent sav) 
  293. {
  294.  
  295. }
  296.  
  297. class TypeCB implements ActionListener
  298. {
  299. public void actionPerformed(ActionEvent e)
  300.  
  301. {
  302. disableFields();
  303. }
  304. }
  305.  
  306.  
  307. class Ell implements ListSelectionListener
  308. {
  309. public void valueChanged(ListSelectionEvent e) 
  310. {
  311.  
  312. int index = NameList.getSelectedIndex();
  313. Name.setText(empList.getEmployee(index).getName());
  314. Eid.setText(empList.getEmployee(index).getEmpId());
  315. Type.setText(empList.getEmployee(index).toEmpType());
  316. Address.setText(empList.getEmployee(index).getAddress());
  317. Hr.setText(empList.getEmployee(index).toHour());
  318. Nohw.setText(empList.getEmployee(index).toRate());
  319. Sal.setText(empList.getEmployee(index).toSal());
  320. Doj.setText(empList.getEmployee(index).toDate());
  321.  
  322. Nohw.setEditable(false); 
  323. Name.setEditable(false);
  324. Sal.setEditable(false); 
  325. Hr.setEditable(false); 
  326. Address.setEditable(false); 
  327. Eid.setEditable(false);
  328. Doj.setEditable(false);
  329. }
  330. }
  331.  
  332.  
  333. class Delete implements ActionListener
  334. {
  335. public void actionPerformed(ActionEvent e)
  336. {
  337. int location = NameList.getSelectedIndex();
  338. empList.deleteEmployee(location);
  339. NameList.clearSelection();
  340. listModel.remove(location);
  341. listModel.clear();
  342. for (int i = 0; i < empList.getSize();i++)
  343. {
  344. String empId = empList.getEmployee(i).getEmpId(); 
  345. listModel.addElement(empId);
  346. empList.sort();
  347. }
  348. }
  349. }
  350.  
  351.  
  352. class Find implements ActionListener
  353. {
  354. public void actionPerformed(ActionEvent e)
  355. {
  356.  
  357.  
  358. }
  359.  
  360.  
I purposely left out the constructor to avoid wasting space
Jun 5 '07 #3
blazedaces
284 100+
Please ignore this post for now... my mistake,

-blazed
Jun 5 '07 #4
Ignore the last post. I don't know who blazed is but yeah I still would like assistance with this assignment.
Jun 5 '07 #5
blazedaces
284 100+
I apologize. Yesterday, when I first looked at this thread you had yet to post your code so I asked you to, but when I posted, you had already posted your code and my post was afterwards, it seemed stupid, so I simply removed the post and kindly asked that you ignore it.

Ok, listen, two things:

First, put your code in code brackets please (when you reply, look to your right to see instructions). Also, try to from now only post your relevant code, not all of it (see posting guidelines).

Next, and more importantly, I don't know how to help you because I do not know what you want/what kind of help you want. You said you do not know what to put in your GUI class... but the question you should be asking yourself is... What do you want your GUI class to do about it?

All l know so far is that you have implemented your Employees through the EmployeeList class, yet I don't know how that relates to your GUI. Do you want it to respond somehow with a confirmation? Do you want it to immediately continue onto some method/store information/calculate data? Is this only about making the button appear? Is it about extending the button class in EmployeeList so it can be easily inserted?

Please try your best to describe the situation more clearly so we can help you as best we can.

Good luck, hoping to hear from you soon,

-blazed
Jun 5 '07 #6
Oh ok sorry about that.

In the GUI, I want to write my own entries (Name, ID, address, etc) after I've cleared all the text boxes. When I press add, I want it to add these elements into my existing array of objects so that it is displayed with the other pre-existing entries in the GUI. I've created the methods in the EmployeeList class

Expand|Select|Wrap|Line Numbers
  1.  
  2. public void addEmployee(Employee employeeType)
  3. {
  4. employee[noOfemp] = employeeType;
  5. noOfemp++;
  6. }
  7.  
  8. public void addVol(String name, String address, String empId)
  9. {
  10. Volunteer vol = new Volunteer(name, address, empId);
  11. vol.setName(name);
  12. vol.setAddress(address);
  13. vol.setEmpId(empId);
  14.  
  15. employee[noOfemp] = vol;
  16.  
  17. }
  18.  
  19. public void addPartSal(String name, String address, String empId, float noOfHours, float hourlyRate )
  20. {
  21. PartTimeEmp part = new PartTimeEmp(name, address, empId, noOfHours, hourlyRate);
  22. part.setName(name);
  23. part.setAddress(address);
  24. part.setEmpId(empId);
  25. part.calcPay(noOfHours, hourlyRate);
  26. employee[noOfemp] = part;
  27.  
  28. }
  29.  
  30. public void addSal(String name,String address, String empId, float salary, String date)
  31. {
  32. SalariedEmp sal = new SalariedEmp(name, address, empId, salary, date);
  33. sal.setName(name);
  34. sal.setAddress(address);
  35. sal.setEmpId(empId);
  36. sal.toSal();
  37. sal.toDate();
  38. employee[noOfemp] = sal;
  39. }
  40.  
Do I only need to call these methods in the add class in the GUI?
Jun 6 '07 #7
blazedaces
284 100+
Oh ok sorry about that.

In the GUI, I want to write my own entries (Name, ID, address, etc) after I've cleared all the text boxes. When I press add, I want it to add these elements into my existing array of objects so that it is displayed with the other pre-existing entries in the GUI. I've created the methods in the EmployeeList class

Expand|Select|Wrap|Line Numbers
  1.   public void addEmployee(Employee employeeType)
  2.     {
  3.     employee[noOfemp] = employeeType;
  4.     noOfemp++;
  5.     }
  6.  
  7.     public void addVol(String name, String address, String empId)
  8.     {
  9.      Volunteer vol = new Volunteer(name, address, empId);
  10.        vol.setName(name);
  11.        vol.setAddress(address);
  12.        vol.setEmpId(empId);
  13.  
  14.        employee[noOfemp] = vol;
  15.  
  16.     }
  17.  
  18.     public void addPartSal(String name, String address, String empId, float noOfHours, float hourlyRate )
  19.     {
  20.        PartTimeEmp part = new PartTimeEmp(name, address, empId, noOfHours, hourlyRate);
  21.        part.setName(name);
  22.        part.setAddress(address);
  23.        part.setEmpId(empId);
  24.        part.calcPay(noOfHours, hourlyRate);
  25.        employee[noOfemp] = part;
  26.  
  27.     }
  28.  
  29.    public void addSal(String name,String address, String empId, float salary, String date)
  30.     {
  31.         SalariedEmp sal = new SalariedEmp(name, address, empId, salary, date);
  32.         sal.setName(name);
  33.         sal.setAddress(address);
  34.         sal.setEmpId(empId);
  35.         sal.toSal();
  36.         sal.toDate();
  37.         employee[noOfemp] = sal;
  38.     }
  39.  
Do I only need to call these methods in the add class in the GUI?
I'm a little confused. First of all, in the last three of your methods you seem to be redundant, either do one of the following, not both, for example in the addVol method you write:
Expand|Select|Wrap|Line Numbers
  1. Volunteer vol = new Volunteer(name, address, empId);
followed by
Expand|Select|Wrap|Line Numbers
  1.        vol.setName(name);
  2.        vol.setAddress(address);
  3.        vol.setEmpId(empId);
Now, unfortunately, I'm not goint to try and look through all your code, so I don't know for sure, but I'm assuming if you have a class Volunteer which has these variable inputs it should look like this, am I wrong?:

Expand|Select|Wrap|Line Numbers
  1. public Volunteer(name, address, empId) {
  2.        setName(name);
  3.        setAddress(address);
  4.        setEmpId(empId);
  5. }
which means that the part that follows is a waste of code, no?

If not, then why do you input those three variables at all? Do one, but don't do both.

On a second note, what array type is employee[]? Is it of type employee? Are volunteer and salariedEmployee extended classes of employee?

If that's the case they should be added, but what is the problem then? What is happening that you don't want happening? Did you not test to see that it works? When you say that you want the GUI to "display" it... what do you mean?

Do you mean simply store it in the background, or do you mean there should be an updated object which displays a list of all employees with perhaps a link to see options for each one or something of the sort?

Good luck, keep trying,

-blazed
Jun 6 '07 #8
Expand|Select|Wrap|Line Numbers
  1.  public void addEmployee(Employee employeeType)
  2.     {
  3.     employee[noOfemp] = employeeType;
  4.     noOfemp++;
  5.     }
  6.  
  7.     public void addVol(String name, String address, String empId)
  8.     {
  9.      Volunteer vol = new Volunteer(name, address, empId);
  10.  
  11.         employee[noOfemp] = vol;
  12.  
  13.     }
  14.  
  15.     public void addPartSal(String name, String address, String empId, float noOfHours, float hourlyRate )
  16.     {
  17.        PartTimeEmp part = new PartTimeEmp(name, address, empId, noOfHours, hourlyRate);
  18.  
  19.        employee[noOfemp] = part;
  20.  
  21.     }
  22.  
  23.    public void addSal(String name,String address, String empId, float salary, String date)
  24.     {
  25.         SalariedEmp sal = new SalariedEmp(name, address, empId, salary, date);
  26.  
  27.         employee[noOfemp] = sal;
  28.     } 
Is this correct?

Yes Employee[] is of type employee. In addition Volunteer, Part Time Employee and Salaried Employee are sub classes of class Employee. I think thats the term when it's a hierarchy.

These methods have been created in the EmployeeList class. The GUI is named the View class. In the View class is where I want to call the add function using the ActionListener.

At the moment the GUI shows a listbox with the employee IDs listed. It also shows in textboxes the name, address, salary, etc of the particular employee selected from the ID in the listbox. At the moment I have set up a working function in the View class which clears all but the listbox of IDs which allows me to enter the details of a new employee including the ID which is in another textbox. When I press the add button, I want it to store the information I have added into the array of objects. Afterwards I want to be able to see the ID I have just entered in the listbox of IDs and when I click it, it should contain all the information I entered in their respective textboxes.

I hope that's enough information for now. Thanks for your time.
Jun 6 '07 #9
blazedaces
284 100+
Expand|Select|Wrap|Line Numbers
  1.  public void addEmployee(Employee employeeType)
  2.     {
  3.     employee[noOfemp] = employeeType;
  4.     noOfemp++;
  5.     }
  6.  
  7.     public void addVol(String name, String address, String empId)
  8.     {
  9.      Volunteer vol = new Volunteer(name, address, empId);
  10.  
  11.         employee[noOfemp] = vol;
  12.  
  13.     }
  14.  
  15.     public void addPartSal(String name, String address, String empId, float noOfHours, float hourlyRate )
  16.     {
  17.        PartTimeEmp part = new PartTimeEmp(name, address, empId, noOfHours, hourlyRate);
  18.  
  19.        employee[noOfemp] = part;
  20.  
  21.     }
  22.  
  23.    public void addSal(String name,String address, String empId, float salary, String date)
  24.     {
  25.         SalariedEmp sal = new SalariedEmp(name, address, empId, salary, date);
  26.  
  27.         employee[noOfemp] = sal;
  28.     } 
Is this correct?

Yes Employee[] is of type employee. In addition Volunteer, Part Time Employee and Salaried Employee are sub classes of class Employee. I think thats the term when it's a hierarchy.

These methods have been created in the EmployeeList class. The GUI is named the View class. In the View class is where I want to call the add function using the ActionListener.

At the moment the GUI shows a listbox with the employee IDs listed. It also shows in textboxes the name, address, salary, etc of the particular employee selected from the ID in the listbox. At the moment I have set up a working function in the View class which clears all but the listbox of IDs which allows me to enter the details of a new employee including the ID which is in another textbox. When I press the add button, I want it to store the information I have added into the array of objects. Afterwards I want to be able to see the ID I have just entered in the listbox of IDs and when I click it, it should contain all the information I entered in their respective textboxes.

I hope that's enough information for now. Thanks for your time.
First of all, I want to repeat this:
what is the problem then? What is happening that you don't want happening? Did you not test to see that it works?
Seriously, I don't know what you see, and I can't just imagine everything that happens at runtime. Tell me what does so we can together figure out a way to make what you want happen. Comprende? Sorry, until I know what is happening, what's not happening, and mostly what exactly is missing I'm not sure how to improve your program.

On a side note, in your code in your first method you do:
Expand|Select|Wrap|Line Numbers
  1. employee[noOfemp] = employeeType;
  2.     noOfemp++;
Yet in all the rest of them you only write:
Expand|Select|Wrap|Line Numbers
  1. employee[noOfemp] = whatever;
If you don't do noOfemp++ then won't something else be happening? Or is it that you want the previous employee replaced by a volunteer or salariedWorker or whatever? It just doesn't seem that's what you want to do...

May a make a suggestion? Make use of the object-oriented-ness (that's what I call it) of Java, change the code in your volunteer method and the rest to change this:
Expand|Select|Wrap|Line Numbers
  1. employee[noOfemp]=vol;
to this:
Expand|Select|Wrap|Line Numbers
  1. addEmployee(vol);
I mean that's what you want it to do right? I have a tendency to use object-oriented-esque coding even too much (I'm lazy, it removes the repitition of coding). Either way I think that needs to be modified unless it's meant to be the way it is, and in that case ignore everything I said.

And again, tell me what's happening and what is not happening that you want to happen, so we can get somewhere.

Good luck,

-blazed
Jun 6 '07 #10
Ok, I created an object in the EmployeeList class. The i tested out the addVol method, put in the entries for name, address and empID and it came back with the error: ";" expected.
Jun 7 '07 #11
Soz ignore my previous post
Jun 7 '07 #12
Ok my add is working fine now, thanks for your help blazed. My problem now is the save method. Say I add or delete an employee, and I want to save that information which is basically saving the array of objects, is there a function or something? Our lecturer never taught us anything about a save function and she's not replying to my emails so if you could help me with that, I'd appreciate it. Thanks.
Jun 7 '07 #13
blazedaces
284 100+
Ok my add is working fine now, thanks for your help blazed. My problem now is the save method. Say I add or delete an employee, and I want to save that information which is basically saving the array of objects, is there a function or something? Our lecturer never taught us anything about a save function and she's not replying to my emails so if you could help me with that, I'd appreciate it. Thanks.
Do you mean save it in a file? I don't understand, "saving the array of object"...?

Keep it stored? Is it going somewhere? Sorry for my misunderstanding.

If you do mean save it to a file then you would probably not want the memory itself saved, but rather the employee information, things like Name, Salary, whatever you had...

Check out the PrintWriter class and the FileOutputStream class as well (these are what I've used, though I don't know if they're the best ways of doing so).

Good luck, glad to have been helpful and I'm sorry your lecturer doesn't seem to care about his students...

-blazed
Jun 7 '07 #14
yeah, it was saving to a file. Got it done overnight with success, YAY!
Jun 8 '07 #15

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: Warren Wright | last post by:
Hello, We maintain a 175 million record database table for our customer. This is an extract of some data collected for them by a third party vendor, who sends us regular updates to that data...
2
by: carrionk | last post by:
Hi, I need to compare if certain records are contained whithin a Master Table. The following tables illustrates the comparing tables and the required Result Master Table ============...
3
by: TJS | last post by:
how do I get a constant to be available to all functions in a code class ? tried : Namespace Namespace Public Class MyClass const myconst as integer = 21 ..... but it wasn't available to...
5
by: MattPF | last post by:
I have a table that is -- 30 Megabytes 90,000 rows ~65 columns My query goes SELECT city FROM table WHERE zip = 90210; It will then find about 10 matching records.
3
by: meyvn77 | last post by:
Hello - I am looking for the best way to store images in a Access DB. My Idea - I have a table with 150,000 records. These recoreds represent a Crash (Traffic Accident). I have 50 different...
1
by: Pete Smith | last post by:
I am making the animated text inside the table cell data. The animation is done using Javascript. Here is the code looks like.. <table><tr><td><script>Java Script code which does animation of...
0
by: day | last post by:
Hi I designed my database in access and I use it to migrate to MYSQL. I have a problem can some on help me on how to make a master detailed table with two other tables of which their field are...
1
by: Verticon:: | last post by:
I have a situation where I need a table if bad items to match to. For example, The main table may be as: Table Main: fd_Id INT IDENTITY (1, 1) fd_Type VARCHAR(100) Table Matcher:...
5
by: Will | last post by:
- I know enough ASP and Access to be dangerous :) - I need to put up a data base on our web server with 3 related tables. - They will be accessed by a limited number of people. - Each user will...
8
by: sxs1 | last post by:
I have performance issue with the query which takes 5-10 mins and has table has very less number of records something arround a million records.I need to insert the filtered data into a global temp...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.