将数组列表数据加载到 JTable 中
2022-09-03 09:12:51
我正在尝试从调用的方法设置项目,到目前为止,它很好。但后来我从中创建了一个arrayList,不知何故,我找不到将此信息存储到JTable中的方法。问题是我找不到一种方法来设置固定的行数FootballClub
这是我的代码:
班级开始联赛:
import javax.swing.*;
import javax.swing.table.*;
import java.awt.*;
public class startLeague implements LeagueManager{
//setting the frame and other components to appear
public startLeague(){
JButton createTeam = new JButton("Create Team");
JButton deleteTeam = new JButton("Delete Team");
JFrame frame = new JFrame("Premier League System");
JPanel panel = new JPanel();
frame.setSize(1280, 800);
frame.setVisible(true);
frame.add(panel);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
String col[] = {"Pos","Team","P", "W", "L", "D", "MP", "GF", "GA", "GD"};
panel.setLayout(new GridLayout(20, 20));
panel.add(createTeam);
panel.add(deleteTeam);
panel.add(new JLabel(""));
//JLabels to fill the space
}
}
足球俱乐部类:
import java.util.ArrayList;
public class FootballClub extends SportsClub{
FootballClub(int position, String name, int points, int wins, int defeats, int draws, int totalMatches, int goalF, int goalA, int goalD){
this.position = position;
this.name = name;
this.points = points;
this.wins = wins;
this.defeats = defeats;
this.draws = draws;
this.totalMatches = totalMatches;
this.goalF = goalF;
this.goalA = goalA;
this.goalD = goalD;
}
体育俱乐部类(摘要):
abstract class SportsClub {
int position;
String name;
int points;
int wins;
int defeats;
int draws;
int totalMatches;
int goalF;
int goalA;
int goalD;
}
最后是 LeagueManager,这是一个接口:
import java.util.ArrayList;
public interface LeagueManager {
ArrayList<FootballClub> originalLeagueTable = new ArrayList<FootballClub>();
FootballClub arsenal = new FootballClub(1, "Arsenal", 35, 11, 2, 2, 15, 30, 11, 19);
FootballClub liverpool = new FootballClub(2, "Liverpool", 30, 9, 3, 3, 15, 34, 18, 16);
FootballClub chelsea = new FootballClub(3, "Chelsea", 30, 9, 2, 2, 15, 30, 11, 19);
FootballClub mCity = new FootballClub(4, "Man City", 29, 9, 2, 4, 15, 41, 15, 26);
FootballClub everton = new FootballClub(5, "Everton", 28, 7, 1, 7, 15, 23, 14, 9);
FootballClub tot = new FootballClub(6, "Tottenham", 27, 8, 4, 3, 15, 15, 16, -1);
FootballClub newcastle = new FootballClub(7, "Newcastle", 26, 8, 5, 2, 15, 20, 21, -1);
FootballClub south = new FootballClub(8, "Southampton", 23, 6, 4, 5, 15, 19, 14, 5);
}
有人可以帮我吗?我已经尝试了好几天了。谢谢。