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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T18:35:47+00:00 2026-06-17T18:35:47+00:00

Here is my code. I have 4 classes, an abstract class (GeoShape), a Rectangle

  • 0

Here is my code. I have 4 classes, an abstract class (GeoShape), a Rectangle class that extends GeoShape, a GraphicsPanel containing my GeoShapes and trying to draw them, and a Launcher class.

GeoShape.java

public abstract class GeoShape
{
    protected Point p;
    protected int width, height;

    public GeoShape(Point p, int width, int height)
    {
        this.p = p;
        this.width = width;
        this.height = height;
    }

    public void drawItself(Graphics g)
    {
        g.setColor(Color.BLACK);
    }

    // Getters and setters...
}   

Rectangle.java

public class Rectangle extends GeoShape
{
    public Rectangle(Point p, int width, int height)
    {
        super(p, width, height);    
    }

    @Override
    public void drawItself(Graphics g)
    {
        super.drawItself(g);
        g.drawRect((int)p.getX(), (int)p.getY(), width, height);
    }
}

GraphicsPanel.java

public class GraphicsPanel extends JPanel
{
    private static final long serialVersionUID = 1L;
    private ArrayList<GeoShape> list;

    public GraphicsPanel() 
    {
        list = new ArrayList<GeoShape>();
    }

    @Override
    public void paintComponents(Graphics g) 
    {
        super.paintComponents(g);
        for(int i = 0 ; i < list.size() ; i++) list.get(i).drawItself(g);
    }

    public void addShapeInList(GeoShape s)
    {
        list.add(s);
    }
}

Launcher.java

public class Launcher extends JFrame
{
    private static final long serialVersionUID = 1L;
    private GraphicsPanel panel;

    public Launcher()
    {
        panel = new GraphicsPanel();
        panel.addShapeInList(new Rectangle(new Point(3,9),120,20));
        panel.repaint();

        this.setTitle("Test");
        this.setContentPane(panel);
        this.setDefaultCloseOperation(EXIT_ON_CLOSE);
        this.setSize(700, 500);
        this.setVisible(true);
    }

    public static void main(String[] args) 
    {
        new Launcher();
    }
}

And nothing happens in the frame… thanks for your help.

  • 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-17T18:35:48+00:00Added an answer on June 17, 2026 at 6:35 pm

    Try to replace it with paintComponent rather than paintComponents

    public void paintComponent(Graphics g) 
    {
        super.paintComponent(g);
        for(int i = 0 ; i < list.size() ; i++) list.get(i).drawItself(g);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is the code I have written for Rectangle class. class Rectangle (l: Double,
I have the following code: public abstract class A<T extends B<? extends A<T>>>{ @Override
Basically, I have 3 classes class abstract A{} protected aMethod(){} class abstract B extends
enter code here I have a ListView that have a different Layout XML for
I have some code here that uses bitsets to store many 1 bit values
So I have this code here: <table> <tr> <td width=200px valign=top> <div class=left_menu> <div
I have the following classes: class Repository : IRepository class ReadOnlyRepository : Repository abstract
I am trying to build a simple abstract Cache class that can enforce methods
Suppose I have an abstract base class, that just defines a container on which
I have several Java interfaces/ABCs/classes: public abstract class Target { public abstract void fire(Load

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.