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 3 of 3 FirstFirst 123
Results 51 to 75 of 75

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

  1. #51
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    22,321
    Thanks
    56
    Thanked 2,374 Times in 2,345 Posts

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

  2. #52
    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

    allrighty tut's here i come!

  3. #53
    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 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

  4. #54
    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 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

  5. #55
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    22,321
    Thanks
    56
    Thanked 2,374 Times in 2,345 Posts

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

  6. #56
    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 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?

  7. #57
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    22,321
    Thanks
    56
    Thanked 2,374 Times in 2,345 Posts

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

  8. #58
    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

    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

  9. #59
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    22,321
    Thanks
    56
    Thanked 2,374 Times in 2,345 Posts

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

  10. #60
    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 ill get back to you with the code

  11. #61
    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;
    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

  12. #62
    Think of me.... Mr.777's Avatar
    Join Date
    Mar 2011
    Location
    Pakistan
    Posts
    1,136
    My Mood
    Grumpy
    Thanks
    20
    Thanked 82 Times in 78 Posts
    Blog Entries
    1

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

  13. #63
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    22,321
    Thanks
    56
    Thanked 2,374 Times in 2,345 Posts

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

  14. #64
    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;
    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.

  15. #65
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    22,321
    Thanks
    56
    Thanked 2,374 Times in 2,345 Posts

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

  16. #66
    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 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;
    	}
    } 
    >

  17. #67
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    22,321
    Thanks
    56
    Thanked 2,374 Times in 2,345 Posts

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

  18. #68
    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

    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.

  19. #69
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    22,321
    Thanks
    56
    Thanked 2,374 Times in 2,345 Posts

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

    I'm going to call the method and get both the x and y values
    How do you get those values?

  20. #70
    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 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

  21. #71
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    22,321
    Thanks
    56
    Thanked 2,374 Times in 2,345 Posts

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

    return the x, y
    How will it do that? A method can only return ONE thing.

  22. #72
    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 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.

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

  23. #73
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    22,321
    Thanks
    56
    Thanked 2,374 Times in 2,345 Posts

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

    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()

  24. #74
    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

    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?

  25. #75
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    22,321
    Thanks
    56
    Thanked 2,374 Times in 2,345 Posts

    Default 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:
    i would set inputColor ==
    == tests for equality
    the x, y will be the set
    This makes no sense

Page 3 of 3 FirstFirst 123

Similar Threads

  1. Making change
    By Jerick in forum Algorithms & Recursion
    Replies: 3
    Last Post: October 7th, 2011, 07: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, 04:32 AM