Java 骰子模拟

Java 骰子模拟,java,simulation,Java,Simulation,因此,这段代码用于制作一个骰子模拟,正如标题所推断的那样。我已接近完成,但我遇到了一个路障,第116行出现错误:a.fillOval(m-diameter/2,n-diameter/2,diameter,diameter) 错误:找不到符号 符号:可变直径 位置:类骰子您已将其定义为直径r import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.util.Random; public class

因此,这段代码用于制作一个骰子模拟,正如标题所推断的那样。我已接近完成,但我遇到了一个路障,第116行出现错误:
a.fillOval(m-diameter/2,n-diameter/2,diameter,diameter)
错误:找不到符号
符号:可变直径

位置:类骰子

您已将其定义为直径r

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.Random;
public class DiceSimulation extends JApplet
{
  /* Initialising Applet */
  public DiceSimulation()
  {
    this.setContentPane(new DiceRollPanel());
  }
  /* method main */
  public static void main(String[] args)
  {
    /* frame */
    JFrame dicewindow = new JFrame();
    dicewindow.setTitle("Dice Simulation");
    dicewindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    dicewindow.setContentPane(new DiceRollPanel());
    dicewindow.pack();
    dicewindow.setVisible(true);
  }
}
class DiceRollPanel extends JPanel
{
  /* Variables declaration */
  private Dice left;
  private Dice right;
  /* constructor */
  DiceRollPanel()
  {
    left = new Dice();
    right = new Dice();
    JButton dicerollButton = new JButton("Click");
    /* dice button font */
    dicerollButton.setFont(new Font("Calibri", Font.PLAIN, 24));
    dicerollButton.addActionListener(new DiceRollListener());
    JPanel dicerollPanel =new JPanel();
    /* dice simulation layout */
    dicerollPanel.setLayout(new GridLayout(1, 2, 6, 0));
    dicerollPanel.add(left);
    dicerollPanel.add(right);
    this.setLayout(new BorderLayout());
    this.add(dicerollButton, BorderLayout.SOUTH);
    this.add(dicerollPanel, BorderLayout.CENTER);
  }
  /* Class for DiceRoll button */
  private class DiceRollListener implements ActionListener
  {
    /* performing action */
    public void actionPerformed(ActionEvent e)
    {
      left.rolls();
      right.rolls();
    }
  }
}
class Dice extends JPanel
{
  /* variable declaration */
  private int values; /* values on the Dice face */
  private int diameterr = 9; /* Diameter of the spots */
  /* class variables */
  private static Random random = new Random();
  public Dice()
  {
    setBackground(Color.white);
    setPreferredSize(new Dimension(90,90));
    rolls();
  }
  public int rolls()
  {
    int value = random.nextInt(6) + 1;
    setValues(value);
    return value;
  }
  public int getValues()
  {
    return values;
  }
  public void setValues(int spots)
  {
    values = spots;
    repaint();
  }
  public void paint(Graphics a)
  {
    super.paint(a);
    int width = getWidth();
    int height = getHeight();
    switch (values)
    {
      case 1: drawSpots(a, width/2, height/2);
              break;
      case 2: drawSpots(a, width/4, height/4);
              drawSpots(a, 3*width/4, 3*height/4);
              break;
      case 3: drawSpots(a, width/2, height/2);
      case 4: drawSpots(a, width/4, height/4);
              drawSpots(a, 3*width/4, 3*height/4);
              drawSpots(a, 3*width/4, height/4);
              drawSpots(a, width/4, 3*height/4);
              break;
      case 5:drawSpots(a, width/2, height/2); 
      case 6:drawSpots(a, width/4, height/4);
             drawSpots(a, 3*width/4, 3*height/4);
             drawSpots(a, 3*width/4, height/4);
             drawSpots(a, width/4, 3*height/4);
             drawSpots(a, width/4, height/2);
             drawSpots(a, 3*width/4, height/2);
             break;
    }
  }
  private void drawSpots(Graphics a, int m, int n) /* drawSpots fn */
               {
   a.fillOval(m-diameter/2, n-diameter/2, diameter, diameter);
  }
}
并将其用作
直径

  private int diameterr = 9; /* Diameter of the spots */

我真的与众不同。非常感谢您的垂钓。
   a.fillOval(m-diameter/2, n-diameter/2, diameter, diameter);