• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Mini Paint Program

 
Jess Te Wiata
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

Help is much appreciated.

This is the minidraw class




This is the Rectangle class


This is my Oval class



And the interface class


 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jess Te Wiata wrote:I think I have pin pointed the problem

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 ?
 
Jess Te Wiata
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Tony Docherty
Bartender
Posts: 2953
59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Piet Souris
Rancher
Pie
Posts: 1215
25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Jess,

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
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic