2016-11-30 1 views
-2

私は現在クラスプロジェクトのこの部分で立ち往生しています...私はテキストファイルからArrayListを作成する必要があります。テキストファイルには、JComboBoxに入力する必要のある口座番号があります。これは私がこれまで持っているものです...のみ最初の口座番号は私のミスがJComboBoxに別のクラスのArrayListを設定する

// 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および/または受け入れることを検討してください。 –

関連する問題