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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T14:52:24+00:00 2026-06-07T14:52:24+00:00

Ok, recently i have written a paint application in Java. Small program similar to

  • 0

Ok, recently i have written a “paint application” in Java. Small program similar to MS Windows Paint and apparently (according to some people that evaluated my source code) im not using classes properly in my application. Unfortunatelly i have no idea what could be wrong, and yet noone is in the mood to tell me what is incorrect.

I have “proper” classes that use the idea of inheritance:

PaintObject  
-ClosedObject  
--RectangleShape  
--OvalShape  
-OpenObject  
--PointShape  
--LineShape  

But still i have no idea what could be wrong in code, what could lead to thinking that classes are not used properly…

The only thing what (in my opinion) could be wrong is the fact that im drawing by creating the new objects like: new RectagleObject(...) and new OvalShape(...) instead of creating one field objectToBeDrawn variable (maybe a PaintObject type) and then assign appropriate shape to it when the method executeOperation is called (obviously along with drawing of that particular shape)

Here is the code sample:

public void executeOperation(Graphics2D gr, int oper, boolean drawingMode){
    if(oper==1){
        new RectangleShape(startLocation, endLocation, borderColor, fillColor).draw(gr);
    }
    else if(oper==2){
        new OvalShape(startLocation, endLocation, borderColor, fillColor).draw(gr);
    }
    ....//more operations
}

Anyone has any idea what could be wrong in terms of general programming habits (unless my ‘guess’ is right? – if it is, please confirm my doubts). Or maybe there is something else?
(Skip the part of oper==1 since i know that such values should be defined constant)

Any help greatly appreciated, im learning by myself and it is really hard to guess how professional programs are designed (and follow their pattern) since my experience is “limited” (actually none).

  • 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-07T14:52:27+00:00Added an answer on June 7, 2026 at 2:52 pm

    If you’re drawing raster images, do you need to keep track of what the user is drawing? Perhaps you mean objects such as PenTool, RectangleTool, etc?

    Right now, it seems like you create objects that persist and are redrawn to draw specific shapes. You can simply have the tool objects draw on an Image once when appropriate (just don’t ever clear the graphics context). Just assign a particular tool to some activeTool field when the tool is selected.

    class DrawingTool {
         public void draw(Graphics g) { }
    }
    
    class PenTool extends DrawingTool {
         public void draw(Graphics g) {
             // some drawing logic
         }
    }
    
    class RectangleTool extends DrawingTool {
         public void draw(Graphics g) {
             // some other drawing logic
         }
    }
    

    So instead of

    oper = 1;
    

    you would write

    activeTool = new PenTool(); // or activeTool = PenTool.GetInstance();
    

    or something similar. Now when you want to draw something, just invoke the draw method. As I stated before, you can do this simply by passing in an Image that you never clear:

    class DrawingCanvas {
         Image image = createImage(GetWidth(), GetHeight());
         DrawingTool activeTool;
    
         // this is what gets invoked on every frame
         public void paint(Graphics g){
              g.drawImage(image, 0, 0, null);
         }
    }
    
    // when you need to draw something
    // (not on every frame, but something new)
    activeTool.draw(image.getGraphics());
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have recently written a survey application that has done it's job and all
I have recently written an application(vb.net) that stores and allows searching for old council
I'm working on a Windows Mobile 6.1 app written in C#. I have recently
I recently have a problem that my java code works perfectly ok on my
I have a large infrastructure that is written in Python 2.6, and I recently
I have a PHP application that is written with Zend Framework. It uses Phing
I have recently written an application on per-contract base for a company. The deal
I have recently written a socket server in PHP that will be handling communication
I have recently written a macro for visual studio 2010 in the macro IDE,
I'm using Visual Studio 2005 on a Windows XP SP3 machine and recently have

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.