Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public LoyaltySchemeMenu() {
- dataFile = new File("C:\\Users/James/Downloads/CustomerLoyaltySchemeFullSolution/customerData.dat");
- readDataFromFile();
- listModel = new DefaultListModel();
- //customers = new CustomerData().createTestData();
- refreshListModel();
- initComponents();
- }
- public static void refreshListModel() {
- String[] names = customers.getCustomerNames();
- listModel.clear();
- for (String n : names) {
- listModel.addElement(n);
- }
- }
- private void readDataFromFile() {
- try {
- inputFile = new FileInputStream(dataFile);
- objectInput = new ObjectInputStream(inputFile);
- customers = (CustomerList) objectInput.readObject();
- objectInput.close();
- } catch (IOException e) {
- JOptionPane.showMessageDialog(this, e.getMessage(),
- "Cannot read from file", JOptionPane.ERROR_MESSAGE);
- } catch (ClassNotFoundException e) {
- e.printStackTrace();
- }
- }
- private void writeDataToFile() {
- try {
- outputFile = new FileOutputStream(dataFile);
- objectOutput = new ObjectOutputStream(outputFile);
- objectOutput.writeObject(customers);
- objectOutput.flush();
- objectOutput.close();
- } catch (IOException e) {
- JOptionPane.showMessageDialog(this, e.getMessage(),
- "Cannot Write to File", JOptionPane.ERROR_MESSAGE);
- }
- }
- private void deleteCustomer() {
- int position = custListbox.getSelectedIndex();
- if (position == -1) {
- JOptionPane.showMessageDialog(this,
- "Please select a customer",
- "No selection", JOptionPane.ERROR_MESSAGE);
- } else {
- int confirm = JOptionPane.showConfirmDialog(this,
- "Are you sure you want to delete "
- + customers.getCustomerAt(position).getFullName(),
- "Confirm delete", JOptionPane.YES_NO_OPTION);
- if (confirm == JOptionPane.YES_OPTION) {
- customers.removeCustomerAt(position);
- refreshListModel();
- clearMainForm();
- }
- }
- }
- private void clearMainForm() {
- nameField.setText("");
- telField.setText("");
- emailField.setText("");
- curPointsField.setText("");
- ltPointsField.setText("");
- }
- public static void refreshDetails() {
- nameField.setText(selected.getFullName());
- telField.setText(selected.getPhoneNo());
- emailField.setText(selected.getEmailAddress().getAddress());
- }
- public static void updatePointsFields() {
- LoyaltySchemeMenu.curPointsField.setText(Integer.toString(LoyaltySchemeMenu.selected.getCurrentPoints()));
- LoyaltySchemeMenu.ltPointsField.setText(Integer.toString(LoyaltySchemeMenu.selected.getLifetimePoints()));
- }
Add Comment
Please, Sign In to add comment