There is something like a DB. There is one JTextField line which is filled with data after pressing the corresponding button. How can I implement the filling of several colons of the type (int, String, String, int) in one line at the touch of a button? That is, somehow put something at the input.

 JTextField txtCreate = new JTextField(); //CREATE txtCreate.setBounds(10, 350, 100, 20); String temp[] = textCreate.getText().replaceAll(" ", "").split(","); add(txtCreate); add(btnCreate); btnCreate.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { new Person(); dm.pd.create(new Person(new Person(Integer.valueOf(temp[0]), temp[1], temp[2], Integer.valueOf(temp[3]))); //HELP dm.pp = dm.pd.read(); tbl.revalidate(); } } ); 

    1 answer 1

    Well, it depends on how you are going to enter the data in that field, you can separate them with a comma, i.e. 12, VASYA, PUPKIN, 20. Then

     String temp[] = textCreate.getText().replaceAll(" ", "").split(","); 

    and correspondingly

     dm.pd.create(new Person(Integer.valueOf(temp[0]), temp[1], temp[2], Integer.valueOf(temp[3]))); 

    Well, check to make the correct input

    • Oh great! I'm going to try now. - Maxim Demyanyuk
    • By the way, you still need to remove the spaces so that errors are not thrown. String temp [] = textCreate.getText (). ReplaceAll ("", "") .split (","); - jessez
    • Kicks an exception on the For input string: "". - Maxim Demyanyuk
    • Throw off the code and data that you enter in the field - jessez
    • Maybe this will help. Stackoverflow.com/questions/530635/… - jessez