0

I've found this Java swing code here, that is said to input data into an array using JOptionPane.

The problem is, if I'm not mistaken, that this code just prints out the data iteratively, but there's no array with the data as an output... At least I couldn't print out the 'textfields' array...

The code is here (the last one): How to use JOptionPane to input data into an array

5
  • this code just prints out the data iteratively,. - so modify the code to add the data to an array and then do whatever you want with array. Rarely will you ever find a code sample that does exactly what you want. Take the time to understand the basics of how the example works and then modify it to do what you want. Commented Oct 24, 2019 at 3:36
  • Welcome to SO! When you place a question try to add a minimum content: input sample, expected output sample, what did you try, research and where are you stuck. What did your try? Just copy? Commented Oct 24, 2019 at 3:40
  • If the number of datum is not known until indicated by the user (stopping it), it would be necessary to (first) collect the data into a (expandable) list or collection like an ArrayList. Commented Oct 24, 2019 at 3:40
  • I meen I can output the data to println, but I somehow cannot catch it into an array... This array public List<JTextField> textfields = new ArrayList<>(OPTIONS); Commented Oct 25, 2019 at 0:13
  • thank you, I made it! class JOptionPaneTest { public static final int OPTIONS = 11; public static List<JTextField> textfields = new ArrayList<>(OPTIONS); //this is my array! public static List <String> Acronyms = new ArrayList<>(OPTIONS); //rest of the code// if (result == JOptionPane.OK_OPTION) { for(JTextField textfield : example.textfields){ //for (int i=0; i<example.textfields; i++) // { Acronyms.add(textfield.getText()); System.out.println(textfield.getText()); } Commented Oct 25, 2019 at 0:57

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.