noorai's Profile User Rating: -----

Reputation: 0 Apprentice
Group:
New Members
Active Posts:
9 (0.01 per day)
Joined:
29-July 12
Profile Views:
751
Last Active:
User is offline Sep 25 2012 02:52 PM
Currently:
Offline

Previous Fields

Dream Kudos:
0
Icon   noorai has not set their status

Posts I've Made

  1. In Topic: MouseListener and MouseMotionListener

    Posted 29 Aug 2012

    View Postpbl, on 28 August 2012 - 07:59 PM, said:

    you shouldn't have static variables :)
    Adding b1 one than once, every time mouse is released, is kind of useless. Do it only once and toggle its visibility if required
    You need to mouseClicked() exactly at 0,0 so that x1 and y1 are 0 so the rest of the mouseReleased is executed


    Hi bpl
    I try your advice but the problem don't solve if you have another advice I needed so much. thanks
    look to the corrected code:
    package n;
    import javax.imageio.ImageIO;
    
    import javax.swing.*;
    
    import java.math.*;
    import java.awt.BorderLayout;
    import java.awt.Color;
    import java.awt.Container;
    import java.awt.Cursor;
    import java.awt.Dimension;
    import java.awt.FlowLayout;
    import java.awt.Graphics;
    import java.awt.Graphics2D;
    import java.awt.GridLayout;
    import java.awt.Point;
    import java.awt.Shape;
    import java.awt.event.*;
    import java.awt.geom.*;
    import java.awt.image.BufferedImage;
    import java.io.File;
    import java.io.IOException;
    
    import javax.swing.border.TitledBorder;
    
    
    public class ImageDrag5 extends JFrame {
    Canvas1 canvas;
      public JLabel label1;
      private  BufferedImage image1;
      private int x1,x2;
      private int y1,y2;
      public JButton b1=new JButton("Button");
      public Container container = getContentPane();
    
      public JFrame f=new JFrame();
      public  Graphics g2;
      public ImageDrag5() {
    	    super();
    	    container.setLayout(null);
    	 
    	    canvas = new Canvas1();
    	    container.add(canvas);
    	   
    	    label1 = new JLabel(new ImageIcon(image1));
    	   
    	    label1.setLocation(0,0);
    	    label1.setSize(75,40);
    	    container.add(label1);
    	    
    	    setSize(600,300);
    	    setVisible(true);
    	  }
      public static void main(String arg[]) {
    	  
    	  new ImageDrag5();
    	 
    	  
    	    } 
      
      class Canvas1 extends JComponent {
    	  public Canvas1() {
    		  initComponents();
    		  
    		  addMouseListener(new EventMouseListener());
    	      addMouseMotionListener(new EventMouseMotionListener());
    	    }
    	 
    	  
    	class EventMouseListener extends MouseAdapter {
    		
    	      public void mousePressed(MouseEvent me) {
    	    	 
    	    	 
    	  }
    	      
    	      public void mouseReleased(MouseEvent me) {
    	    	  if (x1 == 0)
    	    		  if (y1 == 0)
    	    			  {
    	    			  x2=me.getX();
    	    	                   y2=me.getY();
    	    	          b1.setLocation(x2,y2);
    	    	  	  	    b1.setSize(90,30);
    
    	    	  	  	b1.setVisible(true);
    	    	  	  	   
    	    	           }
    	    		  
    	    	  
    	    	  
    	      }
    	      public void mouseClicked(MouseEvent me) {
    	    	 
    	    	  x1=me.getX();
    	    	  y1=me.getY();
    	    	  add(b1);
    	  		b1.setVisible(false);
    	    	
    	    	  
    	      }
    	  }
    	
    	      class EventMouseMotionListener extends MouseMotionAdapter {
    	          public void mouseDragged(MouseEvent me) {
    	        	  
    	          }
    	          public void mouseMoved(MouseEvent me) {
    	        	 
    	          }
    	      }
      
    	      public void initComponents(){
    	    	  
    	          try{
    	              image1 = ImageIO.read(new File(("e:/button1.gif")));
    	              
    	          }
    	          catch(IOException ioe){ioe.printStackTrace();}
      
    	      }
    	      
      }
    }
    
    
    
    
  2. In Topic: MouseListener and MouseMotionListener

    Posted 29 Aug 2012

    Thanks for your advice
    I want the image appear at location(0,0) but the JButton that initiate in any where the mouse pointed after the mouse first chose the image(because I want later to add another images of textbox and label ). If there any advice to this??
  3. In Topic: MouseListener and MouseMotionListener

    Posted 28 Aug 2012

    Sorry I have a mistake in my code in adding the button the correction is:
     b1.setLocation(x2,y2); 
    
    
  4. In Topic: Java Drag and Drop Tutorial: Part 1- Basics of Dragging

    Posted 5 Aug 2012

    please i want to know how implements these code in your tutorials about drag and drop part1 and part2 i need it so much to see how drag & drop a button(to imagine it). i try to run these code but there are more problems.
    Please reply to my question as soon as possible.
    thanks
  5. In Topic: Java Drag and Drop

    Posted 30 Jul 2012

    how can make it? i need documents , links or any thing help me to make drag and drop of button, textbox and label

My Information

Member Title:
New D.I.C Head
Age:
Age Unknown
Birthday:
Birthday Unknown
Gender:

Contact Information

E-mail:
Click here to e-mail me

Friends

noorai hasn't added any friends yet.

Comments

noorai has no profile comments yet. Why not say hello?