2016-11-30 1 views
-2

현재 클래스 프로젝트의이 부분에 갇혀 있습니다 ... 텍스트 파일에서 ArrayList를 만들어야합니다. 텍스트 파일에는 JComboBox에 채워야하는 계좌 번호가 있습니다. 이것은 내가 지금까지 무엇을 가지고 ... 첫 번째 계좌 번호는 내 실수가다른 클래스의 ArrayList로 JComboBox 채우기

// AccountUtility class that reads file and creates ArrayList named test 

public class AccountUtility { 

    ArrayList<String> test = new ArrayList<String>(); 
    String[] number; 
    String columns[], accountNumber, customerName, openDate, balance; 
    int size; 


public AccountUtility(){ 


    BufferedReader in = null; 
    try{ // assume products.txt already exists 
    in = new BufferedReader(new FileReader("accounts.txt")); 
    String line = in.readLine(); 
    while(line != null) { 
    columns = line.split("<>"); 
    accountNumber = columns[0]; 
    customerName = columns[1]; 
    openDate = columns[2]; 
    balance = columns[3]; 

        line = in.readLine(); 
      } 
      in.close(); 
    } 
    catch(IOException ioe) 
    { 
      System.out.println(ioe); 
    } 
} 

public ArrayList <String> getAccountNumbers(){ 

    ArrayList <String> test = new ArrayList<String>(); 
    test.add(accountNumber); 

    return test; 




//class with JComboBox (GUI) 

public class BankAccountApp extends javax.swing.JFrame { 


    public BankAccountApp() { 

     initComponents(); 
     setLocationRelativeTo(null); 

     AccountUtility gc = new AccountUtility(); 

     for(String numbers : gc.getAccountNumbers()){ 
     accountNumberComboBox.addItem(numbers); 
     } 
    } 
+0

생성자에서 작업을 수행하지 마십시오. –

답변

0

내가 당신이 원하는 것은

while(line != null) { 
    columns = line.split("<>"); 
    accountNumber = columns[0]; 
    test.add(accountNumber); 
    .... 
} 

이라고 생각했을 것입니다 확실하지 나머지는 누락 웁니다
public ArrayList getAccountNumbers(){ 
    return test; 
} 
+0

고마워요 !!! –

+0

이 대답이 유용하다면 upvote 및/또는 받아 들일 것을 고려하십시오. –

관련 문제