Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

how to pass the Graphics object from the Paint method to another method?  RSS feed

 
Emran Hassan
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is the problem I am stuck in:
Write a method squareOfAsterisks that displays a solid square (the same number of rows and columns) of asterisks whose side is specified in integer parameter side. Incorporate this method into an applet that reads an integer value for side from the user and performs the drawing with the squareOfAsterisks method. This method should be called from the applet's paint method and should be passed the Graphics object from paint.

I am trying to learn Java on my own from a book, so far all the exercises had a similar example provided in the chapters except this one. Please help me.
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16028
87
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Exactly in the same was as you pass any object from any method to another method.

Make your new method so that it takes a Graphics object as a parameter. Then from the paint method, call your new method with the Graphics object.

See this part of The Java Tutorial: Passing Information to a Method or a Constructor
[ December 01, 2006: Message edited by: Jesper Young ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!