This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
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 Android Security Essentials Live Lessons this week in the Android 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
Author

Need to make a math applet with paint

Marek Paul
Greenhorn

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.
Thanks!
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10172
    
    8

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


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Need to make a math applet with paint
 
Similar Threads
create simple "reports"
Writing a pixel mapping program
How do you draw in a frame?
Drawing a Character Grid
Clock