• Post Reply Bookmark Topic Watch Topic
  • New Topic

Is it possible to make graphics such as "fillRect..." into a variable?  RSS feed

 
Joseph Alrawi
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey!

I want to do a simple background which is only rendered once onto my screen. I want to use

and make the whole background black, but only once. I wanted to try out making the fillRect into a variable so I can do:

The point is, I want G.fillRect(0, 0, getWidth(), getHeight()); to be a variable, even if this is the wrong way to approach what I want to accomplish, is it possible to make this line of code into one variable? The rest of my code if you need info:


Thanks!
 
Rob Spoor
Sheriff
Posts: 20903
81
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can create an interface (or use an existing one) and create anonymous implementations (Java 7 and before) or lambda's (Java 8) for them. For example, in Java 7:
Java 8 makes it a bit easier, also because there are already a lot of matching existing interfaces. For instance, using java.util.function.Consumer:
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!