コード例 #1
0
 private void populateTblCustomer() {
   List<Customer> list = customers;
   DefaultTableModel tableModel = (DefaultTableModel) tblCustomer.getModel();
   tableModel.getDataVector().removeAllElements();
   // tblCustomer.repaint();
   if (list.size() > 0) {
     for (int i = 0; i < list.size(); i++) {
       Customer customer = list.get(i);
       tableModel.insertRow(
           i,
           new Object[] {
             i + 1,
             customer.getSurName(),
             customer.getForeName(),
             customer.getAddLine1(),
             customer.getPostCode(),
             customer.getTelNo(),
             customer.getEmail()
           });
     }
   } else {
     tableModel.insertRow(0, new Object[] {});
   }
 }
コード例 #2
0
  public List<Customer> convertCSV(File file) {
    List<Customer> customers = new ArrayList<>();
    try {
      BufferedReader bf = null;
      bf = new BufferedReader(new FileReader(file));
      String line = null;
      while ((line = bf.readLine()) != null) {
        // FORENAME,SURNAME,CONTACTPERSON,ADDLINE1,ADDLINE2,CITY,EMAIL,FAX,MOBILE,POSTCODE,PROVINCE,TELNO
        try {
          String[] vals = line.split(",", -1);
          System.out.println("Name:" + vals[0] + " " + vals[1]);
          Customer customer = new Customer();
          customer.setForeName(vals[0]);
          customer.setSurName(vals[1]);
          customer.setContactPerson(vals[2]);
          customer.setAddLine1(vals[3]);
          customer.setAddLine2(vals[4]);
          customer.setCity(vals[5]);
          customer.setEmail(vals[6]);
          customer.setFax(vals[7]);
          customer.setMobile(vals[8]);
          customer.setPostCode(vals[9]);
          customer.setProvince(vals[10]);
          customer.setTelNo(vals[11]);
          customers.add(customer);
        } catch (Exception e) {

        }
      }
    } catch (FileNotFoundException ex) {
    } catch (IOException ex) {
    }

    return customers;
  }