This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Calling seperate functions

 
Rob Brew
Ranch Hand
Posts: 101
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All. I'm passing class ship to the GUI, using GUI(Ship ship) but can't refer to it later in the code:

Main:


GUI:


Ship:

Any ideas?

Rob.
 
Manuel Petermann
Ranch Hand
Posts: 177
Hibernate Linux Python
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need to pass the ship object to the method somehow.
Either by a field or by parameter.
 
Rob Brew
Ranch Hand
Posts: 101
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have:
 
Paul Clapham
Sheriff
Pie
Posts: 20196
26
MySQL Database
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So far so good. But don't just ignore it. Take it and store it somewhere so you can use it later.

 
Rob Brew
Ranch Hand
Posts: 101
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Paul.

Thing is i want to call the functions of each instance of class Ships. I could pass the ArrayList ships to the GUI but is there an easier way?

At the moment all that's happening is i'm calling hit on an empty ship.
 
Campbell Ritchie
Sheriff
Pie
Posts: 47292
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need to distinguish passing a Ship from a List<Ship>. Both are possible, but they are very different from each other.

By an "empty ship", do you mean a null reference? You should avoid nulls as far as possible, as in the following example. Note the robust reaction to a null, and the bit about nulls in the documentation comment.
 
Rob Brew
Ranch Hand
Posts: 101
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
At the moment i'm passing an empty instance of Ship to the GUI thread.

I'm using a static method to cycle through each ship in the ArrayList Ships calling the method hit() on each of them. Is there an easier way?
 
Campbell Ritchie
Sheriff
Pie
Posts: 47292
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What do you mean by "empty instance"?
Why are you using a static method?
 
Rob Brew
Ranch Hand
Posts: 101
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm creating a ship without running setShips on it, therefore it's x and values are all zero.

I'm creating a static method hits which cycles through each member of the static arraylist ships and calls the method hits on it:
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic