I am building a Circuit Editor using Java. I'm now at very first stage. Now I'm building a simple editor like Paint.
I've implemented a drawing-pad where you can draw straight line and continue the line until you click an right click, by a "WIRE" Button click in the frame.
I've also implemented an "OR"(Logic) Button. After clicking that button, when you click anywhere in the drawing-pad, you will get an "OR" Logic Circuit.
But now my problem is that I want to implement a SELECT Button. After clicking this button, user can select any "OR" or other "LOGIC" Gates and move that gate to any position.
Now for the coding part. I'm new to JAVA Programming. I'm an advanced programmer in C and a little bit in C++ also.
I'm using the Swing here in JAVA.
I'm taking an image every-time a line is drawn or a "OR" gate is drawn by coding some part in the paintComponent function. The code in the paintComponent function is given below.
public void paintComponent(Graphics g)
{
if(image == null)
{
image = createImage(getSize().width, getSize().height);
graphics2D = (Graphics2D)image.getGraphics();
graphics2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
clear();
}
g.drawImage(image, 0, 0, null);
if(mousedragActv) g.drawLine(oldX, oldY, tmpX, tmpY);
}
Now all the "lines"(i.e wires) and "OR" gates are graphics class. but when i am converting them to image. I lost the class objects. So I'm not able to detect them any more. But I've to convert them to image to keep them in the drawing-pad as I'm "repaint()"-ing again and again.
As I'm not able to detect the graphics class-es any more, so I cant get them when I need them for moving to another place as they have already converted to image.
So, how can I implement this kind of SELECT. or Let me know how can I move the Graphics class object as well as keep other objects in the drawing pad too.
I've searched the Internet a lot and found Paint like Editor but the source-code is so complex that I can't get those.
Please, at least give me concept how can I proceed.