Jump to content

Use onPaint from another class


Recommended Posts

Posted

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.

  • Like 1
Posted

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

Posted

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...