Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Beginning Java
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Jeanne Boyarsky
Ron McLeod
Paul Clapham
Liutauras Vilda
Sheriffs:
paul wheaton
Rob Spoor
Devaka Cooray
Saloon Keepers:
Stephan van Hulst
Tim Holloway
Carey Brown
Frits Walraven
Tim Moores
Bartenders:
Mikalai Zaikin
Forum:
Beginning Java
How can I get my line shape to stay positioned when moving it?
kenny gill
Ranch Hand
Posts: 54
posted 11 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
I'm using a move button to move all the shapes but I can't get the line shape to stay positioned when I move other shapes. I am also having a problem where the line shape won't move if there are multiple shapes drawn.
public void mousePressed(MouseEvent e) { if (model.getAction() == Model.Actions.MOVE) { selectedInstance = model.getSelectedInstance(e.getX(), e.getY()); System.out.println("Selected Index :------------- " + selectedInstance); if (selectedInstance != -1) { oldColor = shape.get(selectedInstance).getLineColorType(); shape.get(selectedInstance).setLineColor(Model.MyColors.RED.toString()); startX = shape.get(selectedInstance).getX() - e.getX(); startY = shape.get(selectedInstance).getY() - e.getY(); } if (shape.get(selectedInstance) instanceof Line) { int diffX = e.getX() - dragStartX; dragStartX = e.getX(); int diffY = e.getY() - dragStartY; dragStartY = e.getY(); ((Line) shape.get(selectedInstance)).moveLineX(diffX); ((Line) shape.get(selectedInstance)).moveLineY(diffY); } } public void mouseDragged(mouseEvent e) { if (model.getAction() == Model.Actions.MOVE) { if (selectedInstance != -1) { shape.get(selectedInstance).setX(e.getX() + startX); shape.get(selectedInstance).setY(e.getY() + startY); } if (shape.get(selectedInstance) instanceof Line) { int diffX = e.getX() - dragStartX; dragStartX = e.getX(); int diffY = e.getY() - dragStartY; dragStartY = e.getY(); ((Line) shape.get(selectedInstance)).moveLineX(diffX); ((Line) shape.get(selectedInstance)).moveLineY(diffY); } }
Campbell Ritchie
Marshal
Posts: 79180
377
posted 11 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Don’t know. But I do know all those casts and
instanceof
tests suggest there is something very wrong with your class designs.
Don't get me started about those stupid
light bulbs
.
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
Can't get my line shape to move when other shapes have been drawn
Requesting help fixing a choice box.
Can't figure out why my shape won't re-size like the other. Code and details inside.
Can't figure out why my Line shape won't re-size
Requesting help fixing a choice box.
More...