在文本字段中显示arraylist值不起作用;这个类包含savebutton,当它将foodquan++保存到列表中时,
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++;
}
}
在这个类中,当按下show按钮时,它会将arraylist中的值显示到一个textfield中,这就是目标
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));
}
}
}
1条答案
按热度按时间3ks5zfa01#
你正在覆盖
JTextField
每次打电话都要重视setText()
. 你需要建立String
循环中的值,然后调用setText()
与创建的String
.