Jump to content

Paint disappearing when minimizing client, will only show when I hover over it ?


Zappster

Recommended Posts

This has been killing me for too long now :(

 

My paint is :

  private BufferedImage img = null;
    private void setBuffImage(){
    try {
        img = ImageIO.read(new URL("http://i.imgur.com/hxNYgK6.jpg"));
    } catch (IOException e) {
    }
    }
   
    private static final Font font1 = new Font("Gentium Basic", 0, 16);
    private static final Color color1 = Color.WHITE;
    @Override
    public void onPaint(Graphics2D g) {        
            timeRan = System.currentTimeMillis() - this.timeBegan;
            g.drawImage(img, 0, 335, null);
            g.setFont(font1);
            g.setColor(color1);
           
            g.drawString("Rewards collected: "+picked,70, 425);
            g.drawString("Farming XP(per hour): "+experienceTracker.getGainedXP(Skill.FARMING)+"("+experienceTracker.getGainedXPPerHour(Skill.FARMING)+")",280, 425);
          
            g.drawString("Status: "+statusWrite(),130, 455);
            g.drawString("Run time: " + ft(timeRan), 360, 385);
        
    }

 

the img gets set on script start. But everytime I minimise my client and open it again, my paint has disappeared and will only come back after I move my cursor on screen.

I have reason to believe setBuffImage() is the culprit as I didn't have this problem before adding it.

Link to comment
Share on other sites

Why?

If it was initialized correctly there's no need to check if it's null 30 times per second.

 

@OP empty try-catch blocks are a big no-no.

 

Well it has no impact on performance.

 

If imgur fucks up your script will still work.

 

onPaint runs on a separate thread so I think there could also be a point at the start where img is null

Edited by Explv
Link to comment
Share on other sites

Well it has no impact on performance.

 

If imgur fucks up your script will still work.

 

onPaint runs on a separate thread so I think there could also be a point at the start where img is null

 

Yeah, I should really move it to a local file :X

 

 

make a graphics var

Graphics2D paint = (Graphics2D) g.create();

and do:

paint.drawString(); etc.

 

I think its because you are using an entity debugger which overrides your paint.

 

I'll look into this now thanks for the fast reply

Link to comment
Share on other sites

Well it has no impact on performance.

 

If imgur fucks up your script will still work.

 

onPaint runs on a separate thread so I think there could also be a point at the start where img is null

 

You might be right since onPaint gets called before onStart.

 

@OP try this

public class Script {

	public static BufferedImage PAINT_BACKGROUND;
	
	static {
		try {
			PAINT_BACKGROUND = ImageIO.read(new URL("http://i.imgur.com/hxNYgK6.jpg"));
		} catch (MalformedURLException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	// onstart ...
	// onloop ...
	
}
Link to comment
Share on other sites

 

You might be right since onPaint gets called before onStart.

 

@OP try this

public class Script {

	public static BufferedImage PAINT_BACKGROUND;
	
	static {
		try {
			PAINT_BACKGROUND = ImageIO.read(new URL("http://i.imgur.com/hxNYgK6.jpg"));
		} catch (MalformedURLException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	// onstart ...
	// onloop ...
	
}

 

Sorry, the only thing that gets called in the onStart, relative to the onPaint, is the setBuffImage() call

Link to comment
Share on other sites

Sorry, the only thing that gets called in the onStart, relative to the onPaint, is the setBuffImage() call

 

onStart usually gets called AFTER the first onPaint called.

So if you use onStart to initialize variables used inside onPaint you could run into trouble.

You could use a static block to make sure the image gets initialize on time or you could null check the image variable in your onPaint.

 

Or maybe it's something entirely different that's causing the issue :p Getting any errors? Try providing a gif if you can.

  • Like 1
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...