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
Code :
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!
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.
Re: problem in my code java code graph editeur
Quote:
the new graph it add in the same position i want add this
Why? How? Where? How it reacts when you try this?
Re: problem in my code java code graph editeur
Quote:
Originally Posted by
Mr.777
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 :()
Re: problem in my code java code graph editeur
Code :
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
}
}
Code :
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();
}
}
Code :
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();
}
}
Code :
public class Principal {
public Principal(){
Acoes a = new Acoes();
a.setVisible(true);
}
public static void main (String args[]){
new Principal();
}
}
Code :
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
Re: problem in my code java code graph editeur