• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Need to make a math applet with paint

 
Marek Paul
Greenhorn
Posts: 1
  • 0
  • 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.
Thanks!
 
Maneesh Godbole
Saloon Keeper
Posts: 10971
11
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • 0
  • 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 http://download.oracle.com/javase/tutorial/uiswing/painting/index.html 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
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic