swing - Java: Create global graphics object -


I have increased the JPanel class to attract the graph. The problem I have encountered is that I have a global graphics The object is needed so that it can be called in many ways ... For example, I am trying to:

  public class graph, jpnell {personal graphics 2d G2D; Public Zero Paint Component (Graphics G) {g2d = (Graphics2D) G; } Public Zero Drawline (int horror, int verte) {g2d.someLogicToDrawMyGridLines (Sompram); }}  

This gives a null pointer exception - so my question is: How do I create a global graphics object? What is the best practice in this situation?

My suggestion would be:

  Public Class Graph, JPNL ( Public Zero Paint Commonant (Graphics G) {SuperPaintConant (G); G2D = (Graphics 2D) G; Dagridd Lines (G2D, ......);} Private Zero Drawgrid Line (Graphics 2DG2 Keep all the use of your graphics reference inside the code, ie, d, int horror, int verb. {G2d.someLogicToDrawMyGridLines (someperm);}}  

ie ColorComponent


Comments

Popular posts from this blog

java - Can't add JTree to JPanel of a JInternalFrame -

javascript - data.match(var) not working it seems -

javascript - How can I pause a jQuery .each() loop, while waiting for user input? -