• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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:
 
reply
    Bookmark Topic Watch Topic
  • New Topic