Java 如何在JButton中使用for循环

Java 如何在JButton中使用for循环,java,Java,//Student和admin都是类s从所有//学生的管理员处获取数组列表。 //我需要以表格格式显示它们,以便使用for循环 public void init(GUI gui){ // the class extends Jframe gui.setSize(1024, 700); gui.setPreferredSize(new Dimension(1024, 700)); gui.setResizable(false); gui.setLocatio

//Student和admin都是类s从所有//学生的管理员处获取数组列表。 //我需要以表格格式显示它们,以便使用for循环

 public void init(GUI gui){
    // the class extends Jframe   
   gui.setSize(1024, 700);
   gui.setPreferredSize(new Dimension(1024, 700));
   gui.setResizable(false);
   gui.setLocationRelativeTo(null);
   gui.setTitle("Student Management System");
   gui.setDefaultCloseOperation(EXIT_ON_CLOSE);
   Admin_AllStudents_pnl=new JLayeredPane();
   Admin_AllStudents_pnl.setSize(1024,700);
   Admin_AllStudents_pnl.setLayout(null);
   Admin_AllStudents_pnl.setVisible(false);
   Admin_AllStudents_pnl.setOpaque(true);
  // Admin_AllStudents_pnl.setBackground(Color.white);

   String col[]={"ID","Name","Password","Cell","Adress"};
   DefaultTableModel tablemodel=new DefaultTableModel(col,0);
   All_Students=new JTable(tablemodel);


   view_all=new JButton("View_All");
   Admin_AllStudents_pnl.add(view_all);
   view_all.setBorder(null); 
   view_all.setBounds(10,10,view_all.getPreferredSize().width,view_all.getPreferredSize().height);


   view_all.addActionListener(new ActionListener(){
       @Override
public void actionPerformed(ActionEvent ae){
ArrayList s=新的ArrayList();
s=admin.AllStudent();
System.out.println(“s数组列表的大小”+s.size());

对于(int i=0;i这一行中的arraylist的大小是多少?
System.out.println(“s arraylist的大小”+s.size())
数组列表的大小为4,并正确打印错误可能不在for循环中我不确定,但如果没有按钮,代码工作正常预期的行为是什么?您遇到的错误或有问题的行为是什么?获得此信息有助于我们帮助您。
       public void actionPerformed(ActionEvent ae) {
        ArrayList<Student> s=new ArrayList<>();
        s=admin.AllStudent();
        System.out.println("size of s arraylist"+s.size());

       for(int i=0;i<s.size();i++)
       {
       String Ids=s.get(i).getId();
       String names=s.get(i).getName();
       String passwords=s.get(i).getPass();
       String cells=s.get(i).getCell();
       String adresss=s.get(i).getAdress();
       Object[] data={Ids,names,passwords,cells,adresss};
       tablemodel.addRow(data);
       }
       }

   });

  Admin_AllStudents_pnl.add(All_Students);

   gui.add(Admin_AllStudents_pnl);