displaying arraylist values in text field not working;this class contains savebutton when it will save foodquan++ in to the list,
import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;
import java.util.ArrayList;
import javax.swing.JButton;
/**
*
* @author sirak elec
*/
public class User extends javax.swing.JFrame {
int Food_num;
int Food_quan;
int Drink_num;
int Drink_quan;
int Tab_num;
ArrayList saveArray1=new ArrayList();
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
Tab_num =Integer.parseInt(Text3.getText());
Food_num =Integer.parseInt(Text6.getText());
Food_quan =Integer.parseInt(Text7.getText());
Drink_num =Integer.parseInt(Text10.getText());
Drink_quan =Integer.parseInt(Text11.getText());
if((Tab_num!=0)&&(Food_quan<=10)&&(Drink_num<=10)&&(Drink_quan<=10)&&(Food_num<=10)){
String ord ="Order Succesfull";
Text14.setText(ord);
}
else{
String tryagain ="Invalid Entry";
Text14.setText(tryagain);
}
}
private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {
show();
}
public void show(){
User cquantity=new User();
int c=cquantity.getquancakesold();
saveArray1.add(c);
}
public int getquancakesold(){
return Food_quan++;
}
}
in this class when show button is pressed it will display the values in the arraylist to a textfield,this was the goal
import java.awt.event.ActionEvent;
import java.util.List;
public class Staff extends javax.swing.JFrame{
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
User val=new User();
list t=val.saveArray1;
if(val.Food_num==1){
for (int j=0;j<t.size();j++) {
jTextField5.setText((t.get(i));
}
}
}
You're overwriting the JTextField
value each time you call setText()
. You need to build the String
value in the loop and then call setText()
with the created String
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.