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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T06:19:58+00:00 2026-05-30T06:19:58+00:00

I working on a project in which I have to simulate a memory manager

  • 0

I working on a project in which I have to simulate a memory manager and show some memory snapshots. I have created a draw class via examples I have found here in which I override the paintComponet(). Everything draws fine.

I would like to be able to draw a rectangle to represent a memory partition and then overlay another rectangle over top to represent an incoming job (ie Job1 is in this partition3). What seems to occur is that I add the partition first (which will always be the case) and then when I add the job it will sit behind the partition block. Is there a way other than drawing the Job first to shift these after the job is created?

Here is the paint override

@Override public void paintComponent(Graphics g) {

    super.paintComponent(g);
    Graphics2D g2d = (Graphics2D)g;

    // set up rendering to allow anti-aliasing
    g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

    // create the rectangle to represent the memory partition block 
    //  x = address position h = amount of memory (y & w are predefined for the display block)

      Rectangle2D rect = new Rectangle2D.Double(x, y, w, h);    // create the rectangle 
    g2d.setPaint(partColor);                // set it's color
    g2d.fill(rect);                 // fill it in

    // create the transparency for the text
     Composite comp = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, .4f);
     g2d.setComposite(comp);

     // draw the text with color, type and size and center the text in the block created above
     g2d.setPaint(Color.black);
     g2d.setFont(new Font("Tahoma", Font.PLAIN, 12));
     g2d.drawString(text, (int)((w / 2) - (text.length()/2)), (int)h/2);

}

The call to draw is in my window class (this will place the partition in front of the job) but I need to order to be reversed without changing the order of the calls.

    // Draw both Text and Block with transparency
    DrawPartition part1 = new DrawPartition(Color.blue, 0, 0, 110, 100, "part1");
    part1.setBounds(5, 5, 110, 100);
    snapPanel.add(part1);

    DrawJob job1 = new DrawJob(Color.green, 0, 0, 110, 100, "Job 1");
    job1.setBounds(5, 15, 110, 100);
    snapPanel.add(job1);
  • 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-30T06:19:59+00:00Added an answer on May 30, 2026 at 6:19 am

    Is there some reason you can’t do this?

    // Draw both Text and Block with transparency
    DrawPartition part1 = new DrawPartition(Color.blue, 0, 0, 110, 100, "part1");
    part1.setBounds(5, 5, 110, 100);
    
    DrawJob job1 = new DrawJob(Color.green, 0, 0, 110, 100, "Job 1");
    job1.setBounds(5, 15, 110, 100);
    snapPanel.add(job1);
    
    snapPanel.add(part1);
    

    A more general answer would be to add a z component to each of your rectangles. Then you can loop through your rectangles in the paintComponent method, drawing them in z order.

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

Sidebar

Related Questions

I am working on a project in which i have created an app on
I'm working on a project in which we have a database, data layer (entity
I'm working on a project which will end up have a lot of application
I have just begun working on a project which uses Mercurial as a version
I have started working on a project which requires Natural Language Processing. We have
Suppose you're working on an enterprise project in which you have to get management
I'm working on a large project (for me) which will have many classes and
I'm working on a web project, which have to process so many client requests.
I am working on a project in which I have to develop bio-passwords based
I have been working on one project which is too complex and contain very

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.