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.

Page 1 of 3 123 LastLast
Results 1 to 25 of 75

Thread: I had an old code it really sucked, so i now am making a new one

  1. #1
    Member
    Join Date
    Jan 2012
    Posts
    67
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default I had an old code it really sucked, so i now am making a new one

    <
    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
    Last edited by Lurie1; February 1st, 2012 at 01:26 PM.


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default 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.

  3. The Following User Says Thank You to Norm For This Useful Post:

    Lurie1 (February 1st, 2012)

  4. #3
    Member
    Join Date
    Jan 2012
    Posts
    67
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default 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
    Last edited by Lurie1; February 1st, 2012 at 01:28 PM.

  5. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default 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?

  6. #5
    Member
    Join Date
    Jan 2012
    Posts
    67
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default 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

  7. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default 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?

  8. #7
    Member
    Join Date
    Jan 2012
    Posts
    67
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default 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

  9. #8
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default 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?

  10. #9
    Member
    Join Date
    Jan 2012
    Posts
    67
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default 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.

  11. #10
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default 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.
    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?

  12. #11
    Member
    Join Date
    Jan 2012
    Posts
    67
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default 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?

  13. #12
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default 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.
    Last edited by Norm; February 1st, 2012 at 03:54 PM.

  14. #13
    Member
    Join Date
    Jan 2012
    Posts
    67
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default 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?

  15. #14
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default 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.
    Last edited by Norm; February 1st, 2012 at 03:54 PM.

  16. #15
    Member
    Join Date
    Jan 2012
    Posts
    67
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default 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

  17. #16
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default 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);

  18. #17
    Member
    Join Date
    Jan 2012
    Posts
    67
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default 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:

    <
     
        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;
                }
            }
        }
    >
    Last edited by Lurie1; February 1st, 2012 at 09:11 PM.

  19. #18
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: I had an old code it really sucked, so i now am making a new one

    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>;
    Last edited by Norm; February 1st, 2012 at 03:53 PM.

  20. #19
    Member
    Join Date
    Jan 2012
    Posts
    67
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default 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

  21. #20
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: I had an old code it really sucked, so i now am making a new one


  22. #21
    Member
    Join Date
    Jan 2012
    Posts
    67
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default Re: I had an old code it really sucked, so i now am making a new one

    <
    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:
    }

  23. #22
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default 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.

  24. #23
    Member
    Join Date
    Jan 2012
    Posts
    67
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default 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?

  25. #24
    Member
    Join Date
    Jan 2012
    Posts
    67
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default 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

  26. #25
    Member
    Join Date
    Jan 2012
    Posts
    67
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default Re: I had an old code it really sucked, so i now am making a new one

    wait never mind i figured it out

Page 1 of 3 123 LastLast

Similar Threads

  1. Making change
    By Jerick in forum Algorithms & Recursion
    Replies: 3
    Last Post: October 7th, 2011, 06:49 PM
  2. Making a clock
    By javapenguin in forum What's Wrong With My Code?
    Replies: 5
    Last Post: January 7th, 2011, 04:36 PM
  3. making my code a little better, if needed.
    By vendetta in forum Object Oriented Programming
    Replies: 4
    Last Post: February 11th, 2010, 03:40 AM
  4. Need help making program
    By ixjaybeexi in forum Collections and Generics
    Replies: 5
    Last Post: December 6th, 2009, 11:36 PM
  5. Digital map application with Java GUI
    By donjuan in forum AWT / Java Swing
    Replies: 3
    Last Post: May 15th, 2009, 03:32 AM