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 6871935
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T03:51:51+00:00 2026-05-27T03:51:51+00:00

I have a simple program to draw simple shapes by canvas. private class MyViewCircle

  • 0

I have a simple program to draw simple shapes by canvas.

private class MyViewCircle extends View {

    public MyViewCircle(Context context) {
        super(context);
        // TODO Auto-generated constructor stub
    }

    @Override
    protected void onDraw(Canvas canvas) {
        // TODO Auto-generated method stub
        super.onDraw(canvas);
        Paint paint = new Paint();
        paint.setAntiAlias(true);
        paint.setColor(Color.RED);
        canvas.drawCircle(89, 150, 30, paint);
    }

}

As you see, the attributes of the circle is

(Color.RED); 
(89, 150, 30, paint);

I want to created another class includes a lot of other features(colors and coordinates) and select them randomly.
So, which way is better, array or arraylist or something else? Could someone gives me an example how to do that? Then how to randomly pick them and put them into the draw function? Cheers!

  • 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-05-27T03:51:52+00:00Added an answer on May 27, 2026 at 3:51 am

    Try creating a simple Java object to contain all the attributes, then add them to a single list and choose an item at random:

    class MyAttributes {
        int color;
        int x, y;
        int radius;
    
        public MyAttributes(int color, int x, int y, int radius) {
            this.color = color;
            this.x = x;
            this.y = y;
            this.radius = radius;
        }
    }
    

    In your View class:

    private List<MyAttributes> mAttributes;
    private Random mRandom;
    
    public MyViewCircle(Context context) {
        mRandom = new Random();
        mAttributes = new ArrayList<MyAttributes>();
    
        mAttributes.add(new MyAttributes(Color.RED, 80, 70, 199));
        mAttributes.add(new MyAttributes(Color.BLUE, 50, 170, 88));
    }
    
    
    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        Paint paint = new Paint();
        paint.setAntiAlias(true);
    
        int randomPosition = mRandom.nextInt(mAttributes.size());
        MyAttributes randomAttr = mAttributes.get(randomPosition);
    
        paint.setColor(randomAttr.color);
        canvas.drawCircle(randomAttr.x, randomAttr.y, randomAttr.radius, paint);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple Javascript program that displays a small rectangle in a canvas.
In my program I want to draw a simple score line graph. I have
I have to write a simple program that will draw something in a Windows
I have a simple OpenGL program and trying to draw an instanced array that
I have a simple Java program that allows a user to draw rectangles on
Say I have simple program that emulates a board game with a number of
I have a simple program that creates a thread, loops twenty times and then
I have a simple program to check if a port is open, but I
I have a simple python program that I'd like to daemonize. Since the point
I have a simple forms program that I have been fighting with for a

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.