Jump to content

Use onPaint from another class


RickyD

Recommended Posts

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
Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

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