Drawing an arrow between two rectangle shapes

i am trying to draw an arrow between two rectangle shapes. the arrow will start from the center of one rectangle and end with the arrow tip at the edge of the other rectangle. i actually draw the arrow first, and draw the rectangles last so the effect of where the arrow starts will seem to come from the edge and not the center.
i have code using some trigonmetry that works for squares, but as soon as the shape becomes a rectangle (i.e. width and height are not the same), the drawing breaks.
can i detect where a line intersects with a shape through clipping and use that point location to draw my arrow head? if so, how?

Here's one way to do this using the rule of similar triangles.
import java.awt.*;
import java.awt.geom.*;
import javax.swing.*;
public class Pointers extends JPanel {
    Rectangle r1 = new Rectangle(40,60,100,150);
    Rectangle r2 = new Rectangle(200,250,175,100);
    int barb = 20;
    double phi = Math.toRadians(20);
    protected void paintComponent(Graphics g) {
        super.paintComponent(g);
        Graphics2D g2 = (Graphics2D)g;
        g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                            RenderingHints.VALUE_ANTIALIAS_ON);
        g2.setPaint(Color.blue);
        g2.draw(r1);
        g2.draw(r2);
        g2.setPaint(Color.red);
        g2.draw(getPath());
    private GeneralPath getPath() {
        double x1 = r1.getCenterX();
        double y1 = r1.getCenterY();
        double x2 = r2.getCenterX();
        double y2 = r2.getCenterY();
        double theta = Math.atan2(y2 - y1, x2 - x1);
        Point2D.Double p1 = getPoint(theta, r1);
        Point2D.Double p2 = getPoint(theta+Math.PI, r2);
        GeneralPath path = new GeneralPath(new Line2D.Float(p1, p2));
        // Add an arrow head at p2.
        double x = p2.x + barb*Math.cos(theta+Math.PI-phi);
        double y = p2.y + barb*Math.sin(theta+Math.PI-phi);
        path.moveTo((float)x, (float)y);
        path.lineTo((float)p2.x, (float)p2.y);
        x = p2.x + barb*Math.cos(theta+Math.PI+phi);
        y = p2.y + barb*Math.sin(theta+Math.PI+phi);
        path.lineTo((float)x, (float)y);
        return path;
    private Point2D.Double getPoint(double theta, Rectangle r) {
        double cx = r.getCenterX();
        double cy = r.getCenterY();
        double w = r.width/2;
        double h = r.height/2;
        double d = Point2D.distance(cx, cy, cx+w, cy+h);
        double x = cx + d*Math.cos(theta);
        double y = cy + d*Math.sin(theta);
        Point2D.Double p = new Point2D.Double();
        int outcode = r.outcode(x, y);
        switch(outcode) {
            case Rectangle.OUT_TOP:
                p.x = cx - h*((x-cx)/(y-cy));
                p.y = cy - h;
                break;
            case Rectangle.OUT_LEFT:
                p.x = cx - w;
                p.y = cy - w*((y-cy)/(x-cx));
                break;
            case Rectangle.OUT_BOTTOM:
                p.x = cx + h*((x-cx)/(y-cy));
                p.y = cy + h;
                break;
            case Rectangle.OUT_RIGHT:
                p.x = cx + w;
                p.y = cy + w*((y-cy)/(x-cx));
                break;
            default:
                System.out.println("Non-cardinal outcode: " + outcode);
        return p;
    public static void main(String[] args) {
        JFrame f = new JFrame();
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        f.getContentPane().add(new Pointers());
        f.setSize(400,400);
        f.setLocation(200,200);
        f.setVisible(true);
}

Similar Messages

  • Suggestion to draw a line between two points...

    I have the XYZ position of 2 points, I would like to draw a line between those points. I have tried with a cylinder and it did not work as I expect...I guess a better method exist in Java3D... Do you have any suggestions??
    thanks
    Pete

    try the LineArray class.

  • How draw a line between two buttons?

    Hi.
    I want to make two movable buttons connected  with a line. When changing position of any button you'll change look of  the line of course.  I know how to draw a line but after MOUSE_DOWN, and  I don't know how to remove an old one line, and how make this line to  be shown all the time?
    My code
    btn2.addEventListener(MouseEvent.MOUSE_DOWN,
    mouseDownHandler3);
    btn2.addEventListener(MouseEvent.MOUSE_UP, mouseUpHandler3);
    btn3.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler3);
    btn3.addEventListener(MouseEvent.MOUSE_UP, mouseUpHandler3);
    // Define a mouse down handler (user is dragging)
    function mouseDownHandler3(evt:MouseEvent):void {
       var object = evt.target;
       // we should limit dragging to the area inside the canvas
       object.startDrag();
    function mouseUpHandler3(evt:MouseEvent):void {
       var obj = evt.target;
          obj.stopDrag();
          //spisujemy x,y
          var x2Pos:Number = btn2.x;
          var y2Pos:Number = btn2.y;
          var x3Pos:Number = btn3.x;
          var y3Pos:Number = btn3.y;
          trace (x3Pos);
          trace (y3Pos);
          var roundObject:Shape = new Shape();
          roundObject.graphics.lineStyle(2, 0x990000, .75);
          roundObject.graphics.moveTo(x2Pos, y2Pos);
          roundObject.graphics.lineTo(x3Pos, y3Pos);
          this.addChild(roundObject);
          //this.removeChild(this.getChildAt(this.numChildren -1));
    Source .FLA: http://www.mediafire.com/?y2tyzz4zxun

    Here's a solution that you can adapt for two or more buttons....
    var btns:Array = [btn2, btn3]; //instances on stage
    //set btn handlers
    function setBtns():void {
          for(var i=0; i<btns.length; i++) {
                btns[i].buttonMode = true;
                btns[i].addEventListener(MouseEvent.MOUSE_DOWN, grab);
                btns[i].addEventListener(MouseEvent.MOUSE_UP, drop);
    setBtns();
    //draws lines btween all btns while a drag is occurring
    function drawLines(e:Event=null):void {
          graphics.clear();
          graphics.lineStyle(2, 0xFF0000);
          graphics.moveTo(btns[0].x+(btns[0].width/2), btns[0].y+(btns[0].height/2));
          for(var j=btns.length-1; j>=1; j--) {
                graphics.lineTo(btns[j].x+(btns[j].width/2), btns[j].y+(btns[j].height/2));
    //handlers
    function grab(event:MouseEvent):void {
          event.target.startDrag();
          addEventListener(Event.ENTER_FRAME, drawLines);
    function drop(event:MouseEvent):void {
        event.target.stopDrag();
        removeEventListener(Event.ENTER_FRAME, drawLines);
    drawLines();

  • Trendline between two points

    hi
    i have a code like this
    trendline.jsp
    <%@page import="ChartDirector.*" %>
    <%
    // The data for the line chart
    double[] data = {50, 55, 47, 34, 42, 49, 63, 62, 73, 59, 56, 50, 64, 60, 67, 67, 58,
        59, 73, 77, 84, 82, 80, 91};
    // The labels for the line chart
    String[] labels = {"Jan 2000", "Feb 2000", "Mar 2000", "Apr 2000", "May 2000",
        "Jun 2000", "Jul 2000", "Aug 2000", "Sep 2000", "Oct 2000", "Nov 2000",
        "Dec 2000", "Jan 2001", "Feb 2001", "Mar 2001", "Apr 2001", "May 2001",
        "Jun 2001", "Jul 2001", "Aug 2001", "Sep 2001", "Oct 2001", "Nov 2001",
        "Dec 2001"};
    // Create a XYChart object of size 500 x 320 pixels, with a pale purpule (0xffccff)
    // background, a black border, and 1 pixel 3D border effect.
    XYChart c = new XYChart(500, 320, 0xffccff, 0x000000, 1);
    // Set the plotarea at (55, 45) and of size 420 x 210 pixels, with white background.
    // Turn on both horizontal and vertical grid lines with light grey color (0xc0c0c0)
    c.setPlotArea(55, 45, 420, 210, 0xffffff, -1, -1, 0xc0c0c0, -1);
    // Add a legend box at (55, 25) (top of the chart) with horizontal layout. Use 8 pts
    // Arial font. Set the background and border color to Transparent.
    c.addLegend(55, 22, false, "", 8).setBackground(Chart.Transparent);
    // Add a title box to the chart using 13 pts Times Bold Italic font. The text is
    // white (0xffffff) on a purple (0x800080) background, with a 1 pixel 3D border.
    c.addTitle("Long Term Server Load", "Times New Roman Bold Italic", 13, 0xffffff
        ).setBackground(0x800080, -1, 1);
    // Add a title to the y axis
    c.yAxis().setTitle("MBytes");
    // Set the labels on the x axis. Rotate the font by 90 degrees.
    c.xAxis().setLabels(labels).setFontAngle(90);
    // Add a line layer to the chart
    LineLayer lineLayer = c.addLineLayer();
    // Add the data to the line layer using light brown color (0xcc9966) with a 7 pixel
    // square symbol
    lineLayer.addDataSet(data, 0xcc9966, "Server Utilization").setDataSymbol(
        Chart.SquareSymbol, 7);
    // Set the line width to 2 pixels
    lineLayer.setLineWidth(2);
    // tool tip for the line layer
    lineLayer.setHTMLImageMap("", "", "title='{xLabel}: {value} MBytes'");
    // Add a trend line layer using the same data with a dark green (0x008000) color. Set
    // the line width to 2 pixels
    TrendLayer trendLayer = c.addTrendLayer(data, 0x008000, "Trend Line");
    trendLayer.setLineWidth(2);
    // tool tip for the trend layer
    trendLayer.setHTMLImageMap("", "", "title='Change rate: {slope|2} MBytes/per month'");
    // output the chart
    String chart1URL = c.makeSession(request, "chart1");
    // include tool tip for the chart
    String imageMap1 = c.getHTMLImageMap("");
    %>
    <html>
    <body topmargin="5" leftmargin="5" rightmargin="0">
    <div style="font-size:18pt; font-family:verdana; font-weight:bold">
        Trend Line Chart
    </div>
    <img src='<%=response.encodeURL("getchart.jsp?"+chart1URL)%>'
        usemap="#map1" border="0">
    <map name="map1"><%=imageMap1%></map>
    </body>
    </html>getchart.jsp
    <%@page import="ChartDirector.*" %><%
    try
         out.clear();
         GetSessionImage.getImage(request, response);
         if (Math.max(1, 2) == 2) return;
    catch (IllegalStateException e)
         response.sendRedirect(response.encodeRedirectURL(
              "getchart.chart?" + request.getQueryString()));
         return;
    %>i have to draw a trendline chart...
    i searched for examples...
    i come across this. above example..
    actually my querry is i ve to draw the trendline between two points.
    in between "data" ( 63 to 70) only...
    is there any way to do this
    please help me
    thank you in advance.

    hi
    i tried this..
    <%@page import="ChartDirector.*" %>
    <%
    // The data for the line chart
    double[] dataX0 = {6};
    double[] dataY0 = {63};
    String[] labels2 = {"Jul 2000", "Aug 2000", "Sep 2000", "Oct 2000", "Nov 2000",
        "Dec 2000"};
    // The lengths (radii) and directions (angles) of the vectors
    double[] dataR = {3};
    double[] dataA = {60};
    // The labels for the line chart
    String[] labels = {"Jan 2000", "Feb 2000", "Mar 2000", "Apr 2000", "May 2000",
        "Jun 2000", "Jul 2000", "Aug 2000", "Sep 2000", "Oct 2000", "Nov 2000",
        "Dec 2000", "Jan 2001", "Feb 2001", "Mar 2001", "Apr 2001", "May 2001",
        "Jun 2001", "Jul 2001", "Aug 2001", "Sep 2001", "Oct 2001", "Nov 2001",
        "Dec 2001"};
    // Create a XYChart object of size 500 x 320 pixels, with a pale purpule (0xffccff)
    // background, a black border, and 1 pixel 3D border effect.
    XYChart c = new XYChart(500, 320, 0xffccff, 0x000000, 1);
    // Set the plotarea at (55, 45) and of size 420 x 210 pixels, with white background.
    // Turn on both horizontal and vertical grid lines with light grey color (0xc0c0c0)
    c.setPlotArea(55, 45, 420, 210, 0xffffff, -1, -1, 0xc0c0c0, -1);
    // Add a legend box at (55, 25) (top of the chart) with horizontal layout. Use 8 pts
    // Arial font. Set the background and border color to Transparent.
    c.addLegend(55, 22, false, "", 8).setBackground(Chart.Transparent);
    // Add a title box to the chart using 13 pts Times Bold Italic font. The text is
    // white (0xffffff) on a purple (0x800080) background, with a 1 pixel 3D border.
    c.addTitle("Long Term Server Load", "Times New Roman Bold Italic", 13, 0xffffff
        ).setBackground(0x800080, -1, 1);
    // Add a title to the y axis
    c.yAxis().setTitle("MBytes");
    // Set the labels on the x axis. Rotate the font by 90 degrees.
    c.xAxis().setLabels(labels).setFontAngle(90);
    c.addVectorLayer(dataX0, dataY0, dataR, dataA,1, 0x0000cc
        ).setArrowHead(11);
    /*LineLayer layer1 = c.addLineLayer();
    //LineLayer layer1 = c.addLineLayer(dataY0, 0xff3333, "Compound AAA");
    layer1.addDataSet(dataY0, 0xff3333, "Close Loop Line").setDataSymbol( Chart.LeftTriangleSymbol, 10);
    layer1.setXData(dataX0);
    layer1.setLineWidth(2);*/
    // Add a line layer to the chart
    LineLayer lineLayer = c.addLineLayer2();
    // Add the data to the line layer using light brown color (0xcc9966) with a 7 pixel
    // square symbol
    lineLayer.addDataSet(data, 0xcc9966, "Server Utilization").setDataSymbol(
        Chart.SquareSymbol, 7);
    lineLayer.setLineWidth(2);
    // output the chart
    String chart1URL = c.makeSession(request, "chart1");
    // include tool tip for the chart
    //String imageMap1 = c.getHTMLImageMap("");
    %>
    <html>
    <body topmargin="5" leftmargin="5" rightmargin="0">
    <div style="font-size:18pt; font-family:verdana; font-weight:bold">
        Trend Line Chart
    </div>
    <img src='<%=response.encodeURL("getchart.jsp?"+chart1URL)%>'
        usemap="#map1" border="0">
    </body>
    </html>how can i set the angle of direction for the arrow..
    suppose
    i wanna draw an arrow b/w these points
    y=50 to y=37
    how can give the length and direction here
    c.addVectorLayer(dataX0, dataY0, dataR, dataA,1, 0x0000cc
        ).setArrowHead(11);i mean in daraR and dataA...
    please help me
    thank you in advance

  • Arc between two points

    Hey Everybody!!
    I want to draw an arc between two points.. i can't seem to be able to figure the math but i'm sure this is fairly simple and somebody has done this before...
    Thanks in advance.

    that's correct...you need three points to define an arc..
    the reason i said two points is that i'm doing a diagram editor and i have to let the user connect pairs of objects using arrow, arcs, lines etc...
    any help is greatly appreciated...

  • How to draw a line on ADF page between two nodes  for mapping.

    Hi everyone,
    Does anyone have a solution that how can I wiring two points by drawing a line on ADF pages.
    My scenario is user want to do a mapping between two xml files. We will build an ADF faces page. This page have two parts, left part contains one tree(base on the source xml), right part is the destination tree(target xml). User can drag an node from left and drop to right. Meantime, a line will be created to connect two node, it would be perfect that when user scroll down the page, or extend the tree node, the line between source and target will be remain connection two node.
    Does anyone have a solution for this, thanks in advance.
    Hongfu.

    so you want to do something like. xsl mapper in soa
    http://www.haertfelder.com/images/pSoaBPEL3.png
    i can think of using javascript.. not sure... neeed extra programming..

  • How to draw a line(shortest distance)  between two ellipse using SWING

    how to draw a line(should be shortest distance) between two ellipse using SWING
    any help will be appreciated
    regards

    import java.awt.*;
    import java.awt.event.*;
    import java.awt.geom.*;
    import javax.swing.*;
    import javax.swing.event.MouseInputAdapter;
    public class ELine extends JPanel {
        Ellipse2D.Double red = new Ellipse2D.Double(150,110,75,165);
        Ellipse2D.Double blue = new Ellipse2D.Double(150,50,100,50);
        Line2D.Double line = new Line2D.Double();
        protected void paintComponent(Graphics g) {
            super.paintComponent(g);
            Graphics2D g2 = (Graphics2D)g;
            g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                                RenderingHints.VALUE_ANTIALIAS_ON);
            g2.setPaint(Color.green.darker());
            g2.draw(line);
            g2.setPaint(Color.blue);
            g2.draw(blue);
            g2.setPaint(Color.red);
            g2.draw(red);
        private void connect() {
            double flatness = 0.01;
            PathIterator pit = blue.getPathIterator(null, flatness);
            double[] coords = new double[2];
            double x1 = 0, y1 = 0, x2 = 0, y2 = 0;
            double min = Double.MAX_VALUE;
            while(!pit.isDone()) {
                int type = pit.currentSegment(coords);
                switch(type) {
                    case PathIterator.SEG_MOVETO:
                    case PathIterator.SEG_LINETO:
                        Point2D.Double p = getClosestPoint(coords[0], coords[1]);
                        double dist = p.distance(coords[0], coords[1]);
                        if(dist < min) {
                            min = dist;
                            x1 = coords[0];
                            y1 = coords[1];
                            x2 = p.x;
                            y2 = p.y;
                        break;
                    case PathIterator.SEG_CLOSE:
                        break;
                    default:
                        System.out.println("blue type: " + type);
                pit.next();
            line.setLine(x1, y1, x2, y2);
        private Point2D.Double getClosestPoint(double x, double y) {
            double flatness = 0.01;
            PathIterator pit = red.getPathIterator(null, flatness);
            double[] coords = new double[2];
            Point2D.Double p = new Point2D.Double();
            double min = Double.MAX_VALUE;
            while(!pit.isDone()) {
                int type = pit.currentSegment(coords);
                switch(type) {
                    case PathIterator.SEG_MOVETO:
                    case PathIterator.SEG_LINETO:
                        double dist = Point2D.distance(x, y, coords[0], coords[1]);
                        if(dist < min) {
                            min = dist;
                            p.setLocation(coords[0], coords[1]);
                        break;
                    case PathIterator.SEG_CLOSE:
                        break;
                    default:
                        System.out.println("red type: " + type);
                pit.next();
            return p;
        public static void main(String[] args) {
            final ELine test = new ELine();
            test.addMouseListener(test.mia);
            test.addMouseMotionListener(test.mia);
            JFrame f = new JFrame();
            f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            f.add(test);
            f.setSize(400,400);
            f.setLocation(200,200);
            f.setVisible(true);
            EventQueue.invokeLater(new Runnable() {
                public void run() {
                    Graphics g = test.getGraphics();
                    g.drawString("drag me", 175, 80);
                    g.dispose();
        private MouseInputAdapter mia = new MouseInputAdapter() {
            Point2D.Double offset = new Point2D.Double();
            boolean dragging = false;
            public void mousePressed(MouseEvent e) {
                Point p = e.getPoint();
                if(blue.contains(p)) {
                    offset.x = p.x - blue.x;
                    offset.y = p.y - blue.y;
                    dragging = true;
            public void mouseReleased(MouseEvent e) {
                dragging = false;
            public void mouseDragged(MouseEvent e) {
                if(dragging) {
                    double x = e.getX() - offset.x;
                    double y = e.getY() - offset.y;
                    blue.setFrame(x, y, blue.width, blue.height);
                    connect();
                    repaint();
    }

  • How can I insert a vertical line  between two underlined unfilled with text lines.  I am trying to construct an invoice and I need a break.  If I try any of the shapes or inset functions it eliminates my underlined lines and shifts the whole document.

    I am trying to construct an invoice.  How can I install a vertical line between two or more underlined lines to create a break.  I have tried the insert, shapes and nothing works.  If I try any of the functions the whole document shifts to the right and I loose some of the lines.  Is there a work around, or is I work not able to do what I want?   
    Thanks
    Armand

    It sounds as though you may have "Object Causes Wrap" activated for the Line Shape. This will push other content away.
    See the Wrap Inspector.
    Jerry

  • Distance between two objects

    Hi folks,
    Who knows how I can discover the distance between two selected objects without using neither guides nor grids?
    Thanks.

    How do imagine this would working without using guides or grids? The way I normally do it is:
    1. Drag out a guide to point A
    2. Drag out a guide to point B
    3. Hold shift and put the mouse cursoe between the two -- it shows you the distance
    You could also use the measuring tool (click and hold the rectangle tool in the tool pallette.)
    Or even just draw a rectangle and look at the width in the property panel. That's a fast and easy method I use sometimes.
    Aaron Beall
    http://fireworks.abeall.com

  • How to drag and drop button between two toolbar?

    Hi,everybody :)
    i hava a problem :
    if i have two toolbar in a frame , and there are some button in each, how can i use dnd package to drag and drop button between two toolbar,such as drag one button in a toolbar to the other toolbar ,i write some sample code ,but find some difficult to finish
    can anyone give me some example code?
    Thanks!

    hi:)
    i have done it ,but there is another problem ,after i finish drag the button and drop it into the toolbar,if my mouse across the dragged button ,it will change the color ,can i setup any mathod to disappear the side_effect?
    thank u
    click open to show the other frame
    and the code is as follows:
    import java.awt.*;
    import java.awt.datatransfer.*;
    import java.awt.dnd.*;
    import java.awt.event.*;
    import java.io.*;
    import javax.swing.*;
    public class buttondrag implements DragGestureListener, DragSourceListener,
    DropTargetListener, Transferable{
    static JFrame source = new JFrame("Source Frame");
    static JFrame target = new JFrame("Target Frame");
    static final DataFlavor[] supportedFlavors = { null };
    static {
    try {
         supportedFlavors[0] = new DataFlavor(DataFlavor.javaJVMLocalObjectMimeType);
    catch (Exception ex) {
         ex.printStackTrace();
    } Object object; // Transferable methods.
    public Object getTransferData(DataFlavor flavor) {
    if (flavor.isMimeTypeEqual(DataFlavor.javaJVMLocalObjectMimeType)) return object;
    else{
    return null;
    public DataFlavor[] getTransferDataFlavors() {
         return supportedFlavors;
    public boolean isDataFlavorSupported(DataFlavor flavor) {
         return flavor.isMimeTypeEqual(DataFlavor.javaJVMLocalObjectMimeType);
    } // DragGestureListener method.
    public void dragGestureRecognized(DragGestureEvent ev) {
    ev.startDrag(null, this, this);
    } // DragSourceListener methods.
    public void dragDropEnd(DragSourceDropEvent ev) { }
    public void dragEnter(DragSourceDragEvent ev) { }
    public void dragExit(DragSourceEvent ev) { }
    public void dragOver(DragSourceDragEvent ev) {
         object = ev.getSource();
    public void dropActionChanged(DragSourceDragEvent ev) { } // DropTargetListener methods.
    public void dragEnter(DropTargetDragEvent ev) { }
    public void dragExit(DropTargetEvent ev) { }
    public void dragOver(DropTargetDragEvent ev) { dropTargetDrag(ev); }
    public void dropActionChanged(DropTargetDragEvent ev) { dropTargetDrag(ev); }
    void dropTargetDrag(DropTargetDragEvent ev) { ev.acceptDrag(ev.getDropAction()); }
    public void drop(DropTargetDropEvent ev) {
         ev.acceptDrop(ev.getDropAction());
         try {
         Object target = ev.getSource();
         Object source = ev.getTransferable().getTransferData(supportedFlavors[0]);
         Component component = ((DragSourceContext) source).getComponent();
         Container oldContainer = component.getParent();
         Container container = (Container) ((DropTarget) target).getComponent();
         container.add(component);
         oldContainer.validate();
         oldContainer.repaint();
         container.validate();
         container.repaint();
         catch (Exception ex) {
              ex.printStackTrace();
              ev.dropComplete(true);
    public static void main(String[] arg) {
    JButton button = new JButton("Drag this button");
    JToolBar sbar = new JToolBar();
    JToolBar dbar = new JToolBar();
    JButton open_button = new JButton("Open");
    source.getContentPane().setLayout(null);
    source.setSize(new Dimension(400, 300));
    sbar.add(button);
    sbar.setBounds(new Rectangle(0, 0, 400, 31));
    sbar.add(open_button);
    open_button.addMouseListener(new MouseAdapter() {
    public void mouseClicked(MouseEvent e) {
    target.setVisible(true);
    source.getContentPane() .add(sbar);
    target.getContentPane().setLayout(null);
    target.setSize(new Dimension(400, 300));
    target.getContentPane().add(dbar);
    dbar.setBounds(new Rectangle(0, 0, 400, 31));
    dbar.add(new JButton("button1"));
    buttondrag dndListener = new buttondrag();
    DragSource dragSource = new DragSource();
    DropTarget dropTarget1 = new DropTarget(sbar, DnDConstants.ACTION_MOVE, dndListener);
    DropTarget dropTarget2 = new DropTarget(dbar, DnDConstants.ACTION_MOVE, dndListener);
    DragGestureRecognizer dragRecognizer1 = dragSource.createDefaultDragGestureRecognizer(button, DnDConstants.ACTION_MOVE, dndListener);
    source.setBounds(0, 200, 200, 200);
    target.setVisible(false);
    target.setBounds(220, 200, 200, 200);
    source.show();
    }

  • Polar equation of a line between two points

    I am trying to make a method to output the points (in polar coordinates (r, theta)) along a line between two given polar coordinates.
    This will mimick the path of an object traveling across a radar screen.
    Is this possible?

    Java does not plot in polar coordiantes, you'll have to convert to rectangular to get a plot. If you're just doing a sweep on a screen, then it's fairly simple to do:
    r is the radius of your screen,
    (0,0) is your Origin translated as (Xmax/2, Ymax/2)
    when you draw the line you just start at your Origin and get your end values as
    X1=X0+r*cos(Theta) and
    Y1=Y0+r*sin(Theta),
    I've not seen, nor do I think there is any other support to do what you want--you have to convert to (x,y) coordinate system.
    This will leave a ragged edge so make a border around your screen.
    import java.awt.Color;
    import java.awt.Dimension;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.awt.Graphics;
    import java.awt.Graphics2D;
    import java.awt.image.BufferedImage;
    import java.awt.Point;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import javax.swing.Timer;
    public class JRadar{
      public JRadar(){
        JPanel p = new MyJPanel();
        JFrame f = new JFrame("ForumJunk: JRadar");
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        f.add(p);
        f.pack();
        f.setVisible(true);
      public static void main(String[] args){
        new JRadar();
      class MyJPanel extends JPanel implements ActionListener{
        Timer t = new Timer(10, this);
        Dimension d = new Dimension(512, 512);
        BufferedImage bi = new BufferedImage(d.width, d.height, BufferedImage.TYPE_INT_RGB);
        Graphics2D g = bi.createGraphics();
        double theta = 0;
        int r = d.width/2 - 16;
        Point origin = new Point(d.width/2, d.height/2);
        public MyJPanel(){
          g.setColor(Color.RED);
          this.setPreferredSize(d);
          t.start();
        public void actionPerformed(ActionEvent e){
          g.clearRect(0, 0, d.width, d.height);
          g.drawOval(16, 16, 480, 480);
          g.drawLine(origin.x, origin.y, (int)(origin.x+r*Math.cos(theta)), (int)(origin.y+r*Math.sin(theta)));
          theta += 0.01;
          if(theta>=Math.PI*2) theta = 0.0;
          repaint();
        public void paintComponent(Graphics g){
          super.paintComponent(g);
          g.drawImage(bi, 0, 0, this);
    }Edited by: morgalr on Mar 3, 2010 4:59 PM: code example added

  • Inserting video between two clips

    Hi does anyone know how to insert video between two clips without erasing some of the two clips. I want to insert and have the other clips just make room for the new clip, extending the timeline the necessary amount. I thought you could just drag it in but it keeps erasing the existing footage in the timeline. Any advise would be awesome

    Make sure the playhead is parked between two clips, and drag the clip from the browser/viewer to the canvas, dropping it on the "insert" box in the edit overlay. Or you could drag the clip from the viewer/browser to the timeline but make sure the arrow that appears is facing to the right, not down.

  • How to draw an arrow  ?

    hi.
    i want to create an application which permet to create graphs.
    to create edges i use :
    var arc = Path {
    strokeWidth: bind width
    elements: [
    MoveTo {
    x: bind debutX
    y: bind debutY
    QuadCurveTo {
    x: bind finX
    y: bind finY
    controlX: bind pointX
    controlY: bind pointY
    and i wan't to draw an arrow on this arc so i add a Polygon
    var triangle = Polygon {
    points: bind [pointX - 10,pointY - 10,pointX,pointY,pointX + 10,pointY - 10]
    fill: Color.AQUA
    strokeWidth: 5
    you can see that i use the same pointX and pointY .....this is what i obtain
    http://www.servimg.com/image_preview.php?i=65&u=11565828][img]http://i86.servimg.com/u/f86/11/56/58/28/fleche10.jpg
    the arrow is not on the arc !!
    thanks
    Edited by: ksergses on Apr 20, 2009 5:31 AM

    >
    Indeed, on B&eacute;zier curves, control points are outside of the curve, in general.
    Note that I see the triangle pointing precisely on the curve on the given screenshot... It depends on what you call arrow tip! ;-)no it's not the right tip pointing on the curve.....in general the arrow is far from the curve
    Back to your problem, either you compute the middle point with the B&eacute;zier formulasthat's what i am thinking about...but even if i do that ...the problem that the curves position can change ..and it's form also...and calculating the middle point is not the solution in this case .......
    i am searching for a tool that bind two objects ( arrow and curve) and after that we can manipulate them like one element ( like flash) !
    I am disappointed that JavaFX does not provide a tool to draw arrows easily.
    thanks
    Edited by: ksergses on Apr 21, 2009 5:03 AM

  • Can I jump between two presentations without exiting presentation mode?

    is it possible to quickly jump between two separate presentations without having to go out of presentation / play mode ??

    OUCH! Random access in Keynote is difficult. It is essentially a linear presentation format. However, IF you want to do this only once, there might be a workaround:
    Create a slide in presentation A that has a black rectangle that covers the entire slide; it could be any slide number, but most likely should be the last slide in the presentation to make it easier to find in a hurry. Make this your Hyperlink to presentation B. (see previous response)
    Then, while showing presentation A, when you want to go to B, press the = (equal) key to display the slide selector on the preview display monitor; select the Hyperlink slide and go to it; click on the slide and that will trigger the hyperlink to B. By the way, it will look better if the first slide in presentation B also is all black to mask the transition.
    The problem, however, will be returning to A where you left-off. There is another workaround for this. First create another black slide and make this #1 in presentation A. Then create a hyperlink at the end of B that will take you back to A, slide 1. Again, use the slide selector to take you back to the slide where you left-off previously. (When you first leave presentation A, be sure you know which slide number you left, so that you can return there (or the next slide) when you come back.)
    Yes, it is cumbersome. Yes, it will not be seamless: there will be some pauses while you are selecting the proper slides and making the transitions. Yes, it should be easier. And, yes, it will be even more difficult to do this more than once (if you can do it at all) in a presentation.
    Good luck.

  • Permissions problem copying files between two Macs

    I've run into a strange problem when trying to copy files between two networked Macs. Some background facts: We have two Macs at home each with three accounts. Two of the accounts are regular user accounts (my wife's and mine, call them "K" and "B" for short) and the third is an administrator account (we'll call it "A"). I have a .Mac account, which I use to sync between the two Macs. The other accounts do not. The user accounts B & K were initially set up on the second Mac via the Migration Assistant, copying over files and settings. The administrator account was not.
    The problem I've run into is that if I am logged in as either user B or K on the local Mac, connect to the remote Mac as the corresponding user, and try to copy files into a folder owned by that same user on the remote Mac, I get a series of three dialog boxes with error messages:
    1) "You may need to enter the name and password for an administrator on this computer to change the item named ..." (stop/continue)
    2) "The item ... contains one or more items you do not have permission to read. Do you want to copy the items you are allowed to read?" (stop/continue)
    3) "The operation cannot be completed because you do not have sufficient privileges for some of the items."
    If I go all the way through this hitting continue / OK on each, what shows up on the remote computer at the end is an empty file with the name and filetype of the local file that I was trying to copy, but of zero length.
    This only happens when I'm copying from (local.B -> remote.B) or (local.K -> remote.K). It does not happen if I try any of the other pairwise combinations (assuming that I've authenticated properly): (local.B -> remote.K or remote.A), (local.K -> remote.B or remote.A), (local.A -> remote.B, remote.K or remote.A). It happens regardless of which Mac is local and which is remote.
    I'm a little baffled. I've tried to search for this on Apple Discussions and other forums, but either haven't been using the right keywords or am coming up blank.
    Anyone have any suggestions?
    Thanks,
    Bob

    borbye is correct that this will remedy the problem but there is a way to do it and have your account work. after changing the user UID and group UID to 501 you will have to restart. then when you log on your home folder will still be your default but you will not have any access. Since you are still an admin you can change that. right click on the home folder and select get info click arrow for sharing and permissions. Your old UID account will show up as _unknown delete this user and add your user to it giving yourself read and write privilege. click on the cog on the bottom and select apply to enclosed items. A warning box will appear stating that this process cannot be undone do you wish to proceed? click yes and a status bar will come up. once the bar is gone the process is complete. since you didn't have access to your home folder you cannot save your settings, this is a good thing since your account will not look remotely the same as yours most likely. all you have to do now is logout and then back in. Your account will look as it did before the change with all the access settings and so forth as before the change... minus some permissions due to the overwrite. It's a minor repair to the permissions to some shares considering you will be able to now move files to and these shares without the permissions alert that only creates a 4kb file instead of the real thing. Takes 5 minutes at most. Have fun.

Maybe you are looking for

  • How to create a private forum in Office 365 SharePoint for customers?

    Hi,  I am implementing a SharePoint Office 365 solution for a client but one of their requirements is sharing regularly updated info with only 20 customers. The idea is to share info with just the customers in a private forum basically to receive fee

  • Error in Query designer

    Hi Experts, I have created char variable for ZOSO_SAELCHDT When i am saving the query it is giving this error. *Errors: VariableZOSO_SAELCHDT(0002tndgsjdthu4buc8gmtnw) does not exist or is incorrectly used 00O2TNDGSJDTHU4C2GCAV0PF0* Can anybody plz h

  • Burning a slideshow to DVD

    I have spent a total of 4 hours over 2 days at the Genius Bar in the Apple Store and NO ONE can figure out my problem! Maybe someone out there is able to help me?? I have a slideshow I created in iPhoto that I need to put on a DVD. Everytime I finish

  • Reporting Financials - Pre requisites

    Hi Experts! I was looking at 'SAP Help' for Reporting Financials (EhP3). http://help.sap.com/saphelp_nw04s/helpdata/EN/30/44593167d447198995bed770d70ddf/frameset.htm It says that for using these (0FI_GL_40....) new data sources the pre requisites are

  • What exactly does Arch do with existing partitions at install time?

    Hi there, I would like ton install linux on a computer which has already ubuntu and Vista. I'd like to keep ubuntu and erase vista altogether. My partitions look like this: /dev/sda1               1           5       40131   de  Dell Utility /dev/sda