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.
Welcome to the Java Programming Forums
The professional, friendly Java community. 21,500 members and growing!
The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.
>> REGISTER NOW TO START POSTING
Members have full access to the forums. Advertisements are removed for registered users.
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.
allrighty tut's here i come!
< 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
ok that cleared up the first error now for the identifier expected errors< 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; } } >
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.
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?
What you describe would be for two separate methods.
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
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.
ok ill get back to you with the code
< 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
Place ; in front of these return statements, keep the method's return statement as Point or any other Point's parent class.
What is this statement supposed to do:
return Point(int x, int y);
The syntax is wrong.
< 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?
Last edited by Lurie1; February 8th, 2012 at 12:40 AM.
What is the code supposed to do? What is the int value that checkColor() is supposed to return?
Setting a value is very different from getting a value.should use setLocation not getLocation right?
Where is the method: getLocation() defined? The compiler can not find it.
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:
< 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; } } >
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.
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.
How do you get those values?I'm going to call the method and get both the x and y values
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
How will it do that? A method can only return ONE thing.return the x, y
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.
My main class, GunningBot.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) { } } >
< 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?
You do not call classes. You call methods. Methods are part of a class.how to call and respond to 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()
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?
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:
== tests for equalityi would set inputColor ==
This makes no sensethe x, y will be the set