java将arraylist显示为textfield

w3nuxt5m  于 2021-06-30  发布在  Java
关注(0)|答案(1)|浏览(240)

在文本字段中显示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));
         }
     }

}
3ks5zfa0

3ks5zfa01#

你正在覆盖 JTextField 每次打电话都要重视 setText() . 你需要建立 String 循环中的值,然后调用 setText() 与创建的 String .

相关问题