0

我正在用 java 编写一个程序,其中涉及到很多图形更改。结果我得到了一个stackoverflowexception。我已经看到很多问题已经通过在 cmd 中使用 Xss 命令解决了,但是这个特殊的问题是非常持久的。由于我使用的是 IDE,因此尝试使用 -Xss 解决它会产生多余的问题,例如 noclassdef found 错误,并且通常“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);
}

该计划有四个班级。我不确定问题出在此处还是其他地方,但我相信这是一个很好的起点。

4

0 回答 0