• Post Reply Bookmark Topic Watch Topic
  • New Topic

Method call question  RSS feed

 
Brandt Charles
Ranch Hand
Posts: 57
Chrome IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm working on something in which a single element of an object array, is to call its own method in which its shape is drawn. The method is this and is declared in the class that is instantiated:

public void draw(Graphics g)
{...}


The method should be called when the corresponding JButton is pushed. I know I am missing the obvious, but I cannot figure out how to get the parameter to match. The call from the event handler will look something like this:

shapes[0].draw( ); But what information do I need to put in the parentheses to execute the call correctly?

We haven't covered simple graphics, so I feel at a bit of a loss. Then again, I've been working on this project for a while, with this being the final part before success, so I may be somewhat delirious. I hope this makes sense, and hints are appreciated. Not looking for handouts as this is part of an assignment.
 
Keith Lynn
Ranch Hand
Posts: 2409
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your draw method needs to be called from within a method like paint(Graphics g) in which a variable of type Graphics is defined.
 
Brandt Charles
Ranch Hand
Posts: 57
Chrome IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, Keith, I'll give it a try!
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!