0

It my first work with swing, help please.

//In this texfield should be an array of digits like this: 10, 5, 8, 1, 11
private JTextField  setATextField = new JTextField(10);
private JButton button = new JButton("Button");
//....
//....
public class UnionActionListener implements ActionListener {
    @Override
    public void actionPerformed(ActionEvent event) {
        ArrayList<Integer> setA = new ArrayList<>();
    }
}

How to add this digits in arraylist? it must be like this:

JTextField field = new JTextField("10, 5, 8, 1, 11", 10);
setA.get(0) = 10;
setA.get(1) = 5;
setA.get(2) = 8;
//......
Shivam Kumar
  • 1,892
  • 2
  • 21
  • 33
Joe Kappa
  • 39
  • 3
  • If you want to add together all the `int`s in an `ArrayList`, you can do `int sum; setA.forEach((elm) -> sum += Integer.intValueOf(elm));`. – Majora320 Mar 13 '16 at 00:57
  • 1
    http://stackoverflow.com/questions/30125296/how-to-sum-a-list-of-integers-with-java-streams – Phill Treddenick Mar 13 '16 at 01:02
  • @Majora320 , Yes, i want add all int s in an arraylist from JTextField setATextField. ' public class UnionActionListener implements ActionListener { @ Override public void actionPerformed(ActionEvent event) { ArrayList setA = new ArrayL;ist<>(); int sum; setA.forEach((Integer) -> sum+=Integer.valueOf(setATextField));' It don't work. – Joe Kappa Mar 13 '16 at 01:22
  • If you had searched the site, there are plenty of posts on this topic. Flagging as a duplicate. – pczeus Mar 13 '16 at 02:44

0 Answers0