Jump to content
View in the app

A better way to browse. Learn more.

OSBot :: 2007 OSRS Botting

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Accessing onPaint method from other class

Featured Replies

Hi, I want onPaint to be different for each task my script is doing so it can switch stats when needed but I don't know how.

I tried this:

// main class 
public void onPaint(Graphics2D g) {
        Fletch fletch = new Fletch();
        fletch.exchangeContext(getBot());
        fletch.FletcherLoopPaint(Graphics2D g);

// Fletch class
   public void FletcherLoopPaint(Graphics g1) {
	// paint
     
   }
  

I am stuck at the onPaint method arguments (or parameters) .

Edited by The Undefeated

4 minutes ago, The Undefeated said:

Hi, I want onPaint to be different for each task my script is doing so it can switch stats when needed but I don't know how.

I tried this:


// main class 
public void onPaint(Graphics2D g) {
        Fletch fletch = new Fletch();
        fletch.exchangeContext(getBot());
        fletch.FletcherLoopPaint(Graphics2D g);

// Fletch class
   public void FletcherLoopPaint(Graphics g1) {
	// paint
     
   }
  

I am stuck at the onPaint method arguments (or parameters) .

 

You could either have a single paint and update the information you want to be displayed when you change tasks, or if you REALLY want a new onPaint method for each task you could make your Task class implement Painter:

import org.osbot.rs07.canvas.paint.Painter;

import java.awt.*;

public class Example implements Painter {
  
    @Override
    public void onPaint(Graphics2D graphics2D) {
        
    }
}

 

And then when you change the current Task that is executing:

getBot().removePainter(previousTask);
getBot().addPainter(newTask);

 

2 minutes ago, Explv said:

 

You could either have a single paint and update the information you want to be displayed when you change tasks, or if you REALLY want a new onPaint method for each task you could make your Task class implement Painter:


import org.osbot.rs07.canvas.paint.Painter;

import java.awt.*;

public class Example implements Painter {
  
    @Override
    public void onPaint(Graphics2D graphics2D) {
        
    }
}

 

And then when you change the current Task that is executing:


getBot().removePainter(previousTask);
getBot().addPainter(newTask);

 

Adding a bit to it, if you are going to end up creating new paint classes for each of your tasks, you will most likely end up repeating lots of code, thus violating the DRY principle.

If you are going to create a new painter for each of your classes you might want to create a manager class for your paints and abstract the code you are going to reuse.

Just my two cents :feels:

  • Author
9 minutes ago, Explv said:

 

You could either have a single paint and update the information you want to be displayed when you change tasks, or if you REALLY want a new onPaint method for each task you could make your Task class implement Painter:


import org.osbot.rs07.canvas.paint.Painter;

import java.awt.*;

public class Example implements Painter {
  
    @Override
    public void onPaint(Graphics2D graphics2D) {
        
    }
}

 

And then when you change the current Task that is executing:


getBot().removePainter(previousTask);
getBot().addPainter(newTask);

 

When I implement Painter the class has to be abstract which results in me not being able to call methods from another class using this:

        Fletch fletch = new Fletch();
        fletch.exchangeContext(getBot());
        fletch.FletcherLoop();
5 minutes ago, Vilius said:

Adding a bit to it, if you are going to end up creating new paint classes for each of your tasks, you will most likely end up repeating lots of code, thus violating the DRY principle.

If you are going to create a new painter for each of your classes you might want to create a manager class for your paints and abstract the code you are going to reuse.

Just my two cents :feels:

My plan was to just keep the basic paint in the main class and only change the stats.

 

Edited by The Undefeated

Recently Browsing 0

  • No registered users viewing this page.

Account

Navigation

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.