drawing is in the same postion
in this code
Multiupload.com - upload your files to multiple file hosting sites!
and i use this library
Multiupload.com - upload your files to multiple file hosting sites!
thnx
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.
drawing is in the same postion
in this code
Multiupload.com - upload your files to multiple file hosting sites!
and i use this library
Multiupload.com - upload your files to multiple file hosting sites!
thnx
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 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()); } }); 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 arg0) { // TODO Auto-generated method stub } @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 } }
it is dos't work with me i don't know why???
Last edited by kisokiso; December 20th, 2011 at 10:56 AM.
Do you have a question to ask or are you having some problems?
Please ask or explain.
Please Edit your post and wrap your code with[code=java]<YOUR CODE HERE>[/code] to get highlighting
If you want help, you'll have to provide an SSCCE that demonstrates the problem.
Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!
Ugh, please don't post multiple copies of the same question. I've merged your duplicate posts.
Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!