Jump to content

need help with Java plz

- - - - -

  • Please log in to reply
6 replies to this topic

#1
lina

lina

    Learning Programmer

  • Members
  • PipPipPip
  • 34 posts
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.

#2
lina

lina

    Learning Programmer

  • Members
  • PipPipPip
  • 34 posts
If someone can show me at least how to start and what should I do first plz

#3
wim DC

wim DC

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 2,084 posts
  • Programming Language:Java, JavaScript, PL/SQL
  • Learning:Java
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.

#4
lina

lina

    Learning Programmer

  • Members
  • PipPipPip
  • 34 posts

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.

I will post the code as soon as get it done. Thx

#5
lina

lina

    Learning Programmer

  • Members
  • PipPipPip
  • 34 posts
I have solved it. Finally !!!!!!!!!!!

#6
wim DC

wim DC

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 2,084 posts
  • Programming Language:Java, JavaScript, PL/SQL
  • Learning:Java
Good job, Lina :)

#7
lina

lina

    Learning Programmer

  • Members
  • PipPipPip
  • 34 posts

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