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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T00:10:47+00:00 2026-05-28T00:10:47+00:00

I am making a sort of command based application to draw geometric figures. So

  • 0

I am making a sort of command based application to draw geometric figures. So if a user enters something like RECT 100, 50, 200, 120 I draw a rectangle at specified location on the drawing panel.

So for this i need to map RECT to g.drawRect(100, 50, 200, 120); and all such similar functions to draw geometric figures.

I will use a hash map for mapping, but i don’t know how to build a array of functions in java. In C++ i have done this though.

The key can be ‘RECT’ and the value the offset of the index.

Please show me how can i index these functions. Or is there a still better way to address the primary concern?

  • 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-28T00:10:48+00:00Added an answer on May 28, 2026 at 12:10 am

    There are no function pointers in Java, you need to do it through inheritance and/or interfaces. Here is an example:

    interface Shape {
        void draw(int[] data);
    }
    
    class Polygon implements Shape {
        public void draw(int[] data) {
            // Draw polygon using points data[i], data[i+1] for points
        }
    }
    
    class Circle implements Shape {
         public void draw(int[] data) {
             // Draw circle using data[0], data[1] for the center, and data[2] for radius
         }
    }
    

    In your main program’s constructor or static initializer:

    Map<String,Shape> shapes = new HashMap<String,Shape>();
    shapes.put("POLY", new Polygon());
    shapes.put("CIRC", new Circle());
    

    In your drawing code:

    shapes.get("CIRC").draw(new int[] {100, 100, 50});
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Currently I'm making sort of SQL command line interface for web-based application. It should
I'm making a sort of Webserver that enables a user to give .jow file
For a little iPhone application I am making, I want to sort a NSMutableArray.
I making a tool where a user has to quickly sort throo a heap
The title sort of explains itself. I am making some 'genrative' artwork in flash.
I'm making a shell script to find bigrams, which works, sort of. #tokenise words
Before making a commit, I prefer to run all hundred-something unit tests in my
I'm making a sort elements web game using jQuery, HTML & CSS. While everything
I have a feeling I am making some sort of foolish mistake here, however
I'm new to rails and making some sort of noob mistake: I frequently need

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.