Jump to content
Frequently Asked Questions
  • Are you not able to open the client? Try following our getting started guide
  • Still not working? Try downloading and running JarFix
  • Help! My bot doesn't do anything! Enable fresh start in client settings and restart the client
  • How to purchase with PayPal/OSRS/Crypto gold? You can purchase vouchers from other users
  • Try asking for help in the chatbox
  • Paint issues


    JPHamlett
     Share

    Recommended Posts

    I have the following code

     

        String dateToFormat(long time) {
            double hour = Math.floor(time);
            double minute = (time - hour) * 60;
    
            return String.format("%02d:%02d", hour, minute);
        }
    
    @Override
        public void onPaint(Graphics graphics) {
            int numPerHr = (int)(numMade / ((System.currentTimeMillis() - timeBegan) / 3600000.0D));
            graphics.setColor(Color.BLUE);
            graphics.fillRect(518, 0, 246, 165);
            graphics.setColor(Color.BLACK);
            graphics.setFont(Font.getFont(Font.SERIF));
            graphics.drawString("Running for: " + timer.formatTime(), 549, 25);
            graphics.drawString("Num made: " + numMade, 549, 50);
            graphics.drawString("Num per hour: " + numPerHr, 549, 75);
            graphics.drawString("Time remaining: " + dateToFormat(timer.remaining()), 549, 100);
            super.onPaint(graphics);
        }

    But when I run the script the paint looks like it's not rendering the final line

     

    Screengrab: https://imgur.com/9K9muTy

     

    So my questions are how do I get the last line to render, and why is my text so blurry?

    Link to comment
    Share on other sites

    Generally I've found in my personal scripts that the issue with strings not drawing is a logical error on my part, that's not to say it necessarily is in yours, but it may be worth double checking the method in question is operating as expected. (Try printing the result to the log).

     

    As for blurry text, I've found toggling Anti aliasing to be a big help, see below.

     

    Within onPaint:

     

    [code]

    Graphics2D g = (Graphics2D) graphics;
    
    g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
            RenderingHints.VALUE_TEXT_ANTIALIAS_ON);

    [/code]

    Link to comment
    Share on other sites

    Wrap your paint with a try/catch and log the errors to find out what the problem is.

    
            try {
              ...paint...
            } catch (Exception e) {
                for (StackTraceElement ex : e.getStackTrace())
                    log("Error onPaint: " + ex.toString());
            }

    Something like that should show you what's going on.

    Link to comment
    Share on other sites

    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
     Share

    ×
    ×
    • Create New...

    Important Information

    We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.