Jump to content

Draggable Paint


Wizard

Recommended Posts

Paint.java class which implements MouseListener and MouseMotionListener classes that allow us to handle mouse events

import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;

import javax.imageio.ImageIO;

public class Paint implements MouseListener, MouseMotionListener {
	
	private int x;
	private int y;
	
	public Rectangle misc;
	public Rectangle stats;
	public Rectangle drag;

	public int draggedFromX = 0;
	public int draggedFromY = 0;
	
	public String status = "Idle";
	public String antiban = "Idle";
	
	public boolean showMisc = false;
	public boolean showStats = false;
	public boolean canDrag = false;
		
	public final Color color1 = new Color(36, 36, 36);
	public final Color color2 = new Color(103, 103, 103);
	public final Color color3 = new Color(103, 103, 103, 150);
	public final Color color4 = new Color(0, 102, 255);
	public final Color color5 = new Color(76, 76, 76, 100);
	public final Color color6 = new Color(255, 255, 255, 30);
	public final Color color7 = new Color(255, 255, 255);
	public final Color color8 = new Color(255, 255, 255, 40);
	public final BasicStroke stroke1 = new BasicStroke(1);
	public final Font font1 = new Font("Arial", 0, 9);
	public final Font font2 = new Font("Arial", 0, 10);
	public final Font font3 = new Font("Arial", 0, 12);
	public BufferedImage img1;
	public BufferedImage img2;
	public BufferedImage normal = null;
	public BufferedImage clicked = null;

	public Paint() {
		x = 261;
		y = 343;

		try {
			final URL cursorURL = new URL("http://i596.photobucket.com/albums/tt47/QaRTooN_/normal.png");
			final URL cursor80URL = new URL("http://i596.photobucket.com/albums/tt47/QaRTooN_/clicked-1.png");
			normal = ImageIO.read(cursorURL);
			clicked = ImageIO.read(cursor80URL);
			img1 = ImageIO.read(new URL("http://i596.photobucket.com/albums/tt47/QaRTooN_/reports-1.png"));
			img2 = ImageIO.read(new URL("http://i596.photobucket.com/albums/tt47/QaRTooN_/stats.png"));
		} catch (IOException e) {
			
		}
	}

	public void draw(Graphics g1) {
		Graphics2D g = (Graphics2D) g1;
		misc = new Rectangle(x + 3, y + 3, 27, 25);
		stats = new Rectangle(x + 31, y + 3, 27, 25);
		drag = new Rectangle(x + 4, y + 31, 258, 12);
		
		g.setColor(color1);
		g.fillRect(x, y, 258, 47);
		g.setColor(color2);
		g.setStroke(stroke1);
		g.drawRect(x + 1, y + 1, 255, 44);
		g.setColor(color3);
		g.setStroke(stroke1);
		g.draw(misc);
		g.setStroke(stroke1);
		g.draw(stats);
		g.drawRect(x + 61, y + 3, 193, 25);
		g.drawRect(x + 3, y + 31, 251, 12);
		if (showMisc == true) {
			g.setColor(color4);
			g.fillRect(x + 4, y + 4, 26, 24);
		}
		if (showStats == true) {
			g.setColor(color4);
			g.fillRect(x + 32, y + 4, 26, 24);
		}
		g.setColor(color4);
		g.fillRect(x + 62, y + 4, 50, 24);
		g.drawImage(img1, x + 5, y + 5, null);
		g.drawImage(img2, x + 34, y + 5, null);
		g.setColor(color6);
		g.fillRect(x, y + 30, 258, 8);
		g.setColor(color6);
		g.fillRect(x, y, 258, 17);
		g.setFont(font1);
		g.setColor(color7);
		g.drawString("Made by Wizard!", x + 83, y + 41);
		g.setFont(font2);
		g.drawString("3% to ", x + 121, y + 19);
		if (showMisc == true) {
			g.setColor(color1);
			g.fillRect(x, y - 104, 160, 104);
			g.fillRect(x + 1, y - 103, 157, 101);
			g.setColor(color2);
			g.drawRect(x + 1, y - 103, 157, 101);
			g.setColor(color8);
			g.fillRect(x, y - 104, 160, 59);
			g.setColor(color7);
			g.drawString("Status : " + status, x + 6, y - 71);
			g.drawString("Anti-Ban : " + antiban, x + 6, y - 58);
			g.drawString("Run Time : " , x + 6, y - 45);
			g.drawString("W.e  : ", x + 6, y - 32);
			g.drawString("W.e  : ", x + 6, y - 19);
			g.drawString("Profit : ", x + 6, y - 6);
			g.setFont(font3);
			g.drawString("Miscellaneous :-", x + 5, y - 87);
		}
		if (showStats == true) {
			g.setColor(color1);
			g.fillRect(x, y - 104, 160, 104);
			g.fillRect(x + 1, y - 103, 157, 101);
			g.setColor(color2);
			g.drawRect(x + 1, y - 103, 157, 101);
			g.setColor(color8);
			g.fillRect(x, y - 104, 160, 59);
			g.setFont(font2);
			g.setColor(color7);
			g.drawString("Exp Gained : ", x + 6, y - 71);
			g.drawString("Current Exp : ", x + 6, y - 58);
			g.drawString("Exp TNL : ", x + 6, y - 45);
			g.drawString("Exp/Hour : ", x + 6, y - 32);
			g.drawString("Start Level : ", x + 6, y - 19);
			g.drawString("Current Level : ", x + 6, y - 6);
			g.setFont(font3);
			g.drawString("Stats :-", x + 5, y - 87);
		}
	}
	
