i am very new in java.
in GUI class i have code like this :
public void actionPerformed(ActionEvent e) {
if(e.getSource()==listButton){
ArrayList<String> list = new ArrayList<String>();
list.add("Orange");
list.add("Apple");
list.add("Pineapple");
list.add("Lemon");
list.add("Pear");
for(int i=0; i < list.size(); i++) {
String s = list.get(i);
{ textArea.setText(s+"\n"); }
}
but its showing only the last name 'Pear' in my textArea but it suppose to show the list of names.
why i am getting this output ???
anybody can tell me where i am doing wrong..............
i also tried like this :
public void actionPerformed(ActionEvent e) {
if(e.getSource()==listButton){
ArrayList<String> list = new ArrayList<String>();
list.add("Orange");
list.add("Apple");
list.add("Pineapple");
list.add("Lemon");
list.add("Pear");
for(String s : list) { // read as for each s in list
textArea.setText (s);
}