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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T20:04:24+00:00 2026-06-09T20:04:24+00:00

I’ve been working with Java graphics programming and I feel that I understands how

  • 0

I’ve been working with Java graphics programming and I feel that I understands how it works.

One thing that I don’t like/haven’t grapsed yet is how to manage drawing lots of graphics (shapes, images, etc) on a panel.

All the books/tutorials I’ve currently being going through have you put all the drawing you want done in the paintCompnents/paint function. Ex,

public void paint(Graphics g){
    //do stuff here....
}

Thing is I have so much I want to draw that putting a bunch of code in one function is ugly, hard to read, and makes it hard to manage/edit…

I understands OOP but I’m new to graphics programming. How should I manage all the “data” I want drawn on my canvas (JPanel to exact). I’m currently calling functions inside the paint(..) method. Ex,

public void paint(Graphics g){
    drawCars(g, x,y,wid,len,etc,etc);
}

then…

drawCars(Graphics g, int x, int y, int wid, etc etc){
    g.drawSomething(x,y,wid,len,)
    g.drawAnotherThing(x+90,y+60,etc, etc);
}

The problem is then in my JPanel class I have all these stray functions i have to manage.

And this is only for drawing “one page” of stuff.. I can’t imagine having to switch views or a game screen where I could have a bunch of things animating on a page..

I’m just looking for direction on how to organize code drawn by the paint() method in java so I don’t go crazy looking at my old work. Any tutorials, books (esp if they’re free), or maybe good code to read would be very very appreciated.

Everything I’ve found thus far is about teaching what you “can” do with graphics/graphics2D/java but i’m looking for organization/style tips as suggested by experts..

  • 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-09T20:04:25+00:00Added an answer on June 9, 2026 at 8:04 pm

    Make classes for logical things you draw like cars. Each object would know all it needs to know to paint it self like position, size and color. If you let all these objects implement a common interface you can all put them together in a list. When time comes to draw them you iterate over the list and call each objects draw method.

    Apart from that document the drawing code well so that for each draw statement it is clear what part it is actual drawing.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text
I am reading a book about Javascript and jQuery and using one of the

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.