	@[member='Override']
	public void mousePressed(MouseEvent e) {
		if (drag.contains(e.getPoint())) {
			canDrag = true;
			draggedFromX = e.getX() - x;
			draggedFromY = e.getY() - y;
		}
		if(misc.contains(e.getPoint())) {
			if(showStats)
				showStats=false;
			showMisc = !showMisc;
		}
		if(stats.contains(e.getPoint())) {
			if(showMisc)
				showMisc = false;
			showStats = !showStats;
		}
	}

	@[member='Override']	
	public void mouseReleased(MouseEvent arg0) {	
		canDrag = false;	
	}

	@[member='Override']	
	public void mouseDragged(MouseEvent e) {
		if (canDrag) {		
			int newX = 0;		
			int newY = 0;			
			newX = e.getX() - draggedFromX;		
			newY = e.getY() - draggedFromY;		
			x = newX;		
			y = newY;
		}
		
	}

	@[member='Override']
	public void mouseMoved(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}

	@[member='Override']
	public void mouseClicked(MouseEvent arg0) {
		// TODO Auto-generated method stub
		
	}

	@[member='Override']
	public void mouseEntered(MouseEvent arg0) {
		// TODO Auto-generated method stub
		
	}

	@[member='Override']
	public void mouseExited(MouseEvent arg0) {
		// TODO Auto-generated method stub
		
	}
}

you can change to your preferred paint position

x = 261;
y = 343;

Now in your main class which extends Script, declare global Paint object

Paint paint;

in onStart add the following lines

paint = new Paint();//initiate paint Object
this.bot.getCanvas().addMouseMotionListener(paint);//Register paint object as mouse motion listener
this.bot.addMouseListener(paint);//register paint object as mouse listener

in onExit add the following to remove the listeners

this.bot.removeMouseListener(paint);
this.bot.getCanvas().removeMouseMotionListener(paint);
	

and in onPaint add the following line

paint.draw(arg0); //arg0 being the onDraws Graphics2D parameter

TO DRAG THE PAINT YOU HAVE TO HOLD YOUR MOUSE IN THE RECTANGLE WHERE Made by Wizard is written, that is the drag area!

 

and thats all!

here a picture of the results

 

esW7UPA.png

e1rFt3B.png

 

After being dragged to another location:

ceZuGbb.png

 

Special thanks for FrostyBug for telling me about the motion part >.>

boge.png

 

Enjoy!

Edited by Wizard
  • Like 5
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...