Results 1 to 9 of 9
  1. #1
    sunolinu is offline Member
    Join Date
    Jan 2010
    Posts
    15
    Rep Power
    0

    Default hove i create arrow?

    what is command of creating arrow?
    thaks

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by sunolinu View Post
    what is command of creating arrow?
    thaks
    Please provide us with enough relevant information so that your question is in fact answerable. Much luck.

  3. #3
    sunolinu is offline Member
    Join Date
    Jan 2010
    Posts
    15
    Rep Power
    0

    Default

    i have some shape like fill circle i want when i click on shape one then clicking
    on another shape the arrow shape create between two shapes

    arrow = --------->

    i want just arrow command not mouse listner , ...

  4. #4
    DarrylBurke's Avatar
    DarrylBurke is online now Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,235
    Rep Power
    19

    Default

    And how do you plan to detect a mouse click without a mouse listener?

    db

  5. #5
    sunolinu is offline Member
    Join Date
    Jan 2010
    Posts
    15
    Rep Power
    0

    Default

    Quote Originally Posted by Darryl.Burke View Post
    And how do you plan to detect a mouse click without a mouse listener?

    db
    my means that i know how create mouse listener and ...
    but what cammand of arrow for example for fill rectangle
    the command is g.fillRect(200,200,10,10)

  6. #6
    hardwired's Avatar
    hardwired is offline Senior Member
    Join Date
    Jul 2007
    Posts
    1,576
    Rep Power
    9

    Default

    Java Code:
    import java.awt.*;
    import java.awt.geom.Path2D;
    import javax.swing.*;
    
    public class Test extends JPanel {
        protected void paintComponent(Graphics g) {
            super.paintComponent(g);
            Graphics2D g2 = (Graphics2D)g;
            g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                                RenderingHints.VALUE_ANTIALIAS_ON);
            Path2D.Double path = new Path2D.Double();
            path.moveTo(100, 125);
            path.lineTo(300, 125);
            path.lineTo(300, 100);
            path.lineTo(350, 155);
            path.lineTo(300, 210);
            path.lineTo(300, 185);
            path.lineTo(100, 185);
            path.lineTo(100, 125);
            g2.setPaint(Color.blue);
            g2.fill(path);
        }
    
        public static void main(String[] args) {
            JFrame f = new JFrame();
            f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            f.add(new Test());
            f.setSize(400,400);
            f.setLocation(200,200);
            f.setVisible(true);
        }
    }

  7. #7
    sunolinu is offline Member
    Join Date
    Jan 2010
    Posts
    15
    Rep Power
    0

    Default

    very excellent thanks you hardwired
    how i narrow it with like a line

  8. #8
    hardwired's Avatar
    hardwired is offline Senior Member
    Join Date
    Jul 2007
    Posts
    1,576
    Rep Power
    9

    Default

    Java Code:
    import java.awt.*;
    import java.awt.geom.*;
    import javax.swing.*;
    
    public class TrigArrow extends JPanel {
        Point p1 = new Point(100,100);
        Point p2 = new Point(300,300);
        double dia = 25.0;
        double barb = 15.0;
        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.red);
            g2.fill(new Ellipse2D.Double(p1.x-1.5, p1.y-1.5, 4, 4));
            g2.fill(new Ellipse2D.Double(p2.x-1.5, p2.y-1.5, 4, 4));
            g2.setPaint(Color.blue);
            g2.draw(new Ellipse2D.Double(p1.x-dia/2, p1.y-dia/2, dia, dia));
            g2.draw(new Ellipse2D.Double(p2.x-dia/2, p2.y-dia/2, dia, dia));
            double dy = p2.y - p1.y;
            double dx = p2.x - p1.x;
            double theta = Math.atan2(dy, dx);
            double x1 = p1.x + (dia/2)*Math.cos(theta);
            double y1 = p1.y + (dia/2)*Math.sin(theta);
            theta += Math.PI;
            double x2 = p2.x + (dia/2)*Math.cos(theta);
            double y2 = p2.y + (dia/2)*Math.sin(theta);
            g2.setPaint(Color.green.darker());
            g2.draw(new Line2D.Double(x1, y1, x2, y2));
            double x = x2 + barb*Math.cos(theta+phi);
            double y = y2 + barb*Math.sin(theta+phi);
            g2.draw(new Line2D.Double(x2, y2, x, y));
            x = x2 + barb*Math.cos(theta-phi);
            y = y2 + barb*Math.sin(theta-phi);
            g2.draw(new Line2D.Double(x2, y2, x, y));
        }
    
        public static void main(String[] args) {
            JFrame f = new JFrame();
            f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            f.add(new TrigArrow());
            f.setSize(400,400);
            f.setLocation(100,100);
            f.setVisible(true);
        }
    }

  9. #9
    sunolinu is offline Member
    Join Date
    Jan 2010
    Posts
    15
    Rep Power
    0

    Default

    very thank you , it is itself and excellent ------------> best thanks for all --------> i next add solved

    i have another question i want to create tape of turing machine graphically i should use what ?

    see here is question :
    how i can to create tape of turing machine graphically
    Last edited by sunolinu; 02-20-2010 at 01:22 AM.

Similar Threads

  1. Arrow Button Example
    By Java Tip in forum SWT Tips
    Replies: 0
    Last Post: 07-11-2008, 04:44 PM
  2. Replies: 0
    Last Post: 07-11-2008, 03:07 PM
  3. Replies: 1
    Last Post: 02-16-2008, 11:22 PM
  4. how to draw an arrow mark using java swing
    By sandhyau in forum AWT / Swing
    Replies: 5
    Last Post: 02-07-2008, 11:52 AM
  5. Draw an arrow
    By Albert in forum SWT / JFace
    Replies: 3
    Last Post: 02-01-2008, 08:11 AM

Posting Permissions

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