Page 2 of 2 FirstFirst 12
Results 21 to 23 of 23
  1. #21
    jim829 is online now Senior Member
    Join Date
    Jan 2013
    Location
    United States
    Posts
    2,946
    Rep Power
    4

    Default Re: draw method for Point2D.Double ?

    Have you looked at the Point2D.Double API? It does not contain a draw method. Also, it looks like you are creating an instance of Cloud in your CloudComponent class. But it is of little use because of its scope. You said that you never covered some of this in class. The instructions make reference to a Car class but your initial attempt indicates you are not quite understanding how to do graphics.

    It appears you are lacking knowledge of some basic fundamentals in Java. Its great you want to learn Java programming but you need to go thru the tutorials (see my signature) and brush up on the basics. And it will take time. As you read you need to write small programs to practice and reinforce what you have read. If you insist on doing some graphics then read the section on custom painting.

    Regards,
    Jim
    The Java™ Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

  2. #22
    jwood is offline Senior Member
    Join Date
    Jun 2013
    Posts
    136
    Rep Power
    0

    Default Re: draw method for Point2D.Double ?

    Yes, I misread the draw part. I am suppose to call the Cloud.java draw method, and I have since change some stuff around. This is where I currently am:
    Java Code:
    public class CloudComponent extends JComponent   {
       	/**
    		   An integer containing the size of each cloud.
    		*/
          private int pointSize;
    		
    		/**
      		   Random generator
       	*/
          private Random Generator;
    		
    		
       	/**
    		   Constructor that takes in a parameter that is assigned to pointSize.
    			@param aPointSize assigns size of each cloud
    		*/
          public CloudComponent(int aPointSize)
          {
             pointSize = aPointSize;
          }
    		
    		/**
    		   Creates a cloud object
    			@param Graphics g calls graphics components
    		*/
          public void paintComponent(Graphics g)
          {  
    		   Cloud newCloud = new Cloud(aPointSize);
    			//recover Graphics2D 
             Graphics2D g2 = (Graphics2D) g;
             Random generator = new Random();
    			
             for (int i = 0; i < 100; i++) 
             {
                //sets random location of points until count is reached. 
                //double d = generator.nextDouble() * pointSize;
                double x = generator.nextDouble() * (getWidth() - pointSize);
                double y = generator.nextDouble() * (getHeight() - pointSize);
                Point2D.Double newPoints = new Point2D.Double(x, y);
                       
                          
                
    				newCloud.add(newPoints);       
    			}
    			newCloud.draw(g2);//Draws points 
    		}
    	}
    I am still getting an error though
    CloudComponent.java:46: error: constructor Cloud in class Cloud cannot be applied to given types;
    Cloud newCloud = new Cloud();
    ^
    required: int
    found: no arguments
    reason: actual and formal argument lists differ in length.

  3. #23
    jwood is offline Senior Member
    Join Date
    Jun 2013
    Posts
    136
    Rep Power
    0

    Default Re: draw method for Point2D.Double ?

    Can someone explain this error to me?(the error point to the new in the error)

    Cloud.java:56: error: no suitable constructor found for Double(java.awt.geom.Point2D.Double,int,int)
    Ellipse2D.Double circle = new Ellipse2D.Double(points.get(i), pointSize, pointSize);
    ^
    constructor java.awt.geom.Ellipse2D.Double.java.awt.geom.Ellip se2D.Double(double,double,double,double) is not applicable
    (actual and formal argument lists differ in length)
    constructor java.awt.geom.Ellipse2D.Double.java.awt.geom.Ellip se2D.Double() is not applicable
    (actual and formal argument lists differ in length)
    1 error

    the code
    Java Code:
    public void draw(Graphics2D g2)      {           
             Random generator = new Random();
                for (int i = 0; i < points.size(); i++)
                    {
                       Ellipse2D.Double circle = new Ellipse2D.Double(points.get(i), pointSize, pointSize);
                        
                        //sets random color of points until count is reached.
                    int red = generator.nextInt(255);
                      int green = generator.nextInt(255);
                    int blue = generator.nextInt(255);
                    Color randomColor = new Color(red, green, blue);
                    randomColor.brighter();//Makes colors brighter
                    g2.setColor(randomColor);//sets random color
                        
                   g2.draw(circle);
                    }
    I am a little confused on how to address the x and y points, since they are stored in the ArrayList. I thought I would just call the array elements to retrieve both points and got the error above. How do I retrieve the individual x and y when they are stored together in the ArrayList?
    Last edited by jwood; 07-28-2013 at 03:41 AM.

Page 2 of 2 FirstFirst 12

Similar Threads

  1. Point2D in integer Grid
    By proggrammer in forum New To Java
    Replies: 1
    Last Post: 06-15-2012, 08:39 AM
  2. How to draw 1/2 or 1/4 of a path2d.double
    By dialuppro in forum Java 2D
    Replies: 1
    Last Post: 05-08-2010, 04:54 AM
  3. Replies: 1
    Last Post: 04-06-2009, 06:45 AM
  4. Replies: 2
    Last Post: 04-03-2009, 05:04 AM
  5. Replies: 5
    Last Post: 03-21-2009, 09:32 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •