Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 13-11-2009
Member
 
Join Date: Nov 2009
Posts: 583
Diagram editor in java

Hi
I have done some programs in java. Now I want to create a diagram editor. My idea is , there will be a rectangle and I will connect them with clicking each of them. I created a rectangle on the screen but I can not choose rectangles. It creates but not recognıze previous one or some one which I clicked with the mouse. Any idea to correct this problem or nay other way round to create such a project. any help will be appreciated. Thanks in advance.
Reply With Quote
  #2  
Old 13-11-2009
Member
 
Join Date: Apr 2008
Posts: 1,948
Re: Diagram editor in java

You said your code just draws rectangles, then there will indeed be no way to select one with the mouse. Your code must keep track of what rectangle have been drawn and then check this list when a mouse click arrives. In the example there is a list of trees, each represented as an object. Each object has an associated hotsp i.e. a Shape (circle) at a particular coordinate location. One particular tree is the value of the global variable hottr. This tree is drawn in a different color.
Code:
public void paint(Graphics g) {
		g.drawImage(diagram, 0, 0, this);
		// draw all the items on the Tree list
		for (Tree t : trees) {
			gOff.setColor((t==hotTree) ? hotColor : treeColor);
			gOff.fill(t.hotsp);
		}
	}
Code:
public void mouseMoved(MouseEvent e) {
		TreeInfo oldHot = hottr;
		hottr = null;
		// if we are in range of one of 'trees', set hottr
		for (Tree t : trees) {
			if (t.hotSpot.contains(1.0 * e.getX(), 1.0 * e.getY())) {
				hottr = tree;
				break;
			}
		}
		if (oldHot != hottr) repaint();
	}
Reply With Quote
  #3  
Old 13-11-2009
Member
 
Join Date: Nov 2009
Posts: 583
Re: Diagram editor in java

Thanks for your reply.
I tried to create object like creating array list and adding them, then usıng Poınt p = e.getpoint and compareing if(s.contains(p)). But the problem is getlocation always return 0.0 it is located at the top left of the window. when I am creating object it creates on screen but when I ask its location it says me that is on 0.0 point. But it works when I used Rectangle2d class from library .it gave real coordinates and choosing work.But I want to create my own object and rectangle
Reply With Quote
  #4  
Old 13-11-2009
Member
 
Join Date: Apr 2008
Posts: 1,948
Re: Diagram editor in java

Hi
The best idea is to create your own objects with four rectangle coordinates. Or you might create a subclass of Rectangle. The previous post mentions "if(s.contains(p))", but fails to say what s is. It would have to be a Shape or rectangle describing where the rectangle was drawn in the window. Check your program for the same and if any problem then post by your query.
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Diagram editor in java"
Thread Thread Starter Forum Replies Last Post
Is there a Mission Editor or Map Editor or Mods for Steel Armor: Blaze of War? NatwarL@L Video Games 6 20-12-2011 07:04 PM
Java editor for palm device! Honey Singh Software Development 4 15-09-2010 05:17 AM
Best editor for java HardWeaR Windows Software 3 24-11-2009 09:47 AM
Gliffy Online Diagram Editor Jeffrey Reviews 3 11-11-2009 10:45 AM
JAVA WYSIWYG Editor information WeezY Software Development 4 08-11-2009 02:09 AM


All times are GMT +5.5. The time now is 08:37 PM.