Win a copy of 97 Things Every Java Programmer Should Know this week in the Java in General forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
  • Piet Souris
  • salvin francis
  • fred rosenberger

Need to make a math applet with paint

Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, I wanted to make an program that does the following:
-Displays a grid (Sort of like a sheet of graph paper)
-Draws geometric shapes on that grid
-Can draw a straight line from one point to another.

I'm pretty sure about the mathematical and techincal systems that would be applied, however I have no clue as to where/how I would generate the grid, and how to draw the lines, etc.
I could use a few pointers as to what I should read up on.
Posts: 11445
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch.

You will need to override the paintComponent(Graphics g) method of your panel to draw the grid and shapes. Take a peek at for tips on how it should be done.
Note: Notice the call to super.paintComponent() in the overridden method.

If you check out the API class for Graphics you will notice it has built in methods like drawLine() and drawPolygon() which you will find useful.

I pseudo code
1) Subclass JPanel
2) Override paintComponent
3) In your overridden paint component do all custom painting operations like drawing the grid, shapes etc
4) Use an instance of your panel in the application
Creativity is allowing yourself to make mistakes; art is knowing which ones to keep. Keep this tiny ad:
Thread Boost feature
    Bookmark Topic Watch Topic
  • New Topic