-4

我正在为我的编程课开发一个游戏,我在 Eclipse 中编写了没有可见错误的代码,但是当我编译它时,我收到以下错误消息:

TogizKumalak20.java:220:错误:类 board20 中的方法 moveBoard 不能应用于给定类型;playBoard.moveBoard(playTurn, keyCharAsInt); 必需:cup20 找到:int,int 原因:实际参数列表和形式参数列表的长度不同

我不确定是什么原因造成的以及如何解决它。非常感谢您的任何意见,并提前感谢您!

import java.awt.Container;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.event.ActionEvent;
import java.awt.event.MouseEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseMotionAdapter;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.geom.Ellipse2D;
import java.awt.geom.Point2D;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextField;
import java.awt.Cursor;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import javax.swing.*;
import java.io.*;
import javax.swing.JFileChooser;
import java.awt.Color;
import java.awt.event.*;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;


public class TogizKumalak20
{
    public static void main(String[] args)
    {
        TKFrame myFrame = new TKFrame();
        myFrame.setTitle("Togiz Kumalak U22");
        myFrame.setVisible(true);
    }
}

class TKFrame extends JFrame
{
    private TKPanel myPanel;
    private final int FRAMEW = 700;
    private final int FRAMEH = 700;

    public TKFrame()
    {
        setSize(FRAMEW, FRAMEH);

        myPanel = new TKPanel();
        Container contentPane = getContentPane();

        contentPane.add(myPanel);
        addWindowListener(new WindowCloser());

        JMenuBar menuBar = new JMenuBar();
        setJMenuBar(menuBar);

        JMenu fileMenu = new JMenu("File");
        menuBar.add(fileMenu);

        JMenuItem restartItem = new JMenuItem("Restart");
        fileMenu.add(restartItem);

        RestartListener myRestartListener = new RestartListener();
        restartItem.addActionListener(myRestartListener);

        JMenuItem exitItem = new JMenuItem("Exit");
        fileMenu.add(exitItem);

        ExitListener myExitListener = new ExitListener();
        exitItem.addActionListener(myExitListener);
    }

    private class WindowCloser extends WindowAdapter
    {
        public void windowClosing(WindowEvent event)
        {
            dispose();
        }
    }

    private class RestartListener implements ActionListener
    {
        public void actionPerformed(ActionEvent event)
        {

            myPanel.renewBoard();

            myPanel.renewTextArea();

            myPanel.setMoveCount(1);
        }
    }

    private class ExitListener implements ActionListener
    {
        public void actionPerformed(ActionEvent event)
        {
            System.exit(0);
        }
    }
}

class TKPanel extends JPanel
{
    private board20 playBoard;
    private int playTurn;
    private JTextArea actionRecordArea;
    private JScrollPane actionScrollPane;
    private int moveCount = 1;

    public TKPanel()
    {
        super();
        playTurn = 1;
        playBoard = new board20();
        actionRecordArea = new JTextArea(6, 24);
        actionRecordArea.setEditable(false);
        actionScrollPane = new JScrollPane(actionRecordArea,
            JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
            JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
        add(actionScrollPane, "North");
        addMouseListener(new MouseHandler());
        addMouseMotionListener(new MouseMotionHandler());
        addKeyListener(new KeyHandler());
        setFocusable(true);
    }

    public void renewBoard()
    {
        playBoard = new board20();
        repaint();
    }

    public void renewTextArea()
    {
        actionRecordArea.setText("");
        repaint();
    }

    public int getMoveCount()
    {
        return moveCount;
    }

    public void setMoveCount(int countIn)
    {
        moveCount = countIn;
    }

    public void paintComponent(Graphics g)
    {
        super.paintComponent(g);
        Graphics2D g2 = (Graphics2D) g;
        playBoard.drawBoard(g2);
    }

    private class MouseHandler extends MouseAdapter
    {
        public void mouseClicked(MouseEvent event)
        {
            cup20 returnedCup;

            returnedCup = playBoard.isTheMouseInaCup(event.getPoint());

            if(returnedCup != null)
            {
                if(returnedCup.getWhoseCup() == playTurn)
                {
                    setCursor(Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR));

                    playBoard.moveBoard(returnedCup);

                    int whatCupNumber = playBoard.getCupNumber(returnedCup);
                    actionRecordArea.append("Move:  " + moveCount + ".  Player:  " + playTurn + ".  Cup:  " + whatCupNumber + ".\n");
                    moveCount++;

                    if(playTurn == 1)
                      playTurn = 2;
                    else
                      playTurn = 1;

                    repaint();
                }
            }
        }
    }

    private class MouseMotionHandler extends MouseMotionAdapter
    {
        public void mouseMoved(MouseEvent event)
        {
            cup20 retCup = playBoard.isTheMouseInaCup(event.getPoint());

            if(retCup == null)
              setCursor(Cursor.getDefaultCursor());
            else
            {
                if(retCup.getWhoseCup() == playTurn)
                  setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
                else
                  setCursor(Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR));
            }
        }
    }

    private class KeyHandler extends KeyAdapter
    {
        public void keyTyped(KeyEvent event)
        {
            char keyChar = event.getKeyChar();

            int keyCharAsInt;

            if(keyChar == '1' || keyChar == '2' || keyChar == '3' || keyChar == '4' || keyChar == '5' || keyChar == '6' || keyChar =='7' || keyChar == '8' || keyChar == '9')
            {
                keyCharAsInt = (int) keyChar - 48;

                setCursor(Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR));

                playBoard.moveBoard(playTurn, keyCharAsInt);

                actionRecordArea.append("Move:  " + moveCount + ".  Player:  " + playTurn + ".  Cup:  " + keyCharAsInt + ".\n");
                moveCount++;

                if(playTurn == 1)
                  playTurn = 2;
                else
                  playTurn = 1;

                repaint();
            }
            else
            {
            }
        }

        public board20 getBoard()
        {
            return playBoard;
        }

        public String getText()
        {
            return actionRecordArea.getText();
        }

        public void setText(String textIn)

    {
            actionRecordArea.setText(textIn);
        }
    }

}
4

2 回答 2

2

(粗体表示原来的错误信息,就位。)

TogizKumalak20.java的第220行,类 board20 中的方法 moveBoard 不能给定的类型调用(它被称为playBoard.moveBoard(playTurn, keyCharAsInt)因为该方法被声明为采用单个cup20参数,但有两个参数(int,int ) 在方法调用中使用,因此实际参数列表和形式参数列表的长度不同

于 2013-03-26T22:53:41.470 回答
0

你有另一个只需要一个参数的 moveBoard 调用。你有理由认为有一个版本的方法需要两个整数作为参数吗?如果是这样,您使用的是正确版本的 board20 吗?那是你的课,还是图书馆课?你不给它来源。

该错误告诉您没有具有该方法签名的方法(参数的数量和类型构成签名)。编译器可用的类版本中没有这样的方法。

于 2013-03-26T22:36:43.930 回答