Jump to content

onPaint()


Recommended Posts

Posted
public void onPaint(Graphics g) {

Graphics2D gr = (Graphics2D) g;
gr.drawString("hahhahahaahha", 16, 105);

}

any idea why this isn't drawing anything on screen? Iv been messing around with it and it just wont draw anything to screen . I tried just using g (not gr) and still no luck.

 

public void onPaint(Graphics2D gr) {

gr.drawString("hahhahahaahha", 16, 105);

}

was the wrong parameter ^_^

Posted (edited)
public void onPaint(Graphics g) {

Graphics2D gr = (Graphics2D) g;
gr.drawString("hahhahahaahha", 16, 105);

}

any idea why this isn't drawing anything on screen? Iv been messing around with it and it just wont draw anything to screen . I tried just using g (not gr) and still no luck.

 

 

 

You override the methods in Script when you want to use them, this means both the return type and parameters must be identical:

@ScriptManifest(author = "", name = "", info = "", version = 0, logo = "")
public class Main extends Script{

    @Override
    public void onStart(){

    }

    @Override
    public int onLoop() throws InterruptedException{

        return 0;
    }

    @Override
    public void onPaint(Graphics2D g){

    }

    @Override
    public void onExit(){

    }
}
Edited by Explv
Posted (edited)

i only started learning how to do it earlier today but shouldnt this;

gr.drawString("hahhahahaahha", 16, 105);

be just

g.drawString("hahhahahaahha", 16, 105);

like i said, i just started today so i dont know if that 'r' makes any of a difference. i just know that i dont have it in mine and it works emote32342.png

 

 

well i have

public void onPaint(Graphics2D g)

{

Graphics2D gr = g;

g.drawString("hahahahhahahh", 16, 105);

}

 

 

 

yeah, i should have left it as g. I casted it to Graphics2D because initially my parameter was only Graphics and i knew it should be Graphics2D...Why did i not think of changing the parameter?...i dont know sad.png

 

You can look up type casting in java if u didn't understand this bit of code

Graphics2D gr = (Graphics2D) g;

It looks to me like gr in your code is an unused variable. meaning it has been assigned a value but it is never being called. Your code should work without that line.

Edited by ni562
Posted

yeah, i should have left it as g. I casted it to Graphics2D because initially my parameter was only Graphics and i knew it should be Graphics2D...Why did i not think of changing the parameter?...i dont know sad.png

 

You can look up type casting in java if u didn't understand this bit of code

Graphics2D gr = (Graphics2D) g;

It looks to me like gr in your code is an unused variable. meaning it has been assigned a value but it is never being called.

i should of refreshed before editing my post NotLikeThis haha 

 

i think i just pretty much copied and pasted from pugs tutorial :doge:

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...