In the button numx.write Writes: "The method write (int) in the type BufferedWriter is not applicable for the arguments (List)" A if I enter numx.write (Arrays.asList (x); That output error: "Type mismatch: cannot convert from List to int "How to save as an array in the text, then to refer to each element of the text?
import java.util.ArrayList; import java.util.Arrays; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.*; import java.util.List; import javax.swing.*; import javax.swing.border.EmptyBorder; public class Start extends JFrame { /** * */ private static final long serialVersionUID = -6516165981432576014L; //Local variables private JTextField m[] = new JTextField[9]; private String n[] = new String[9]; private int x[] = new int [9]; private JButton button; Start(){ //Top super("Determinant"); //Closing setDefaultCloseOperation(EXIT_ON_CLOSE); //Label JLabel label = new JLabel(new ImageIcon("detA.png")); //ArrayList Box box1 = Box.createHorizontalBox(); Box box2 = Box.createHorizontalBox(); Box box3 = Box.createHorizontalBox(); for (int i = 0; i<9; i++) { m[i] = new JTextField(1); //First Line if (i < 3) { box1.add(Box.createHorizontalStrut(1)); box1.add(m[i]); } //Second Line else if ((i>=3) && (i<6)){ box2.add(Box.createHorizontalStrut(1)); box2.add(m[i]); } else if (i>=6) { //Third Line box3.add(Box.createHorizontalStrut(1)); box3.add(m[i]); } } //Make Button button = new JButton("Result"); Box box4 = Box.createHorizontalBox(); box4.add(Box.createHorizontalGlue()); box4.add(button); for (int i = 0;i<9;i++) { try { n[i] = m[i].getText(); x[i] = Integer.parseInt(n[i]);} catch (NumberFormatException e) { } ; } //buttonListener button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ev) { try { FileWriter saveX = new FileWriter("test.txt", true); BufferedWriter numx = new BufferedWriter(saveX); List<int[]> list = Arrays.asList(x); numx.write(list); numx.close(); } catch (Exception e) { } } }); //Make MainBox Box mainBox = Box.createVerticalBox(); mainBox.setBorder(new EmptyBorder(12,12,12,12)); setContentPane(mainBox); mainBox.add(Box.createVerticalStrut(10)); getContentPane().add(label); mainBox.add(box1); mainBox.add(box2); mainBox.add(box3); mainBox.add(box4); //Size and visible pack(); setResizable(false); setVisible(true); } }