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 5 of 5

Thread: drawing is in the same postion :(

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

    Angry drawing is in the same postion :(



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

    Angry drawing is in the same postion

    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.

  3. #3
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: drawing is in the same postion :(

    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

  4. #4
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: drawing is in the same postion

    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!

  5. #5
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: drawing is in the same postion :(

    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!

Similar Threads

  1. Drawing a pentagon
    By Zomosa in forum AWT / Java Swing
    Replies: 7
    Last Post: October 11th, 2011, 10:21 PM
  2. help with JFrame, drawing, and JButtons
    By Khoatic in forum AWT / Java Swing
    Replies: 1
    Last Post: November 19th, 2010, 12:34 AM
  3. Line Drawing Program
    By The_Mexican in forum What's Wrong With My Code?
    Replies: 5
    Last Post: November 13th, 2010, 03:54 PM
  4. [SOLVED] Drawing on JFrame
    By kbarrett1989 in forum AWT / Java Swing
    Replies: 3
    Last Post: October 31st, 2010, 03:41 AM
  5. Drawing
    By toxikbuni in forum Java Theory & Questions
    Replies: 0
    Last Post: April 20th, 2010, 02:43 PM