Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Calling seperate functions

 
Rob Brew
Ranch Hand
Posts: 101
  • 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
  • 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
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have:
 
Paul Clapham
Sheriff
Posts: 20713
29
Eclipse IDE Firefox Browser MySQL Database
  • 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
  • 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
Posts: 48363
56
  • 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
  • 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
Posts: 48363
56
  • 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
  • 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:
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic