counter - Add() 在 Java 中不起作用(Greenfoot)
问题描述
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and
MouseInfo)
/**
* Write a description of class MyWorld here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class MyWorld extends World
{
private Counter counter;
public Counter würfelanzahl;
public int Felder;
/**
* Constructor for objects of class MyWorld.
*
*/
public MyWorld()
{
// Create a new world with 600x400 cells with a cell size of 1x1 pixels.
super(900, 900, 1);
addObject(new Würfel1(), 400, 500);
addObject(new Würfel2(), 500, 500);
addObject(new Auto(), 825, 825);
addObject(new katze(), 790, 800);
würfelanzahl=new Counter("Felder: ");
addObject(würfelanzahl, 465, 550);
*getwürfelanzahl().add(100);*
Felder=0;
}
public Counter getwürfelanzahl()
{
return würfelanzahl;
}
public void addwürfelanzahl(int würfelanzahl)
{
Felder+=würfelanzahl;
}
}
在这里,我尝试将整数添加到计数器。我不明白为什么 add() 不起作用。我收到错误,它没有找到符号并询问我是否是指 act()。奇怪的是我复制了我写的另一个程序的这个,它在那里没有问题。
解决方案
推荐阅读
- python-3.x - 在 seaborn 库中绘制 Lineplot 时遇到问题
- python - Django:经过身份验证的用户的相关对象
- python - Python - 匹配除了换行符之外没有空格的字符串?
- java - 这是我的第一个 servlet 程序,我有问题
- python - Python 为 Selenium 导入 Chrome Webdriver
- javascript - 如何使用 express 显示实时变量 node.js
- javascript - 为什么这个阶乘查找算法不是 O(n!) 运行时复杂度?
- c - 逻辑&&和||怎么做 算子随着增量和减量工作?
- html - 引导导航栏汉堡下拉菜单在桌面(所有分辨率)上工作正常,但在移动设备上不工作
- python - 有没有办法根据用户输入调用特定变量?