Hi,
CAN SOMEONE GIVE ME a hand to solve my java program? sorry it's little bit long
This program uses polymorphism to execute simple shapes: circles, squares, and rectangles. The mouse is used to click on a window, and wherever you click, a shape will appear randomly (each shape type has its own color: circles are green, squares are yellow, and rectangles are blue). The implementation should make use of an ArrayList, but your ArrayList should store the shape objects themselves. For this to work, you will need to define a class for each shape object. Of course, each object will need to store its color. But also, each class will need to provide a draw () method that takes a Graphics object as argument, and draws itself with the appropriate commands on that Graphics object. You must use polymorphism to implement this program. All of your various shape classes should extend a Shape abstract class (which you also define). This will allow you to store an ArrayList of Shapes in the JPanel part of your program. Then, modify your program so that if you click on existing shapes, they become red, but if you click on the background, you get a new shape (as before). For this to work, your shapes should implement a boolean method (maybe call it contains) that takes a Point as argument, and returns true or false in accordance with the appropriate geometric calculation. (This is why each of your geometric objects needs its own implementation for contains ().) Back in your JPanel subclass, where you are handling mouse clicks, you need to insert a check: run through your list of shapes, and determine which of them contain the point where the user just clicked. If so, change those shapes' colors to red. But if the click point was not inside any of the existing shapes, generate a random shape at that location, as you were doing in the first part of this assignment. ). Again Your Shape superclass should define abstract methods draw() and contains() (and maybe others).
Thank you so so so much for helping me.
6 replies to this topic
#1
Posted 28 November 2010 - 06:51 PM
|
|
|
#2
Posted 28 November 2010 - 09:01 PM
If someone can show me at least how to start and what should I do first plz
#3
Posted 29 November 2010 - 12:33 AM
Start with the circle, triangle, square class. Create the shape class after those, and make the circle, triangle, square class extend Shape.
Put in the shape class as much as possible, everything that's common in the circle, triangle and square class goes into shape. So not only the draw(), and contains(), but also the color.
Please try to put this together (leave methods empty if you don't know what to write in them) and post some code. Noone will be willing to help much if you don't provide some code yourself.
Put in the shape class as much as possible, everything that's common in the circle, triangle and square class goes into shape. So not only the draw(), and contains(), but also the color.
Please try to put this together (leave methods empty if you don't know what to write in them) and post some code. Noone will be willing to help much if you don't provide some code yourself.
#4
Posted 29 November 2010 - 03:54 AM
oxano said:
Start with the circle, triangle, square class. Create the shape class after those, and make the circle, triangle, square class extend Shape.
Put in the shape class as much as possible, everything that's common in the circle, triangle and square class goes into shape. So not only the draw(), and contains(), but also the color.
Please try to put this together (leave methods empty if you don't know what to write in them) and post some code. Noone will be willing to help much if you don't provide some code yourself.
Put in the shape class as much as possible, everything that's common in the circle, triangle and square class goes into shape. So not only the draw(), and contains(), but also the color.
Please try to put this together (leave methods empty if you don't know what to write in them) and post some code. Noone will be willing to help much if you don't provide some code yourself.
I will post the code as soon as get it done. Thx
#5
Posted 03 December 2010 - 11:20 AM
I have solved it. Finally !!!!!!!!!!!
#6
Posted 03 December 2010 - 11:21 AM
Good job, Lina :)
#7
Posted 03 December 2010 - 08:02 PM
oxano said:
Good job, Lina :)
Thank you, It was not easy. Someone helped me out :)
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users


Sign In
Create Account


Back to top









