Mini Paint Program

Hello, I am currently writing a small drawing program and I am having trouble with changing the size of the shapes. To do this, I have to access the arraylist shapes, check whether pressedX/pressedY is on any of the shapes in the arraylist using the findShape() method and then when released, uses moveBy() in the Rectangle/Oval/Line class and moveShape() in the miniDraw class to move the shape and draw it in the newreleasedX/releasedY position.

So far I think I have pin pointed the problem to being the method in all the shapes classes, that checks whether the pressedX/pressedY which is the on() method, and the findShape() method in the miniDraw class.

I am really noobish and I take ages to understand things so bear with me if either there are a lot of silly things in the code or the answer is really simple.

You may have pinpointed the problem, but you haven't actually told us what the problem is.
Is the code doing something that you didn't expect it to do ?
Is the code not doing something that you wanted it to do ?
Something else ?

Joanne

Jess Te Wiata
Greenhorn

Joined: Jun 03, 2014
Posts: 4

posted Jun 04, 2014 03:55:14

0

Ah, yes, sorry. The shapes are not moving when I click and release. At one point it was giving me null pointer exceptions but I managed to fix that and now it compiles and runs fine, but it still doesn't move the shapes.

Without the classes in the ecs100 package we can't compile and run your code which makes it harder for us to see what is happening.

May I suggest you add a lot more trace statements so you can see the program flow.
One thing that struck me as odd was in your mousePerformed method you add a new shape every time the mouse is released, are you sure this is correct?

Jess Te Wiata
Greenhorn

Joined: Jun 03, 2014
Posts: 4

posted Jun 04, 2014 05:54:06

0

Yea, I need to add comments. I would probably pick up errors a lot quicker.

Ah yes, I see that and I will investigate it. Maybe that is the reason the shape is not showing up. It's a good start and I didn't pick up on it. Thank you.

in your opening post you mentioned having problems with the 'findShape' method. If you look at the code:

you can see that when you do find a Shape s, you nevertheless return 'currentShape'.
You also do not use the parameters of this method, but you use the variables 'pressedX'
and 'pressedY'. These also happen to be the actual parameters when you invoke this
method, so it will not make any difference here.

Be aware though, that when shapes overlap, then you will only find one of these, namely
the one that comes first in the 'shapes' array. In these cases, you could for instance use a
double click, or shift-click, to select another shape. It will make you program a bit more
complex. How do you display a selected shape? By putting some squares in the corners?

Greetz,
Piet

Jess Te Wiata
Greenhorn

Joined: Jun 03, 2014
Posts: 4

posted Jun 04, 2014 15:14:22

0

So, when I call currentShape, it's not returning the shape that x, y is on, it's returning whatever the currentShape is at the time? In that case I should be using the arraylist.get(index) to return whatever element makes s.on(pressedX, pressedY) true?

The code is only supposed to selected the topmost shape but I am all for making the program nicer. Once I get the shapes moving, I am definitely going to look into other ways I can make the program better.