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
  • Paint issues


    JPHamlett

    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

    Archived

    This topic is now archived and is closed to further replies.

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