开发者

Java: Import saved ArrayList and display in text field

开发者 https://www.devze.com 2023-04-05 09:04 出处:网络
having trouble with this. I have an ArrayList which I have output t开发者_高级运维o a file, I want to be able to open this file and display the contents in a jTextField

having trouble with this.

I have an ArrayList which I have output t开发者_高级运维o a file, I want to be able to open this file and display the contents in a jTextField

private void btnSubmitActionPerformed(java.awt.event.ActionEvent evt) {                                          
   computer= new Computer();
   computer.setComputerType(cbType.getSelectedItem().toString() +"\n");
   computer.setWeight(txtWeight.getText() +"\n");
   computer.setBatteryLife(txtBattery.getText() +"\n");
   computer.setScreenSize(txtScreenSize.getText() +"\n");
   computer.setRamSize(txtRAM.getText() +"\n");
   computer.setOS(cbOS.getSelectedItem().toString() +"\n");
   computer.setManufacturerName(txtManufacturer.getText() +"\n");
   computer.setProcessorModel(txtCPU.getText() +"\n");
   computer.setCpuCoreType(txtCPUCore.getText() +"\n");

    //Store computer in ArrayList
    myComputerList.add(computer);

    System.out.print("Size of array " + myComputerList.size() + "\n");
     System.out.print("\n");
}

private void btnSaveActionPerformed(java.awt.event.ActionEvent evt) {                                        

    try {
        ObjectOutputStream outputStream = new ObjectOutputStream(
        new FileOutputStream("ArrayFile.bin"));
        outputStream.writeObject(myComputerList);
        outputStream.close();
        System.out.println("Array output file" + "\n");
        }
            catch(IOException err)
            {
                System.out.println("Problem with file output");
            }
            System.out.println("Computer written to the file computers.bin");
} 
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号