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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T02:49:30+00:00 2026-06-14T02:49:30+00:00

This is my last exercise in my headfirst book but when i run the

  • 0

This is my last exercise in my headfirst book but when i run the application the shape is not being drawn, I’m pretty stumped cause there are no errors.

public class ShapesDriver extends Frame{ //You said Frame in the Tutorial4 Document
    private ArrayList<Drawable> drawable;
    public static void main(String args[]){
        ShapesDriver gui = new ShapesDriver();

        gui.addWindowListener(new WindowAdapter(){
            @Override
            public void windowClosing (WindowEvent e){
                System.exit(0);
            }
        });    
    }

    public ShapesDriver(){
        super("Shapes");
        setSize(500, 500);
        setResizable(false);
        setVisible(true);
        show();
    }

    public void Paint (Graphics g){
        DrawableRectangle rect1 = new DrawableRectangle(150, 100);
        drawable.add(rect1);
        for(int i = 0; i < drawable.size(); i++){
            drawable.get(i).draw(g);
        }        
    }
}

DrawableRectangle Class

public class DrawableRectangle extends Rectangle implements Drawable{
    private int x, y;
    public DrawableRectangle(int height, int width){
        super(height, width);
    }

    @Override
    public void setColour(Color c) {
        this.setColour(c);
    }

    @Override
    public void setPosition(int x, int y) {
        this.x = x;
        this.y = y;
    }

    @Override
    public void draw(Graphics g) {
        g.drawRect(x, y, width, height);
    }
}

Rectangle Class

public abstract class Rectangle implements Shape {
    public int height, width;

    Rectangle(int Height, int Width){
        this.height = Height;
        this.width = Width;
    }

    @Override
    public double area() { return width * height; }
}

Shape Class

public interface Shape {
    public double area();
}
  • 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-14T02:49:34+00:00Added an answer on June 14, 2026 at 2:49 am

    Lets start with, Java is case sensitive, so public void Paint (Graphics g){ is never going to be called by Java, as the method name is paint

    Then lets move onto, you should rarely, if ever, extend a top level container like JFrame and especially override the paint method. paint does a lot of really important work and you should always call super.paint

    Instead, you should extend from something JPanel and override the paintComponent method instead (remembering to call super.paintComponwnt)

    And then I’d include Rohit’s suggestions.

    You might like to have a read through

    • Performing Custom Painting
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I came across this issue last night where my CSS would not affect the
This was working last night, but I must have accidentally changed something, because it
I need this query - update last but one record. UPDATE changes SET checked=''
I posted a question last night, but unfortunately I was not specific enough vis
I have to do this exercise: Do an application in C that manages a
I feel embarrassed asking this question, but I've spent the last half an hour
This is probably trivial, and I do have a solution but I'm not happy
I'm trying to solve the last exercise of this JavaScript Closure Tutorial which takes
I am trying to run this code from the beginners' python book Think Python
This is part of a lab exercise for a course I'm doing, it's not

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.