我正在用java编写一个程序,它涉及很多图形更改。结果我得到了stackoverflowexception。我已经看到很多问题已经通过在cmd中使用Xss命令解决了,但是这个特殊问题非常持久。由于我使用IDE,尝试使用-Xss解决它会产生冗余问题,例如noclassdef发现错误,并且通常'javac'拒绝使用“找不到符号”runt编译源代码。程序代码有点冗长,所以我想知道是否有人遇到过这样的问题,并愿意分享解决方案。谢谢。
public void updateTable()
{
for(int p1Finder = 0; p1Finder < playerReference.length; p1Finder++) //for loop to locate the playerReference associated with P1
{
if(update.getP1Name().equalsIgnoreCase(playerReference[p1Finder].getName())) //p1 reference found
{
if(update.getP1Score() > update.getP2Score()) //If the player on the left (P1) wins
{
playerReference[p1Finder].setPlays();
playerReference[p1Finder].setWins();
playerReference[p1Finder].setGoalsFor(update.getP1Score());
playerReference[p1Finder].setGoalsAgainst(update.getP2Score());
playerReference[p1Finder].setGoalDifference();
playerReference[p1Finder].setPoints();
}
else if(update.getP1Score() < update.getP2Score()) //If the player on the left (P1) loses
{
}
else //if the game ends in a draw
{
}
}
repaint();
}
}
上面的方法应该适用于某些分数,然后重新绘制一个联赛表。绘制表格中的所有内容(即使用Graphics方法)。和我的程序中的paintComponent方法如下所示。
protected void paintComponent(Graphics ink)
{
super.paintComponent(ink);
Font decorativeFont = new Font("Harrington", Font.BOLD, 30);
Font boldFont = new Font("", Font.BOLD ,20);
Font normalFont = new Font("", Font.PLAIN ,18);
ink.setFont(decorativeFont);
ink.setColor(Color.BLACK);
int yStars = 60; //y coordinate for the decorative stars
int xStars = 65; //x coordinate for the decorative stars
int countStars = 0;
//Draw the title of the football league
ink.drawString("NJENGA FOOTBALL LEAGUE", 115, 30);
//draw the decorative stars below the title
while(countStars < 55)
{
ink.drawString("*", xStars, yStars);
xStars = xStars + 10;
countStars++;
}
//remove decorative font and set the normal font
ink.setFont(boldFont);
//draw the fields that are used on the table ie.player, plays, wins etc
//use for loop
int xFields = 0; //x coordinate for the fields string names
int yFields = 80; //y coordinate for the fields string names
for(int counter = 0; counter < fieldNames.length; counter++)
{
ink.drawString(fieldNames[counter], xFields, yFields);
if(counter == 0)
{
xFields = xFields + 150;
}
else
{
xFields = xFields + 73;
}
}
//draw a blue line between the fields and the records
ink.setColor(Color.BLUE);
ink.fillRect(0, 90, getWidth(), 5);
//draw the player names and data into the table
ink.setFont(normalFont);
ink.setColor(Color.BLACK);
int xRecord;
int yRecord = 140;
for(int counter = 0; counter < playerReference.length; counter++)
{
xRecord = 0;
ink.drawString(playerReference[counter].getName().toUpperCase(), xRecord, yRecord); //draw the player name
xRecord = xRecord + 153; //increase the xCoordinate to facilitate proper drawing of next field
ink.drawString((playerReference[counter].getPlays()+""), xRecord, yRecord); //draw the player plays
xRecord = xRecord + 73; //increase the xCoordinate to facilitate proper drawing of next field
ink.drawString((playerReference[counter].getWins()+""), xRecord, yRecord); //draw the player wins
xRecord = xRecord + 73; //increase the xCoordinate to facilitate proper drawing of next field
ink.drawString((playerReference[counter].getDraws()+""), xRecord, yRecord); //draw the player draws
xRecord = xRecord + 73; //increase the xCoordinate to facilitate proper drawing of next field
ink.drawString((playerReference[counter].getLosses()+""), xRecord, yRecord); //draw the player losses
xRecord = xRecord + 73; //increase the xCoordinate to facilitate proper drawing of next field
ink.drawString((playerReference[counter].getGoalsFor()+""), xRecord, yRecord); //draw the player goals scored
xRecord = xRecord + 73; //increase the xCoordinate to facilitate proper drawing of next field
ink.drawString((playerReference[counter].getGoalsAgainst()+""), xRecord, yRecord); //draw the player goals conceeded
xRecord = xRecord + 73; //increase the xCoordinate to facilitate proper drawing of next field
ink.drawString((playerReference[counter].getGoalDifference()+""), xRecord, yRecord); //draw the player goal difference
xRecord = xRecord + 73; //increase the xCoordinate to facilitate proper drawing of next field
ink.drawString((playerReference[counter].getPoints()+""), xRecord, yRecord); //draw the player points
yRecord = yRecord + 50; //increase the yCoordinate to facilitate proper drawing of next record
}
//draw a blue line between the fields and the records
ink.setColor(Color.BLUE);
ink.fillRect(0, yRecord, getWidth(), 5);
}
该计划共有四个班级。我不确定问题是在这里还是其他地方,但我相信它是一个好的开始。