Drawing in a grid on an AWT Canvas - java

Hi I'm currently making an application for some research I am doing. I need to be able to draw on a grid in a canvas. More detail:
I need to create the grid, possibly displaying it in the canvas itself, with a customizable number of vertical/horizontal grid markers.
I need to be able to draw points that snap only to grid line intersections.
I need to be able to draw lines that can only snap to grid line intersections as well.
I need a way to fill in an area that has been bounded by the lines that I drew with a certain color.
Please note that I am not looking for someone to write the program for me, I just need help taking that first step and where to look for additional resources etc. I have no idea where to begin. Also I am using NetBeans GUI Builder, if that is helpful. All I have now is the canvas set up. I have no idea where to go from there. Thank you very much.

Related

Is there a function to find color of point in AWT/SWING

So, I've created this little maze building algorithm (trying to understand how Java AWT & Swing works).
Now, I've used the Graphics (paint method) to create the maze itself, meaning I didn't store it anywhere.
Now I wanted to know if there is a way to know if at given a specific point on the JFrame, is there a way to tell which color it is?
If so, how can I do it?
Let's say for example in my maze I want to see what color is on the PURPLE dot (seeing if it's a wall there basically).
Is there a way to do it, or do I have to do a work-around that?
Thanks.
There is no direct way to a Component's image buffer. But there are two indirect ways.
(Better) Create an Image (Either BufferedImage or Component.createImage) with the same height and width as your Component. You can then run myComponent.paint(myBuffer.getGraphics());. This will draw the component on the image, and from there you can get the pixel Color you are interested in
(Alternative) You can use java.awt.Robot to capture the screen in an Image. Use this image similar as described above

how can I make a Moveable and resizable canvas draw Android?

I need to create a Canvas draw (Or maybe another better way of creating this?) that has two separate points in a horizontal line. This is not the problem, but I need the two endpoints to move independently and also be "resizable" on user touch and drag. I've added a gif to better explain what I need.
What is the best approach for this? Can it really be done using a canvas drawing? Even better, I just care if the line resizes horizontally, I don't need it to change vertically at all.
I'm not putting here the end goal of this, simply because it's not the point of my question, but if it proves to be necessary I can edit and explain why I need this.
canvas can do any drawing you want, in you case, consider using seekbar or custom it

Best way to draw a scrolling curved path onto a canvas

I want to create an illusion of a moving road or path.
For fun, I was thinking about how this could be done:
draw the whole path out in an image and simply have the image scroll across the screen - this would be annoying to manually draw and eliminates the ability to have a random path.
generate a pixel thin line equal the to width of the path at the top of the screen and simply move the line down the screen to have it scroll. And constantly generate new lines at the top in a slightly different location.
This is all I could come up with, I'm sure there are much better ways. How would y'all do it?
What about making a queue which stores the path with a maximum size. And then you just redraw it when it gets updated.
I think drawing the line again is comparable to drawing a full screen image in performance concerns. Furthermore it will take less memory.

Creating scalable checkered margin in java swing

I need to write programm which must drawing graphs.. I use java with swing (if you think that swing it is not good decigion please offer other tools) .. And my teacher say that I must drawing graphs on checkered margin and I don't know what use in this situation.. If someone do something like this please help me.. How make this checkered margin (and my teacher say to me that this checkered margin must be scalable)
UPDATE
Oh I forget to say that I mast drawing graph by myself (set 2 dots and then my function must draw line between this dots)
For reference, MyPanel draws a gray checkerboard in its background; SineTest shows how to plot using cartesian coordinates.

Android UI Design Suggestion

This is the scenario:
I have one image background set on an activity. On this background, a rectangle has been drawn (in other words, one image depicting a rectangle). I need to display text WITHIN this rectangle.
Right now, I have one solution in mind: since I'm going to optimize the UI for most screens (incl. tablets), I'm going to customize the main .xml layout for each screen size (multiple .xml layouts). Thus, I can manually set the place where the text area goes within the rectangle (+ its size).
I am most certain that this solution is NOT good. I'd like to hear some suggestions from more advanced developers. What would an elegant way of placing text over a background image showing a rectangle, so that the text stays within the rectangle's borders be?
Because I need to set particular positions for other UI elements (centered buttons (vertically/horizontally), I am currently using a Relative Layout.
By default if you have used dp as dimensional measure, your app should in theory work fine for all resoultions. Android by default scales the screen to fit different screens. AndroidDeveloper You just have to make sure that you have different images for resources (Rectangle image). There is another post in SO which you might be intrested to look into link
Cheers
RIchie

Categories