Add a mouselistener to drawingpanel - mouselistener

I would appreciate a very simple how-to on implementing a mouseListener into a DrawingPanel. If I want to return pixels of mouse clicks, for example, how do i do this? Thank you.

Basically you just add a mouse listener to that drawing panel, there are a lots of tutorials.
And getting coordinates of pixels is just calling e.getX() and e.getY() methods in mouseClicked(MouseEvent e).

Related

How can I implement this type of Button in Flutter?

I tried various other things like FAB Circular menu, but I wasn't able to achieve this outcome. Any help is appreciated.
This is from an app I saw on the Play Store
Not sure, if this is the best way, but I guess you could draw this (e.g. slices of a donut), position them with screen width, sin and cos and then put inkwells on top of them.

How to free draw and erase on a MATLAB GUI?

I wanted to create a gui that worked as a canvas for free drawing lines with the mouse and with option of erasing...
anyone can help me?
The simplest solution is to look at how other people have implemented this. For example, searching for freehand on the File Exchange brings up this freehand drawing function.
As a basic idea, you'll want to either regularly capture the mouse position, or to evaluate a callback on mouse movement.

drawing a line from gesture between 2 buttons

I am beginner for interactions on iphone. I have 3 buttons, one on the left, and the 2 other ones on the right. I would like to push the left button with finger and display a line real time stretching with my finger moving on screen that goes to the other button I am going to go to on the right - and then I reach the button on the right and release my finger the line stays on screen.
Where should I start in the manual to understand how to do something like this?
- please don't say page 1 ;-)
thanks for all the pointers so I can learn and write the code myself
Cheers,
geebee
Wow, uh, you're jumping right into the deep end.
First, the answer to your question is ... check out the Sample Code at developer.apple.com. By playing with those sample projects, and running them in the debugger, and reading that code, you can learn a whole lot about what you're trying to do.
Using those samples as your tutorial, refer to specific information in the reference docs also available at developer.apple.com. There are specific docs on the classes you'll be using (e.g. UIButton Class Reference), and there are high level guides that talk about different areas, like the Event Handling Guide for iOS, and Drawing and Printing Guide for iOS.
Here are some of the issues you're going to face, and some of the areas that you should read up on:
UIButtons are going to respond to your touch and won't allow any other view to receive that touch without some special handling in your code.
Check out samples that deal with UITouch events, Quartz 2D drawing, creating custom controls
Try doing this without any buttons first, that's fairly simple. Just figure out how to detect a TouchDownInside event, track the finger movement across the screen, and detect a TouchUpInside event, all in a normal UIView. (There may be a sample for this.)

How to detect circular gesture via Gesture Recognizer?

I am trying to implement a volume-control-like round button. Currently I can detect swipes by the Gesture Recognizer. How can I detect a circular gesture (clockwise and anti-clockwise) on the button? Thanks!
Are you looking for a one-touch gesture (like a circular slider), or a two-touch gesture (like grabbing and turning a real-world knob)? If the latter, take a look at UIRotationGestureRecognizer.
If the former, you're pretty much on your own. You can certainly implement your solution as your own custom gesture recognizer: this is expected by Apple, and there's some documentation to get you started (though I haven't seen many working examples out there). See also How to correctly subclass UIGestureRecognizer.
As a general approach, I'd think of the region for the gesture as a donut shape: a zone with center c, inner radius r1, and outer radius r2. When the user touches down you can calculate the distance from c using the Pythagorean theorem, and the angle with your favorite trig function. With that, you can determine whether the touch is within the zone. As the user drags, you can update the control value based on the angle. At some point, they'll either touch up, or drag outside of the zone, and that will end the gesture. I suggest allowing the touch to stray pretty far inside r1 or outside of r2: fingers are imprecise tools.
As failing to find a solution, and by logical inspiration from #sixten's answer, I've gone and created something useful, it's not bullet proof, but it seems to do what I need for now.
Please anyone, fork it, clone it, use it, improve it, it's open source, here's my repo link:
https://bitbucket.org/danielphillips/dpcirculargesturerecognizer
Have you tried writing your own gesture recognizer? There are detailed instructions in the docs.
Best Way would be implement Custom Gesture Recognizer. I do not know if you wish to detect a Discreet Gesture (Event Handling method would be called once the full circle has been detected) or a Continues Gesture (Event Handling method would be called every time you move your finger on a circular Path).
Probably, the user may not draw a perfect circle, and the solution provided by #Sixten Otto would be good.

How do you return draggable content to their original positions in iPhone dev?

I am wanting to create a button in my iPhone app that when touched will return other draggable elements to their original position. I have looked at the Apple "MoveMe' example, but that returns the button to the center of the screen. I want to be able to position draggable objects around the screen, drag the objects within the app, and then return them to their original starting positions by pressing a designated button.
Any help appreciated!
Cache the initial positions of your draggable objects, and use an event handler on the button to reset their positions. I'm a little confused. The MoveMe example code is exactly what you need to answer your question -- what more do you want? You won't find a perfect code example for any arbitrary problem you can dream up.
Play around with saving the original positions and using MoveMe to reset the objects and I bet you'll have what your looking for in no time at all.