-
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 GB{
public boolean checkColor(Color inputColor) {
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 true;
}
}
}
return false;
{
while (!checkColor(newColor)) {
new Color = new Color(196, 195, 181);
}
}
}
>
anyway im getting 10 errors and they are all noobie errors but idk how to fix..
what i want to do is declare a method then check a new color against the method..
the errors are:
illegal start of expression
identifier expected
; expected
) expected
-
Re: I had an old code it really sucked, so i now am making a new one
Check the correct pairing of the {}s
Is all code inside of a method? Its hard to tell with the way the {}s are positioned in your code.
You should post the full text of the error message. Your edited version left important information, like the source line number.
-
Re: I had an old code it really sucked, so i now am making a new one
that paring cleared up all but 1 problem.
java:27: '(' or '[' expected
new Color = new Color(196, 195, 181);
i edited the code in the first post to reflect this
-
Re: I had an old code it really sucked, so i now am making a new one
new Color = new Color(196, 195, 181);
Your syntax is wrong. new usually only goes to the right of an = when you create an instance of a class.
What are you trying to do here?
-
Re: I had an old code it really sucked, so i now am making a new one
well im trying to set a color for the method to check and if it return true, as in it can find the color move a mouse to that position
-
Re: I had an old code it really sucked, so i now am making a new one
What is the name of the variable you are trying to assign the new color value to?
-
Re: I had an old code it really sucked, so i now am making a new one
I believe it is:
if (image.getRGB(x, y) == inputColor.getRGB())
inputColor i believe is the one that is being assigned the RGB value
-
Re: I had an old code it really sucked, so i now am making a new one
This is what I am talking about:
new Color = new Color(196, 195, 181);
What is that statement supposed to do?
-
Re: I had an old code it really sucked, so i now am making a new one
oh ya sorry dident get the question,
ok so the method that includes that little piece is supposed to take a screenshot and look for the specified color, the color is specified by:
new Color = new Color(196, 195, 181);
the above statement is supposed to link the color (new Color) to the color in the get pixel method specifically inputColor, so it specifies what color to look for through inputColor.
-
Re: I had an old code it really sucked, so i now am making a new one
Time to go back to the text book and see how to define a variable and give it a value that is an instance of a class.
Quote:
supposed to link the color (new Color) to the color in the get pixel method
What do you mean by "link"?
(new Color) is not a variable name nor a valid Color object. What is it supposed to be?
-
Re: I had an old code it really sucked, so i now am making a new one
ok well if i were declaring a variable for newColor what would i declare it as, int?
-
Re: I had an old code it really sucked, so i now am making a new one
If you are saving int values in newColor, then define it as an int variable.
int newColor;
What does an int variable have to do with creating a Color object as this statement does:
new Color(196, 195, 181); // Create a Color object
These are very basic concepts that should have been covered in the first couple of chapters.
What is a variable?
How to define a variable.
How to assign a value to a variable.
How do create an instance of a class.
-
Re: I had an old code it really sucked, so i now am making a new one
ok so what variable would that be declared under? not int or float or long or short right?
-
Re: I had an old code it really sucked, so i now am making a new one
What values are you going to assign to the variable? Given that you will know how to define it.
These are very basic concepts that should have been covered in the first couple of chapters.
What is a variable?
How to define a variable.
How to assign a value to a variable.
How do create an instance of a class.
How to compare the contents of one variable with the contents of another variable.
How to call methods in a class.
-
Re: I had an old code it really sucked, so i now am making a new one
well im going to assign it RGB values so that the method knows what value to search for
-
Re: I had an old code it really sucked, so i now am making a new one
If RGB values are ints, then create an int variable to hold them.
You still have not said what you want this statement to do.
new Color = new Color(196, 195, 181);
-
Re: I had an old code it really sucked, so i now am making a new one
this statment:
new Color = new Color(196, 195, 181);
it sets the color for the method to look for, i want it to set the inputColor value in this chunk of code:
Code java:
<
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 true;
}
}
}
>
-
Re: I had an old code it really sucked, so i now am making a new one
Quote:
it sets the color for the method to look for
Did you read this list and do you understand what each item in the list means?
These are very basic concepts that should have been covered in the first couple of chapters.
What is a variable?
1)How to define a variable.
2)How to assign a value to a variable.
3)How do create an instance of a class.
You need to review these items.
Your statement only does step 3 correctly.
Where do you do step 1????
The syntax for defining a variable:
<datatype> <NAME>
new is not a datatype
Color is not a name.
The syntax for assigning a value to a variable:
<variableName> = <the value>;
-
Re: I had an old code it really sucked, so i now am making a new one
see i havent actually had a class or textbook or anything on this kind learning it as i go so ill research those then get back to you, if you know of a site with good tutorials please tell me
-
Re: I had an old code it really sucked, so i now am making a new one
-
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 GB{
public boolean 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 true;
}
}
}
return false;
}
{
while (!checkColor(inputColor)) {
inputColor = new Color(196, 195, 181);
}
}
}
public static void main(String[] args)
{
}
}
>
my updated code that now only has two errors:
1. java.30: unreachable statement
{
2. java:35 missing return statement:
}
-
Re: I had an old code it really sucked, so i now am making a new one
Where is line 30. What code is there?
You need to add a return statement at the end of the checkColor() method.
You may have an infinite loop if you call the checkColor method from inside of the checkColor method.
If checkColor() is passed a color as an argument, why do you change its value inside of the method?
Your {}s are not properly aligned. It is very hard to see the nesting of code within loops and methods the way you have them.
-
Re: I had an old code it really sucked, so i now am making a new one
ok now i have gotten that a few times, the its hard to read, but i don't know how you want me to fix it so its not as difficult, is there a standard i can look at or something like that?
-
Re: I had an old code it really sucked, so i now am making a new one
return false;
}
{
while (!checkColor(inputColor)) {
inputColor = new Color(196, 195, 181);
that is code lines 28-32
-
Re: I had an old code it really sucked, so i now am making a new one
wait never mind i figured it out