-
Re: I had an old code it really sucked, so i now am making a new one
Do you know how to define a class with members?
Look at using the constructor to take the three values and to store them in the class's member variables.
See the tutorials if you don't know what I am talking about.
-
Re: I had an old code it really sucked, so i now am making a new one
allrighty tut's here i come!
-
Re: I had an old code it really sucked, so i now am making a new one
Code java:
<
import java.awt.*;
import java.awt.event.*;
import java.awt.Robot;
import java.awt.AWTException;
import java.awt.Rectangle;
import java.awt.Color;
import java.awt.Toolkit;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
public class GBpixel{
int a;
int b;
int c;
public variables (int b, a, c)
{
y = b;
x = a;
inputColor = c;
}
public int checkColor(Color inputColor) throws Exception
{
Robot robot = new Robot();
Rectangle rectangle = new Rectangle(0, 0, 1365, 770);
BufferedImage image = robot.createScreenCapture(rectangle);
for(int x = 0; x < rectangle.getWidth(); x++)
{
for (int y = 0; y < rectangle.getHeight(); y++)
{
if (image.getRGB(x, y) == inputColor.getRGB())
{
}
}
}
return 0;
}
public int get ()
{
return x;
return y;
return inputColor;
}
}
>
ok but im getting 3 errors:
1 java 19 invalid method declaration; return type required
2 java 19 identifier expected
3 java 19 identifier expected
-
Re: I had an old code it really sucked, so i now am making a new one
Code java:
<
import java.awt.*;
import java.awt.event.*;
import java.awt.Robot;
import java.awt.AWTException;
import java.awt.Rectangle;
import java.awt.Color;
import java.awt.Toolkit;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
public class GBpixel{
int a;
int b;
int c;
public GBpixel (int b, a, c)
{
y = b;
x = a;
inputColor = c;
}
public int checkColor(Color inputColor) throws Exception
{
Robot robot = new Robot();
Rectangle rectangle = new Rectangle(0, 0, 1365, 770);
BufferedImage image = robot.createScreenCapture(rectangle);
for(int x = 0; x < rectangle.getWidth(); x++)
{
for (int y = 0; y < rectangle.getHeight(); y++)
{
if (image.getRGB(x, y) == inputColor.getRGB())
{
}
}
}
return 0;
}
public int get ()
{
return x;
return y;
return inputColor;
}
}
>
ok that cleared up the first error now for the identifier expected errors
-
Re: I had an old code it really sucked, so i now am making a new one
A method will only execute one return statement. When it is executed, execution flow exits the method and returns the one value. The extra returns in the get method will not execute.
You need to read up somemore about how methods work and how to use them. Stacking multiple return statements shows a basic misunderstanding.
-
Re: I had an old code it really sucked, so i now am making a new one
ok so i should build 2 methods, one that has a variable say the RBG pixel data and returns the (x, y) position of that pixel, and another method that has the variable of (x, y) and returns the pixel RBG data or would that not work?
-
Re: I had an old code it really sucked, so i now am making a new one
What you describe would be for two separate methods.
-
Re: I had an old code it really sucked, so i now am making a new one
yes two separate methods, now the question i have is how would i declare the RGB a variable and the (x, y) a variable when there are 3 and 2 components of each one and methods can hove only one input one output
-
Re: I had an old code it really sucked, so i now am making a new one
Methods can have many parameters passed to them.
The RGB data is contained in an int.
Use a Point class object to return the x & y values.
-
Re: I had an old code it really sucked, so i now am making a new one
ok ill get back to you with the code
-
Re: I had an old code it really sucked, so i now am making a new one
Code java:
<
import java.awt.*;
import java.awt.event.*;
import java.awt.Robot;
import java.awt.AWTException;
import java.awt.Rectangle;
import java.awt.Color;
import java.awt.Toolkit;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import java.awt.Point;
public class GBpixel{
int inputColor;
public GBpixel (int inputColor)
{
}
public int checkColor(Color inputColor) throws Exception
{
Robot robot = new Robot();
Rectangle rectangle = new Rectangle(0, 0, 1365, 770);
BufferedImage image = robot.createScreenCapture(rectangle);
for(int x = 0; x < rectangle.getWidth(); x++)
{
for (int y = 0; y < rectangle.getHeight(); y++)
{
if (image.getRGB(x, y) == inputColor.getRGB())
{
}
}
}
return 0;
}
public Point get (int x, int y)
{
return Point(int x, int y);
}
}
thats my get pixel method, here is what i want it to do:
i call it with an input of the RGB color and i want ti search for that color and return with the Point of that color.
i am getting three errors:
1 java:45 '.class' expected
return Point(int x, int y)
2 java:45 ';' expected
return Point(int x, int y)
3 jave:45 ';' expected
return Point(int x, int y)
any help and a quick this method will do/not do what you want it to do would help alot
-
Re: I had an old code it really sucked, so i now am making a new one
Place ; in front of these return statements, keep the method's return statement as Point or any other Point's parent class.
-
Re: I had an old code it really sucked, so i now am making a new one
What is this statement supposed to do:
return Point(int x, int y);
The syntax is wrong.
-
Re: I had an old code it really sucked, so i now am making a new one
Code java:
<
import java.awt.*;
import java.awt.event.*;
import java.awt.Robot;
import java.awt.AWTException;
import java.awt.Rectangle;
import java.awt.Color;
import java.awt.Toolkit;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import java.awt.Point;
public class GBpixel{
int inputColor;
public GBpixel (int inputColor)
{
}
public int checkColor(Color inputColor) throws Exception
{
Robot robot = new Robot();
Rectangle rectangle = new Rectangle(0, 0, 1365, 770);
BufferedImage image = robot.createScreenCapture(rectangle);
for(int x = 0; x < rectangle.getWidth(); x++)
{
for (int y = 0; y < rectangle.getHeight(); y++)
{
if (image.getRGB(x, y) == inputColor.getRGB())
{
}
}
}
return getLocation();
}
}
>
i am getting 1 error
java:41: cannot find symbol
symbol : method getLocation()
location: class GBpixel
return getLocation();
wait i should use setLocation not getLocation right?
-
Re: I had an old code it really sucked, so i now am making a new one
What is the code supposed to do? What is the int value that checkColor() is supposed to return?
Quote:
should use setLocation not getLocation right?
Setting a value is very different from getting a value.
Where is the method: getLocation() defined? The compiler can not find it.
-
Re: I had an old code it really sucked, so i now am making a new one
ok this is not working for me:
i want this method to take the input pixel value RGB value and search the screenshot for it returning the Point(x, y) of that pixel when it is found: i get the error
cannot find symbol
symbol : method Point()
here is the code:
Code java:
<
import java.awt.*;
import java.awt.event.*;
import java.awt.Robot;
import java.awt.AWTException;
import java.awt.Rectangle;
import java.awt.Color;
import java.awt.Toolkit;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import java.awt.Point;
import java.lang.Object;
import java.awt.geom.Point2D;
public class GBpixel{
int inputColor;
public GBpixel (int inputColor)
{
}
public int checkColor(Color inputColor) throws Exception
{
Robot robot = new Robot();
Rectangle rectangle = new Rectangle(0, 0, 1365, 770);
BufferedImage image = robot.createScreenCapture(rectangle);
for(int x = 0; x < rectangle.getWidth(); x++)
{
for (int y = 0; y < rectangle.getHeight(); y++)
{
if (image.getRGB(x, y) == inputColor.getRGB())
{
return Point();
break;
}
}
}
return 0;
}
}
>
-
Re: I had an old code it really sucked, so i now am making a new one
If you want to create an instance of a class you need to use the new statement.
Your call to the Point class constructor does not have any parameters.
How are you going to return the x and y values?
Also the method is defined to return an int not a Point.
-
Re: I had an old code it really sucked, so i now am making a new one
what do you mean how am i going to return the x, y values. I'm going to call the method and get both the x and y values of the color specified set them in the main class as current x,y values and use them until this method is called and they are changed again.
-
Re: I had an old code it really sucked, so i now am making a new one
Quote:
I'm going to call the method and get both the x and y values
How do you get those values?
-
Re: I had an old code it really sucked, so i now am making a new one
well the method will take a screen shot, search the shot for the color that was input through int inputColor and return the x, y of the pixel with that specific color
-
Re: I had an old code it really sucked, so i now am making a new one
How will it do that? A method can only return ONE thing.
-
Re: I had an old code it really sucked, so i now am making a new one
Ok so i have this class which is my find pixel class, i believe as it is now it will when called find the inputColor value and set its location using the set location. What i need to do now is make my main class call it and respond by moving the mouse to the location set by the class.
Code java:
<
import java.awt.*;
import java.awt.event.*;
import java.awt.Robot;
import java.awt.AWTException;
import java.awt.Rectangle;
import java.awt.Color;
import java.awt.Toolkit;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import java.awt.Point;
import java.lang.Object;
import java.awt.geom.Point2D;
public class GBpixel{
int inputColor;
public GBpixel (int inputColor)
{
}
public int checkColor(Color inputColor) throws Exception
{
Robot robot = new Robot();
Rectangle rectangle = new Rectangle(0, 0, 1365, 770);
BufferedImage image = robot.createScreenCapture(rectangle);
for(int x = 0; x < rectangle.getWidth(); x++)
{
for (int y = 0; y < rectangle.getHeight(); y++)
{
if (image.getRGB(x, y) == inputColor.getRGB())
{
break;
}
}
}
return 0;
}
public void setLocation(int x, int y)
{
}
}
>
My main class, GunningBot.java
Code java:
<
import java.awt.*;
import java.awt.event.*;
import java.awt.Robot;
import java.awt.AWTException;
import java.awt.Rectangle;
import java.awt.Color;
import java.awt.Toolkit;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
public class GunningBot
{
public static void main(String[] args) throws Exception
{
}
}
>
I have goggled and researched this and cant find how to call and respond to a class if you have any tutorials or anything on it or can explain how to do that it would help lots! Ahh i see now you cant call the class so i would call the method GBpixel right?
-
Re: I had an old code it really sucked, so i now am making a new one
Quote:
how to call and respond to a class
You do not call classes. You call methods. Methods are part of a class.
Your code is full of calls to methods:
if (image.getRGB(x, y) == inputColor.getRGB()) // 2 calls tp getRGB()
BufferedImage image = robot.createScreenCapture(rectangle); // call to createScreen Capture()
-
Re: I had an old code it really sucked, so i now am making a new one
so in the method class i would set inputColor == and then i would just do Mouse.move and the x, y will be the set after i set inputColor?
-
Re: I had an old code it really sucked, so i now am making a new one
Please post something that looks more like code, I can not tell what you are talking about.
For example this looks like a compare not an assignment statement:
Quote:
i would set inputColor ==
== tests for equality
Quote:
the x, y will be the set
This makes no sense