It's not a secret anymore!
The moose likes Applets and the fly likes Need to make a math applet with paint Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Applets
Bookmark "Need to make a math applet with paint" Watch "Need to make a math applet with paint" New topic

Need to make a math applet with paint

Marek Paul

Joined: Nov 11, 2010
Posts: 1
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.
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10836

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

[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
I agree. Here's the link:
subject: Need to make a math applet with paint
jQuery in Action, 3rd edition