Jump to content

Paint won't show


Jack Shep

Recommended Posts

I know this seems like a rookie problem but I can't find the issue. Here's my paint.

@Override
    public void onPaint(Graphics2D g) {
        
        DecimalFormat df = new DecimalFormat("#");
        timeRan = System.currentTimeMillis() - this.timeBegan;
        currentXp = skills.getExperience(Skill.FLETCHING);
        
        if (currentXp > logXp) {
            itemsMade += 15;
            logXp = currentXp;
        }
        
        if (guiOptionChose == "Arrow shafts") {

            int temp = Integer.parseInt(logPrice);
            int temp2 = Integer.parseInt(arrowShaftPrice);
            int temp3 = Integer.parseInt(headlessArrowPrice);
            int temp4 = Integer.parseInt(featherPrice);
            
            xpGained = currentXp - beginningXp;
            gpGained = (itemsMade * temp2) - (temp * itemsMade);
            totalGpGained = gpGained / 1000;
            gpPerHour = (int)(gpGained / ((System.currentTimeMillis() - timeBegan) / 3600000.0D));
            totalGpPerHour = gpPerHour / 1000;
        }
        
        if (guiOptionChose == "Headless arrows") {

            int temp = Integer.parseInt(logPrice);
            int temp2 = Integer.parseInt(arrowShaftPrice);
            int temp3 = Integer.parseInt(headlessArrowPrice);
            int temp4 = Integer.parseInt(featherPrice);
            int temp5 = temp2 + temp4;
            
            xpGained = currentXp - beginningXp;
            gpGained = (itemsMade * temp3) - (temp5 * itemsMade);
            totalGpGained = gpGained / 1000;
            gpPerHour = (int)(gpGained / ((System.currentTimeMillis() - timeBegan) / 3600000.0D));
            totalGpPerHour = gpPerHour / 1000;
        }
        
        g.setColor(Color.WHITE);
        g.drawString("Run Time: " + ft(timeRan), 5, 260);
        g.drawString("Xp Gained: " + xpGained, 5, 280);
        g.drawString("Gp Gained: " + df.format(totalGpGained) + " k", 5, 300);
        g.drawString("Gp Per Hour: " + df.format(totalGpPerHour) + " k/hr", 5, 320);
    }

 

Edited by Jack Shep
Link to comment
Share on other sites

I just noticed you're parsing a lot of strings to integers, so I suspect that's throwing an NumberFormatException error which is preventing the paint from being rendered. I would avoid parsing anything on the paint method, as the rendering is called a stupid amount of times per second and so you're re-parsing again and again. It's both inefficient and likely causing problems.

You should perhaps paint the raw string values and see whether they display as numbers, null, or empty. You can actually test this by going back to my earlier comment and making it "if (false)" instead, that way you're not parsing anything and are instead going straight to the drawing code.

Edited by liverare
Link to comment
Share on other sites

44 minutes ago, liverare said:

I just noticed you're parsing a lot of strings to integers, so I suspect that's throwing an NumberFormatException error which is preventing the paint from being rendered. I would avoid parsing anything on the paint method, as the rendering is called a stupid amount of times per second and so you're re-parsing again and again. It's both inefficient and likely causing problems.

You should perhaps paint the raw string values and see whether they display as numbers, null, or empty. You can actually test this by going back to my earlier comment and making it "if (false)" instead, that way you're not parsing anything and are instead going straight to the drawing code.

The only issue with leaving the variables as 'string' is that I don't actually print those values. I use them in my formulas to calculate the values of the variables that I do actually print. So I need those variables as 'int's. However, what you're saying about re-parsing again and again makes sense. I only need to convert the variables from 'string' to 'int' once as they're just the OSBuddy prices of a few items. So I'll try parsing my strings to integers in my onStart() method and see if that fixes the issue.

Link to comment
Share on other sites

1 hour ago, liverare said:

I just noticed you're parsing a lot of strings to integers, so I suspect that's throwing an NumberFormatException error which is preventing the paint from being rendered. I would avoid parsing anything on the paint method, as the rendering is called a stupid amount of times per second and so you're re-parsing again and again. It's both inefficient and likely causing problems.

You should perhaps paint the raw string values and see whether they display as numbers, null, or empty. You can actually test this by going back to my earlier comment and making it "if (false)" instead, that way you're not parsing anything and are instead going straight to the drawing code.

What I tried worked, my paint finally prints now, thank you for the help. But of course this generated another issue, now the script stops moments after I start it, although it sounds like an unrelated issue, the script worked 100% (besides for the paint) before I made the change. I tried parsing the strings in my onLoop() instead which fixed the new issues but again the constant re-parsing caused some issues. (So much lag that the script wouldn't run). Any Ideas?

Link to comment
Share on other sites

On 11/22/2018 at 3:20 AM, liverare said:

int something;

@Override
public int onLoop() throws InterruptedException {

  try {
    something = Integer.parseInt("12345");
  } catch (NumberFormatException e) {
    logger.error(e);
  }
  
  return 200;
}

@Override
public void onPaint(Graphics2D g) {
  
  g.drawString(25, 25, "Something: " + something);
}

 

It works! Thank you so much for your help

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