Note that there are some explanatory texts on larger screens.

plurals
  1. POJava enum class
    text
    copied!<p>I am implementing the enum class which I will use to retrieve some background in application, a current implementation of this class is here:</p> <pre><code>public enum Painters{ /** * Available painters. */ Background(getBackgroundPainter()), InactiveBackground(getInactiveBackgroundPainter()), DesktopBackground(getBackgroundPainter()); /** * The background painter. */ private Painter&lt;Component&gt; _painter; /** * Constructor will initialize the object. */ Painters(Painter&lt;Component&gt; painter){ _painter = painter; } /** * Will return a current painter. * @return instance of Painter&lt;Component&gt; */ public Painter&lt;Component&gt; painter(){ return _painter; } private static Painter&lt;Component&gt; getBackgroundPainter(){ MattePainter mp = new MattePainter(Colors.White.alpha(1f)); PinstripePainter pp = new PinstripePainter(Colors.Gray.alpha(0.2f),45d); return (new CompoundPainter&lt;Component&gt;(mp, pp)); } private static Painter&lt;Component&gt; getInactiveBackgroundPainter(){ MattePainter mp = new MattePainter(Colors.White.alpha(1f)); GlossPainter gp = new GlossPainter(Colors.Gray.alpha(0.1f), GlossPainter.GlossPosition.BOTTOM); PinstripePainter pp = new PinstripePainter(Colors.Gray.alpha(0.2f), 45d); return (new CompoundPainter&lt;Component&gt;(mp, pp, gp)); } } </code></pre> <p>My problem is that I need to call the painter() method each time I trying to get a painter but I prefer just to write the type of the painter instead. I thought that if I can to extend the Painter by my enum then probably I will get the right functionality, but it looks that it is not possible in java. </p> <pre><code>public enum Painters extends Painter&lt;Component&gt; </code></pre> <p>Do you know any solution for this problem???</p> <p>Currently I am using it in this way:</p> <pre><code>Painters.Background.painter(); </code></pre> <p>but I need:</p> <pre><code>Painters.Background; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload