Jump to content

onPaint()


ni562

Recommended Posts

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 ^_^

Link to comment
Share on other sites

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

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

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:

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