RickyD Posted July 22, 2015 Share Posted July 22, 2015 I have variables in my secondary class I want to implement in the onPaint of my main class. How would I pull in those vars? Quote Link to comment Share on other sites More sharing options...
Bobrocket Posted July 22, 2015 Share Posted July 22, 2015 StaticSecondaryClass.variable; //If .variable has the "public static" modifier StaticSecondaryClass ssc = new StaticSecondaryClass(); ssc.variable; //If .variable has just a "public" modifier 1 Quote Link to comment Share on other sites More sharing options...
Botre Posted July 22, 2015 Share Posted July 22, 2015 I have variables in my secondary class I want to implement in the onPaint of my main class. How would I pull in those vars? Method 1 in your SecondaryClass: toPaint(Graphics2D g2d){ g2d.drawString("This is text added to the g2d by the secondary class", 1, 1); } in your Primary Class: private SecondaryClass instance; @override onPaint(Graphics2D g2d) { instance.toPaint(g2d); } Method 2 You could also just use accessors: in your SecondaryClass: private x var1 = something; private x var2= something; public x getVar1() {return var1;} public x getVar2() {return var2;} in your Primary Class: private SecondaryClass instance; @override onPaint(Graphics2D g2d) { g2d.draw(instance.getVar1(), 0, 0); g2d.draw(instance.getVar2(), 0, 0); } Written without an IDE but should get the point across, there are other ways to do it but these are a good start imho. 1 Quote Link to comment Share on other sites More sharing options...
RickyD Posted July 22, 2015 Author Share Posted July 22, 2015 Method 1 in your SecondaryClass: toPaint(Graphics2D g2d){ g2d.drawString("This is text added to the g2d by the secondary class", 1, 1); } in your Primary Class: private SecondaryClass instance; @override onPaint(Graphics2D g2d) { instance.toPaint(g2d); } Method 2 You could also just use accessors: in your SecondaryClass: private x var1 = something; private x var2= something; public x getVar1() {return var1;} public x getVar2() {return var2;} in your Primary Class: private SecondaryClass instance; @override onPaint(Graphics2D g2d) { g2d.draw(instance.getVar1(), 0, 0); g2d.draw(instance.getVar2(), 0, 0); } Written without an IDE but should get the point across, there are other ways to do it but these are a good start imho. Method 1 didn't work Quote Link to comment Share on other sites More sharing options...
Botre Posted July 22, 2015 Share Posted July 22, 2015 Method 1 didn't work You didn't do it right :.x Quote Link to comment Share on other sites More sharing options...
Tom Posted July 23, 2015 Share Posted July 23, 2015 There is a better way to do this, but I don't know if it is what you want. You can have you entire paint in another class, then just add it as the paint listener on script start, or where ever you need it. I think its like, script.addPaintListener(new YOURPAINTCLASS) Then just implement the paint listener in that class and tada you're done Quote Link to comment Share on other sites More sharing options...