Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 6 of 6

Thread: problem in my code java code graph editeur

  1. #1
    Junior Member kisokiso's Avatar
    Join Date
    Dec 2011
    Posts
    5
    My Mood
    Cool
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Talking problem in my code java code graph editeur

    hi evry one i have some problms in this code source

    Multiupload.com - upload your files to multiple file hosting sites!
    graph editeur

    the new graph it add in the same position i want add this

    graphComponent.getGraphControl().addMouseListener(new MouseAdapter(){
    public void mousePressed(MouseEvent e) {
    // TODO Auto-generated method stub
    if(e.getClickCount() == 2){
    long x = e.getX();
    long y = e.getY();
    mxGraphComponent graphComponent = new mxGraphComponent(graph);
    Object cell = graphComponent.getCellAt((int) x, (int)y);
    System.out.println(graph.convertValueToString(cell));
    }
    }
     
    });

    but it's dont work with me
    help me plz

    ps i used the Jgraphx bibio
    Multiupload.com - upload your files to multiple file hosting sites!
    Last edited by kisokiso; January 6th, 2012 at 07:27 AM.


  2. #2
    Forum Squatter newbie's Avatar
    Join Date
    Nov 2010
    Location
    North Wales
    Posts
    661
    My Mood
    Stressed
    Thanks
    28
    Thanked 115 Times in 106 Posts
    Blog Entries
    1

    Default Re: problem in my code java code graph editeur

    "Doesn't work" isn't exactly specific now is it?
    Please provide more information about the issues you're having.
    Please use [highlight=Java]//code goes here...[/highlight] tags when posting your code

  3. #3
    Think of me.... Mr.777's Avatar
    Join Date
    Mar 2011
    Location
    Pakistan
    Posts
    1,136
    My Mood
    Grumpy
    Thanks
    20
    Thanked 82 Times in 78 Posts
    Blog Entries
    1

    Default Re: problem in my code java code graph editeur

    the new graph it add in the same position i want add this
    Why? How? Where? How it reacts when you try this?

  4. #4
    Junior Member kisokiso's Avatar
    Join Date
    Dec 2011
    Posts
    5
    My Mood
    Cool
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy Re: problem in my code java code graph editeur

    Quote Originally Posted by Mr.777 View Post
    Why? How? Where? How it reacts when you try this?

    I don't know how but it , i try many times ( i'm amateur in java )

  5. #5
    Junior Member kisokiso's Avatar
    Join Date
    Dec 2011
    Posts
    5
    My Mood
    Cool
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: problem in my code java code graph editeur

    import javax.swing.JButton;
    import java.awt.*;
    import java.awt.event.*;
    import java.awt.Color;
    import java.awt.Graphics;
    import java.util.HashMap;
    import javax.swing.JFrame;
    import javax.swing.JOptionPane;
    import com.mxgraph.view.mxGraph;
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.JFrame;
    import javax.swing.JMenu;
    import javax.swing.JMenuBar;
    import javax.swing.JMenuItem;
    import javax.swing.JTextField;
    import com.mxgraph.swing.mxGraphComponent;
    import com.mxgraph.view.mxGraph;
    import java.awt.Dimension;
    import java.awt.FlowLayout;
    import javax.swing.JOptionPane;
    import java.util.HashMap;
     
     
    public class Acoes  extends JFrame 
    implements MouseListener, MouseMotionListener
    {
    	protected static mxGraph graph = new mxGraph();
    	protected static HashMap m = new HashMap(); 
    	 private int prevX;
         private int prevY;
    	private  static int x,y;
    	private   String name ;
    	private Container 			mainContainer;
    	private String fileName;
    	 private boolean dragging;
    	private mxGraphComponent GraphComponent;
    	private JTextField text;
    	private JButton  buttAdd;
    	private JButton  butAddJiton;
     
    	private JButton  buttAddPlac;
    	private JButton  buttDel;
    	private JButton  buttLin;
    	private Object  cell ;
    	private JMenuBar mainBar;
    	JMenu fileMenu, editMenu, setColorMenuItem, aboutMenu;	
    	JMenuItem newMenuItem, openMenuItem, closeMenuItem, saveMenuItem, saveAsMenuItem, exitMenuItem, undoMenuItem, redoMenuItem, foreGroundMenuItem, backGroundMenuItem, authorMenuItem;
     
     
    	public mxGraph getGraph  (){
    		return graph;
    	}
    	public  static HashMap getM(){
    		return m;
    	}
     
    public  Acoes (){
    	super("Jpetri - Mos38-kiso");
    		initGUI();
    		mainBar 		= new JMenuBar();
    		setJMenuBar(mainBar);
    		/*----------------------------------------------------------------------------*/		
    		fileMenu  		= new JMenu("File");
    		fileMenu.setMnemonic('F');
     
    		newMenuItem		= new JMenuItem("New");
    		openMenuItem 	= new JMenuItem("Open");
    		closeMenuItem 	= new JMenuItem("Close"); 
    		saveMenuItem 	= new JMenuItem("Save");
    		saveAsMenuItem 	= new JMenuItem("Save As");
    		exitMenuItem	= new JMenuItem("Exit");
     
    		newMenuItem.addActionListener(null );
    		openMenuItem.addActionListener(null );
    		saveMenuItem.addActionListener(null);
    		saveAsMenuItem.addActionListener( null);
    		closeMenuItem.addActionListener(null );
    		exitMenuItem.addActionListener(null);
     
    		fileMenu.add(newMenuItem);
    		fileMenu.add(openMenuItem);
    		fileMenu.add(closeMenuItem);
    		fileMenu.addSeparator();
    		fileMenu.add(saveMenuItem);
    		fileMenu.add(saveAsMenuItem);
    		fileMenu.addSeparator();
    		fileMenu.add(exitMenuItem);
    /*----------------------------------------------------------------------------*/
    		editMenu = new JMenu("Edit");
    		editMenu.setMnemonic('E');
     
    		undoMenuItem	   = new JMenuItem("Undo");
    		redoMenuItem 	   = new JMenuItem("Redo");
     
    		setColorMenuItem   = new JMenu("Set Color");
    		foreGroundMenuItem = new JMenuItem("Set ForeGround");
    		backGroundMenuItem = new JMenuItem("Set BackGround");
     
     
     
    		setColorMenuItem.add(foreGroundMenuItem);
    		setColorMenuItem.add(backGroundMenuItem);
     
    		editMenu.add(undoMenuItem);
    		editMenu.add(redoMenuItem);
    		editMenu.addSeparator();
    		editMenu.add(setColorMenuItem);
    /*----------------------------------------------------------------------------*/
    		aboutMenu	= new JMenu("About");
    		aboutMenu.setMnemonic('A');
     
    		authorMenuItem = new JMenuItem("Author");
     
    		aboutMenu.add(authorMenuItem);
    /*----------------------------------------------------------------------------*/			
    		mainBar.add(fileMenu);
    		mainBar.add(editMenu);
    		mainBar.add(aboutMenu);
    /*----------------------------------------------------------------------------*/
    		/*----------------------------------------------------------------------------*/
    		/*----------------------------------------------------------------------------*/	
     
    	/*----------------------------------------------------------------------------*/
    		/*----------------------------------------------------------------------------*/
     
    }
    private void initGUI() {
    	setSize(900, 600);
    	setLocationRelativeTo(null);
     
     
        GraphComponent = new mxGraphComponent(graph); 
    	GraphComponent.setPreferredSize(new Dimension(870,480));
    	getContentPane().add(GraphComponent); //
    	this.addMouseListener(this);
         this.addMouseMotionListener(this);
     
    	//
     
     
     
     
    	text = new JTextField();
    	getContentPane().add(text);
    	text.setPreferredSize(new Dimension(520, 21));
    	setLayout(new FlowLayout(FlowLayout.LEFT));
     
    	buttAddPlac = new JButton("AddPlac");
    	getContentPane().add(buttAddPlac);
    	buttAddPlac.addActionListener(new ActionListener(){
     
    		public void actionPerformed(ActionEvent e){
    			AddPlac add = new AddPlac(text.getText());
    		}
    	});
     
    	butAddJiton = new JButton("AddJito");
    	getContentPane().add(butAddJiton);
    	butAddJiton.addActionListener(new ActionListener(){
     
    		public void actionPerformed(ActionEvent e){
    			AddJito add = new AddJito(text.getText());
     
    		}
    	});
     
     
     
    	buttAdd = new JButton("add trans");
    	getContentPane().add(buttAdd);
     
    	 class MousePressListener implements MouseListener {
    		public void mouseDragged(MouseEvent evt)
            {
                if(!dragging)
                    return;
                int x = evt.getX();
                int y = evt.getY();
                if(x < 3)
                    x = 3;
                if(x > getWidth() - 57)
                    x = getWidth() - 57;
                if(y < 3)
                    y = 3;
                if(y > getHeight() - 4)
                    y = getHeight() - 4;
                //graphicsForDrawing.drawLine(prevX, prevY, x, y);
               prevX = x;
               prevY = y;
     
               AddGraph add = new AddGraph(text.getText());
     
            }
     
    		 public  void mouseClicked (MouseEvent evt){
    			 x = evt.getX();
    			 y = evt.getY();
    			 AddGraph add = new AddGraph(text.getText());
     
     
    		 }
     
    		@Override
    		public void mouseEntered(MouseEvent arg0) {
    			// TODO Auto-generated method stub
     
    		}
     
    		@Override
    		public void mouseExited(MouseEvent arg0) {
    			// TODO Auto-generated method stub
     
    		}
     
    		@Override
    		public void mousePressed(MouseEvent evt) {
    			// TODO Auto-generated method stub
    			 int x = evt.getX();
    	            int y = evt.getY();
    	            int width = getWidth();
    	            int height = getHeight();
    	            if(dragging)
    	                return;
    	            if(x > width - 53)
    	            {
    	                if(y > height - 53)
    	                    repaint();
     
    	            } else
    	            if(x > 3 && x < width - 56 && y > 3 && y < height - 3)
    	            {
    	                prevX = x;
    	                prevY = y;
    	                dragging = true;
    	                AddGraph add = new AddGraph(text.getText());
    	            }
    		}
     
    		@Override
    		public void mouseReleased(MouseEvent evt) {
    			// TODO Auto-generated method stub
     
    			 if(!dragging)
    	            {
    	                return;
    	            } else
    	            {
    	                dragging = false;
    	                AddGraph add = new AddGraph( null); 
    	                return;
    	            }
     
    		}
    	 };	 
     
     
    	buttAdd.addActionListener(new ActionListener(){
     
    		public void actionPerformed(ActionEvent e){
     
    			dragging = true;;
    		}
    	});
    	buttDel = new JButton("delt"); 
    	getContentPane().add(buttDel);
    	buttDel.addActionListener(new ActionListener(){
     
    		@Override
    		public void actionPerformed(ActionEvent arg0){
    			graph.getModel().remove(cell);
    	    }
    	});
    	buttLin = new JButton("Arc"); 
    	getContentPane().add(buttLin);
    	buttLin.addActionListener(new ActionListener(){
     
    		public void actionPerformed(ActionEvent e){
               AddLin line = new AddLin();
    	}
    	});
     
    	GraphComponent.getGraphControl().addMouseListener(new MouseAdapter()
    	{
    		public void mouseReleased(MouseEvent e)
    		{
    			cell = GraphComponent.getCellAt(e.getX(), e.getY());
    		}
    	});
     
       }
    @Override
    public void mouseDragged(MouseEvent evt) {
    	// TODO Auto-generated method stub
    	 if(!dragging)
             return;
         int x = evt.getX();
         int y = evt.getY();
         if(x < 3)
             x = 3;
         if(x > getWidth() - 57)
             x = getWidth() - 57;
         if(y < 3)
             y = 3;
         if(y > getHeight() - 4)
             y = getHeight() - 4;
         //graphicsForDrawing.drawLine(prevX, prevY, x, y);
        prevX = x;
        prevY = y;
     
        AddGraph add = new AddGraph(text.getText());
    }
    @Override
    public void mouseMoved(MouseEvent arg0) {
    	// TODO Auto-generated method stub
     
    }
    @Override
    public void mouseClicked(MouseEvent arg0) {
    	// TODO Auto-generated method stub
     
    }
    @Override
    public void mouseEntered(MouseEvent arg0) {
    	// TODO Auto-generated method stub
     
    }
    @Override
    public void mouseExited(MouseEvent arg0) {
    	// TODO Auto-generated method stub
     
    }
    @Override
    public void mousePressed(MouseEvent arg0) {
    	// TODO Auto-generated method stub
     
    }
    @Override
    public void mouseReleased(MouseEvent arg0) {
    	// TODO Auto-generated method stub
     
    }
    }



    import java.awt.Color;
    import java.util.HashMap;
    import javax.swing.JFrame;
    import javax.swing.JOptionPane;
    import com.mxgraph.view.mxGraph;
    import com.mxgraph.swing.mxGraphComponent;
    import com.mxgraph.util.mxConstants;
    import com.mxgraph.util.mxUtils;
    import com.mxgraph.view.mxGraph;
    import com.mxgraph.view.mxStylesheet;
    import java.awt.Color;
    import java.util.Hashtable;
     
    public class AddPlac extends Acoes {
    	  private static final long serialVersionUID = 196831535599934813L;
    	public AddPlac(String name){
    		this.getGraph().getModel().beginUpdate();
    		  Hashtable<String, Object> style = new Hashtable<String, Object>();
    		  style.put(mxConstants.STYLE_FILLCOLOR, mxUtils.getHexColorString(Color.red));
    		    style.put(mxConstants.STYLE_STROKEWIDTH, 1.5);
    		    style.put(mxConstants.STYLE_STROKECOLOR, mxUtils.getHexColorString(new Color(0, 0, 170)));
    		    style.put(mxConstants.STYLE_SHAPE, mxConstants.SHAPE_ELLIPSE);
    		    style.put(mxConstants.STYLE_PERIMETER, mxConstants.PERIMETER_ELLIPSE);
    		    mxStylesheet stylesheet = graph.getStylesheet();
    		    stylesheet.putCellStyle("MyStyle", style);
    		Object parent = this.getGraph().getDefaultParent();
    		Object v1 = this.getGraph().insertVertex(parent, null, name, 70,70, 70, 70, "MyStyle");;
     
    		this.getM().put(name,v1);
    		this.getGraph().getModel().endUpdate();
     
    	}
     
    }

    import java.awt.Color;
    import java.awt.Graphics;
    import java.util.HashMap;
    import javax.swing.JFrame;
    import javax.swing.JOptionPane;
    import com.mxgraph.view.mxGraph;
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    public class  AddGraph extends Acoes {
    	private  static int x,y;
    	 public void AddGraph ( int xx, int yy ){
    		 x= xx;
    		 y = yy;
    		 repaint();
     
    	 }
     
     
     
    	public AddGraph(String name){
    		this.getGraph().getModel().beginUpdate();
    		Object parent = this.getGraph().getDefaultParent();
    		Object v1 = this.getGraph().insertVertex(parent,null, name,x,y,10, 50);
    	//	Object v2 = this.getGraph().insertVertex(parent,null, name,30,30,10, 50);
    		this.getM().put(name,v1);
    		this.getGraph().getModel().endUpdate();
     
    	}
     
     
     
    }
    public class Principal {
    	public Principal(){
    		Acoes a = new Acoes();
    		a.setVisible(true);
     
    	}
    	public static void main (String args[]){
    		new Principal();
    	}
    }
    import javax.swing.JFrame;
    import javax.swing.JOptionPane;
    import java.awt.Component;
     
    import java.awt.MouseInfo;
    import java.util.HashMap;
     
    public class AddLin   extends Acoes {
    	public AddLin(){
    		Object parent = this.getGraph().getDefaultParent();
    		Object v1 = this.getM().get(JOptionPane.showInputDialog("digite o graph 1:"));
    		Object v2 = this.getM().get(JOptionPane.showInputDialog("digite o graph 2:"));
            String name = JOptionPane.showInputDialog("digite o name line :"); 
     
            this.getGraph().insertEdge(parent, null, name, v1, v2);
    	}
    }

    this all code
    Last edited by kisokiso; January 6th, 2012 at 07:34 AM.

  6. #6
    Think of me.... Mr.777's Avatar
    Join Date
    Mar 2011
    Location
    Pakistan
    Posts
    1,136
    My Mood
    Grumpy
    Thanks
    20
    Thanked 82 Times in 78 Posts
    Blog Entries
    1

    Default Re: problem in my code java code graph editeur

    You must provide SSCCE

Similar Threads

  1. Problem with Java code for Project
    By JavaAsh in forum What's Wrong With My Code?
    Replies: 7
    Last Post: October 19th, 2011, 03:52 AM
  2. Java Bar graph takes user input to create graph?
    By kenjiro310 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: March 31st, 2011, 07:37 AM
  3. reformatting java code problem
    By Fordy252 in forum File I/O & Other I/O Streams
    Replies: 0
    Last Post: November 23rd, 2010, 01:44 PM
  4. Re: Java Newbie Code Problem
    By erinbasim in forum What's Wrong With My Code?
    Replies: 1
    Last Post: January 17th, 2010, 01:05 AM
  5. [SOLVED] Java Newbie Code Problem
    By lee in forum What's Wrong With My Code?
    Replies: 6
    Last Post: January 16th, 2010, 02:05 PM