首页 > 解决方案 > 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()。奇怪的是我复制了我写的另一个程序的这个,它在那里没有问题。

标签: countergreenfoot

解决方案


推荐阅读