I want to make a rectangle to move object insade rectangle to other position on canvas, if anyone has any suggestion I will be very happy.
Here is an example:
This must be a paint application, so you should already have some code and you'd better post it, so we could use as the starting point.
You need to write a custom widget and intercept touch events to build the selection. Whenever the selection changes, you have to repaint the UI to draw the selection rectangle. When you detect the end of the gesture, the widget listens to touch events to decide if the user wants to move the selected area (the touch gestures started inside the selection) or deselect it and maybe start a new selection. Again, if the user is dragging the selection, every new touch event causes an invalidate() on the component.
What exactly is it that you are displaying?
If it is a image you can dimply duplicate the pixels in a selected rectangle and temporary save it in a new image until the drag motion stop and then paint it back on the original image.
Related
I am trying to create an actor with Scene2D, that appears on the screen only when a certain event is triggered. To do so, I use the following code:
blackRectangle.addAction(Actions.alpha(0));
optionalStage.addActor(blackRectangle);
blackRectangle.addAction(Actions.delay(0.5f,Actions.alpha(0.7f, 0.5f)));
The problem I am having is that when the rectangle is added to the optionalStage, the rectangle appears on the screen for 1 frame, disappears, and then proceeds to fade in as supposed to.
I tried playing with
actor.setVisible(true/false);
but no luck. Is there a way to prevent that "flash" when the actor is added to the stage, even though its alpha is 0?
Change this :
blackRectangle.addAction(Actions.alpha(0));
to
blackRectangle.getColor().a=0;
I am writing an android app but am new to this.
I want to upload an image from storage and find the color values of certain spots in the image, not on click but automatically
and store them in a list or array.
I repeat I am new to this, I know there is a onTouch event which gets coordinates of where you touch the image.
I do not know how to get coordinates of a certain spot automatically without any interaction on the image by user. I want to press a button and it goes and gets certain coordinates colors.
Please help me out instead of referring me to the Ontouch version page
I am drawing a gesture on the screen. Can we control the speed of drawing the gesture ?? It is being displayed but directly without showing how it was drawn.. I tried using sleep(), wait() methods but didn't work. I want it show the path how the gesture was drawn slowly.. Is it possible ?
I am writing a zigzag drawer as my school assignment. Basically what is expected is to be able to draw zigzags on a canvas, to be able to move vertices of the zigzags and to be able to move the entire zigzag. Also we can change the color and thickness of the zigzags.
I could manage to draw zigzags, a left click starts and subsequent left clicks continues the zigzag, and a right click finishes it. In this way i can draw several zigzags.
What i can not do is how i can make the vertices of the zigzags movable? I am keeping the point coordinates in an arraylist of type mypoint which consists of x, y and depth values. I am drawing all the painting on a canvas which is an extended class of JPanel. in the paintcomponent method i call drawline methode for every vertex in the list. As these are just paintings i cannot figure out how i will detect that the user is clicking on the vertex. Can i have little button like controllers when clicked will do the job i want. i tried to use labels and standard buttons, but neither can i position them appropriately nor are they too large to be just handlers for vertices.
Do you have suggestions on these?
You could have two modes of operations, which must be chosen by the user by selecting a radio button, for example: one for drawing zigzags, and the other one for selecting vertices.
While the chosen mode is "zigzag", the mouse clicks allow drawing zigzags as you have already implemented. When the chosen mode is "vertex selection", then a mouse click could find a vertex whose distance from the clicked point is less than 3 pixels, and the dragging of the mouse could move the vertex from its original position, following the mouse pointer.
You could inform the user about the selected vertex by displaying a small squere around the vertex.
I have made an Ellipse with the help of java.awt.geom.Ellipse2D
Now, I want that whenever user clicks on that ellipse, an event is generated so that I can listen to that event and peform subsequent tasks based on the ellipse which generated that event.
Here is a simple example of an object drawing program that demonstrates click, drag and multiple selection. Also consider JGraph, which is a much more advanced library for graph visualization.
I'm going to assume this is a question asking a way to listen to mouse clicks which are made on an ellipse drawn on some Swing component using Graphics2D.draw.
The simple answer is, there is no way to generate mouse events from graphics drawn on a surface.
However, here's an alternative approach:
Store the Ellipse2D objects from which the ellipses were drawn from in a List.
Register a MouseListener on the Swing component where the user is to click on.
From the MouseEvents generated from the mouse clicks, determine the location at which the mouse was clicked (using MouseEvent.getPoint), and check if the mouse click occurred in any of the Ellipse2Ds contained in the aforementioned List, using the Ellipse2D.contains method.
I don't think this is possible without lots of handcoded stuff (letting the canvas or whatever, listen to mouse events, and calculating yourself if the ellipse was clicked on).
If you want to do more like that consider scenegraph. With that the ellipse would be an object in its own right and you can register event listeners.
Edit as response to comment:
Scenegraph: https://scenegraph.dev.java.net/
google for more resources: scenegraph java
And yes. Scenegraph ist part of the JavaFX stuff, but works nicely with pure Java (no FX)