它说数字 125,100 是以下行中的不兼容类型: _die1 = newDie(125,100);
我不明白,因为在 NewDie 方法中它需要 int 2 int,所以它应该可以正常工作......?!基本上这个程序创建骰子卷,我试图让它显示卷#2
import java.awt.*;
// The panel which holds the two dice
import javax.swing.*;
public class DicePanel extends JPanel
{
// instance variables
private Die _die1, _die2;
private int _roll;
/**
* Constructor for objects of class DicePanel
*/
public DicePanel()
{
// initialise instance variables
super();
setBackground(Color.GRAY);
_die1 = new Die(125,100);
_die2 = new Die(250,100);
roll();
}
// display the dice in the panel
public void paintComponent(Graphics pen)
{
super.paintComponent(pen);
Graphics2D aBetterPen = (Graphics2D)pen;
_die1.paint(aBetterPen);
_die2.paint(aBetterPen);
}
// roll both dice and display them
public void roll()
{
// _die1 = new Two(125,100);
// _die2 = new Three(250,100);
_die1 = newDie(125,100);
// _die2 = DicePanel.newDie(250,100);
//repaint();
}
// retrieve the value of each die
public int getDie1()
{
return _die1.getValue();
}
public int getDie2()
{
return _die2.getValue();
}
// factory method for a die
public void newDie(int x, int y){
//_roll = randomNumber(1,6);
_die1 = new Two(x,y);
// _die2 = new Three(x,y);
}
// random number generator to return and integer between two integers, inclusive.
public static int randomNumber(int low, int high){
return low + (int)(Math.random()*(high-low+1));
}
}