현재 클래스 프로젝트의이 부분에 갇혀 있습니다 ... 텍스트 파일에서 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);
}
}
생성자에서 작업을 수행하지 마십시오. –