Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8132257
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T09:18:16+00:00 2026-06-06T09:18:16+00:00

So im trying to make an adroid application that draws a stream of circles

  • 0

So im trying to make an adroid application that draws a stream of circles as touchevent takes place. If i draw on the left side of the screen it should draw a green circle, and if its on the right , it should draw a blue circle. The app is doing this, but it changes the color of all the circles already drawn. SO i made a Draw circle Class and a array list of objects to treat each cricle as an individual objec, still not working Even after a Touchup event. the code for it is given below

 private class Drawcirlce  {

        public Drawcirlce(Canvas c) {
        // TODO Auto-generated constructor stub


        for (Point point : points) {

             if(flag==true)
                    c.drawCircle(point.x, point.y, 5, paint);
                    else
                    c.drawCircle(point.x, point.y, 5, p2);
        }
    invalidate();
    }
    /*for (Point point : points) {
     if(flag==true)
        mcan.drawCircle(point.x, point.y, 5, paint);
        else
        mcan.drawCircle(point.x, point.y, 5, p2);
}*/

}


public void onDraw(Canvas canvas) {


    i++;
     //Drawcirlce d=new Drawcirlce();
dc.add(new Drawcirlce(canvas));

Log.d(TAG, "i: " + i);invalidate();
}
public boolean onTouch(View view, MotionEvent event) {
    // if(event.getAction() != MotionEvent.ACTION_DOWN)
    // return super.onTouchEvent(event);
    Point point = new Point();
    point.x = event.getX();
    point.y = event.getY();
    if(point.x>200){
        paint.setColor(Color.BLUE);
    flag=true;
    }
    else{
        p2.setColor(Color.GREEN);
    flag=false;
    }

    points.add(point);
    //dc.add(new Drawcirlce(mcan));

    invalidate();
    Log.d(TAG, "point: " + point);
    return true;
}

public boolean onTouch(View view, MotionEvent event) {
    // if(event.getAction() != MotionEvent.ACTION_DOWN)
    // return super.onTouchEvent(event);
    Point point = new Point();
    point.x = event.getX();
    point.y = event.getY();
    if(point.x>200){
        paint.setColor(Color.BLUE);
    flag=true;
    }
    else{
        p2.setColor(Color.GREEN);
    flag=false;
    }

    points.add(point);
    //dc.add(new Drawcirlce(mcan));

    invalidate();
    Log.d(TAG, "point: " + point);
    return true;
}

Any one know aht im doing wrong, or if theres a way around this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T09:18:18+00:00Added an answer on June 6, 2026 at 9:18 am

    Your Drawcirlce class needs to have a Paint object in it. (You can make this public to the class, or give it getPaint() and setPaint(), whichever.) Then, when you call c.drawCircle(point.x, point.y, 5, paint);, call it with the Paint object in the class instead.

    Something like this:

    private class Drawcirlce {
        public Paint myPaint;
    
        public void draw(Canvas c) { // Don't use a constructor here...
            if (myPaint == null)
                return;
    
            for (Point point : points) {
                c.drawCircle(point.x, point.y, 5, myPaint);
                invalidate();
            }
        }
    }
    

    Then, in your onTouch event, you do something like this:

    Drawcirlce myCircle = new Drawcirlce();
    if (flag == true)
        myCircle.myPaint = new Paint(paint); // Copies the current paint object.
    else
        myCircle.myPaint = new Paint(p2); // Copies the current p2 object.
    dc.add(); // Adds our circle with its own Paint object.
    

    Lastly, you would have to change your onDraw event.

    for (Drawcirlce d : dc) { // Loop through everything in the dc array.
        d.draw(canvas); // Draw it to this canvas!
    }
    

    This code, in effect, assigns a circle the ability to have its own Paint object. Then, when touching, you create a Paint to give it. Lastly, when drawing, you use that Paint instead of the current one.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to make an application on android that takes the contact name
im trying to make an android application that whenever a user conncects to a
I'm trying to make an OAuth 2.0 Provider and an Android application that is
I am trying to make an application that will have a set of screens
I'm trying to make an Android application that will display a map of a
I am trying to make an Android/ Java application that needs to connect to
I have an html/javascript/css project that i am trying to make an Android application
I'm trying to make an Android application that need to access some webservices, returning
I am trying to make a little application that simulates the dice. I want
I'm new to android and am trying to make an application that when the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.