Jump to content

Shape program help. Please.

- - - - -

  • Please log in to reply
1 reply to this topic

#1
stevie754

stevie754

    Programmer

  • Members
  • PipPipPipPip
  • 110 posts
Hi everyone,

I am having a little trouble with my latest university assignment. (So don't give me the answer straight out if you got it just looking pointed in the right direction).

I have been tasked with creating a program that will show 3 different shapes:
  • Square, Triangle, and Circle.
  • Only 1 shape will be drawn on the screen at any one time.
  • There are 2 calculations in text boxes at the bottom of the screen showing the area and boundary for the given shape.
  • There is also a slider at the bottom of the screen and as it is moved the area and boundary calculation will change accordingly.
  • The shapes and the calculations are connected into the relevant JMenuItem, changeAction Listener.

The problem I am having is the final stage that I am at now.
I need to be able to make the shapes being drawn to the screen repaint and take into account the slider value and add that onto the shape boundaries, therefore changing the size of the shape.

I have the shapes being created with the default values working correctly, and can hardcode in numbers to add to the coordinates to make the shapes scale as I would like.

I just need to get a way to pass values from the slider in the class MyControlPanel to the paintComponent method in the DrawShape class

Thanks in advance for any replies and taking the time to read this.
Stephen

#2
fread

fread

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 787 posts
You need to have variables holding the dimensions of the shape in the shape class. Create a method (a setter) to update the value of the variables in the shape class when the slider moves. When paint is called it will draw with the new values each time.
//for example updating a rectangle
public void updateRectangle(width, height){
        this.width = width;
         this.height = height;
}

When paint draws it gets the updated values.
[FONT=Verdana]
[/FONT]draw(x,y,width,height)





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users