• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Java Problem

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hello.. i am doing java at school and have a problem with something that we are doing.

We are making a Colony program(Game of Life). At the moment we have been given the Colony Model in a packed .jar file(contains classes that do all the work), and we have to make the GUI. We have been given an excercise just to try and interect with the model(call methods from the model and print out the return values - working in dos atm so no actuall graphical interface). My problem is that I am having trouble interacting with the model. when i call on methods from the model i get 'non-static method cannot be reference from a static context' - this happens even when called from a non-static method. Below is the model specs. Atm I just wanna setMaxGen to a number and be able to getMaxGen and print the value on screen.. thanks for any help.



Colony Model - Brief Specification


Class ColonyCtlr

Field Summary
Colony states:
static final int STOPPED
static final int PAUSED
static final int STEPPING
static final int RUNNING
Colony stop status:
static final int NORMAL - growing normally
static final int DEAD - no living cells
static final int STABLE - identical to the next generation
static final int CYCLIC - repeated within specified generations
static final int MAXGEN - reached maximum generations

Constructor Summary
ColonyCtlr(ColonyListener listener_)

Method Summary
void start()
Starts the life generation process in the Colony.

void stop()
Stops the life generation process and resets the generation number leaving the current generation in tact.

void pause()
Pauses the life generation process.

void step()
Produces the next generation of the Colony.

void clear()
Clears the colony ready to start again.

void createCell(int x_, int y_)
Creates a living cell at position (x_,y_)

void deleteCell(int x_, int y_)
Deletes a living cell at position (x_,y_)

void setMaxGen(int max_)
Sets the maximum number of generations

int getMaxGen()
Returns the maximum number of generations

int getState()
Returns the state of the colony,
i.e. either stopped, paused, stepping or running.

int getStopStatus()
Returns the status (reason) of the stopped state,
i.e. ok, dead, stable, cyclic or maximum generations reached.

boolean isAliveAt(int x_, int y_)
Returns whether a cell is alive at posn (x_,y_)
in the current generation

int getGenNum()
Returns the current generation number

int getPopulationCount()
Returns the current population count





Interface ColonyListener

Method Summary
void colonyChanged()
Indicates some change has occurred in the colony


 
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

can you please post some code with which we can understand your problem?

Stefan
 
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi there

you have to call setMaxGen on a ColonyCtlr object, that is :



you can't call ColonyCtlr.setMaxGen(32) because setMaxGen() is not a static method, that means you have to call that method on an instance of ColonyCtlr

If it's not the answer you wanted, post some code as Stefan requested.

Arnaud

[edit, changed some ubb codes]
[ October 11, 2004: Message edited by: Arnaud Burlet ]
 
Burnz316
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i was just trying to just call on ColonyCtlr.setMaxGen(32)

my new code is below.. i get one error from that

cannot resolve symbol - variable listener

-thanks for the help



Edit: code updated
[ October 11, 2004: Message edited by: Burnz316 ]
 
Burnz316
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ok fixed my code.. works now.. thanks for the help!

 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Mr Burn(s),

Welcome to JavaRanch!

You may not have read our naming policy on the way in. It requires that you use a full, real (sounding) first and last name for your display name. You can change your display name here.

Thanks, and hope to see you around the Ranch, pardner!
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic