Results 1 to 2 of 2

Thread: Drag and drop

  1. #1
    thayalan is offline Member
    Join Date
    Feb 2009
    Rep Power

    Smile Drag and drop

    Hello there,
    I am currently working on developing a module to compute the fault tree probability. I'm planning to use the Java AWT and Swing class to develop a J-Frame or container containing the drag and drop images (AND and OR gate symbols). The images are expected to be drawn(dragged and dropped) at another container. Upon completion the software should compute the value and store them.
    The question is how do I go about creating the JFrame or container with the images to be used in the drawing?


    Last edited by thayalan; 02-16-2009 at 05:12 AM.

  2. #2
    Steve11235's Avatar
    Steve11235 is offline Senior Member
    Join Date
    Dec 2008
    Rep Power


    Here are a few tips:

    Start with a JFrame.

    Set the content pane to GridLayout; 1 row, column.

    Add a JPanel. The JPanel will automatically fill the JFrame.

    Set the JPanel layout manager to null. This causes absolute positioning, which allows you to put components where you want them.

    Create a JComponent subclass to represent your gates. JLabel with a border and preferredSize might work quite nicely.

    For each gate component, add appropriate listeners for mouse down and mouse up.

    When a mouse down event occurs for a gate, start a javax.swing.Timer (*not* a java.util.Timer). Set the timer interval to 30 millis, which will give you a refresh rate of around 33 updates a second.

    Every time the timer fires, find the mouse position, and move the selected gate's top/left corner to the mouse position.

    Also, you can create a "snap to grid" effect by rounding off the mouse coordinates to the lower 5 or 10.

    Stop the time on mouse up.

    This approach saves having to monitor mouse move events while providing a smooth motion for the user.

    Have fun.

Similar Threads

  1. help with drag and drop on JList
    By ysl530 in forum AWT / Swing
    Replies: 4
    Last Post: 01-22-2011, 04:58 PM
  2. Simple DND (Drag and Drop) Example
    By Java Tip in forum SWT Tips
    Replies: 0
    Last Post: 07-07-2008, 04:37 PM
  3. SWT DND (Drag and Drop) comprehensive Example
    By Java Tip in forum SWT Tips
    Replies: 0
    Last Post: 07-07-2008, 04:36 PM
  4. Drag and drop
    By abhivenugopal in forum JavaServer Pages (JSP) and JSTL
    Replies: 0
    Last Post: 01-30-2008, 02:10 PM
  5. help drag and drop in JTabbedPane
    By RO86 in forum AWT / Swing
    Replies: 0
    Last Post: 08-14-2007, 01:22 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts