How to draw only straight line instead of angled one??

Dear friends,
I saw a very good code posted by guru here(I think is camickr),
But I tried to change it and I hope to draw only straight line instead of angled one, can you help how to do it??
Thanks so much.
import java.util.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
public class DrawingArea extends JPanel
     Vector angledLines;
     Point startPoint = null;
     Point endPoint = null;
     Graphics g;
     public DrawingArea()
          angledLines = new Vector();
          setPreferredSize(new Dimension(500,500));
          MyMouseListener ml = new MyMouseListener();
          addMouseListener(ml);
          addMouseMotionListener(ml);
          setBackground(Color.white);
     public void paintComponent(Graphics g)
          // automatically called when repaint
          super.paintComponent(g);
          g.setColor(Color.black);
          AngledLine line;
          if (startPoint != null && endPoint != null)
               // draw the current dragged line
               g.drawLine(startPoint.x, startPoint.y, endPoint.x,endPoint.y);
          for (Enumeration e = angledLines.elements(); e.hasMoreElements();)
               // draw all the angled lines
               line = (AngledLine)e.nextElement();
               g.drawPolyline(line.xPoints, line.yPoints, line.n);
     class MyMouseListener extends MouseInputAdapter
          public void mousePressed(MouseEvent e)
               if (SwingUtilities.isLeftMouseButton(e))
                    startPoint = e.getPoint();
          public void mouseReleased(MouseEvent e)
               if (SwingUtilities.isLeftMouseButton(e))
                    if (startPoint != null)
                         AngledLine line = new AngledLine(startPoint, e.getPoint(), true);
                         angledLines.add(line);
                         startPoint = null;
                         repaint();
          public void mouseDragged(MouseEvent e)
               if (SwingUtilities.isLeftMouseButton(e))
                    if (startPoint != null)
                         endPoint = e.getPoint();
                         repaint();
          public void mouseClicked( MouseEvent e )
               if (g == null)
                    g = getGraphics();
               g.drawRect(10,10,20,20);
     class AngledLine
          // inner class for angled lines
          public int[] xPoints, yPoints;
          public int n = 3;
          public AngledLine(Point startPoint, Point endPoint, boolean left)
               xPoints = new int[n];
               yPoints = new int[n];
               xPoints[0] = startPoint.x;
               xPoints[2] = endPoint.x;
               yPoints[0] = startPoint.y;
               yPoints[2] = endPoint.y;
               if (left)
                    xPoints[1] = startPoint.x;
                    yPoints[1] = endPoint.y;
               else
                    xPoints[1] = endPoint.x;
                    yPoints[1] = startPoint.y;
     public static void main(String[] args)
          JFrame frame = new JFrame("Test angled lines");
          frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
          DrawingArea d = new DrawingArea();
          frame.getContentPane().add( d );
          frame.pack();
          frame.setVisible(true);
}

Change the AngledLine class to store two points instead of 3 points (I would rename the class to be StraightLine). The code is much simpler because you just store the starting and ending points and you don't need to calculate the middle point.

Similar Messages

  • How can i draw a straight line with a brush?

    i know the pencil tool can draw a straight line with anchor points. is there a setting for the pencil tool that can mimic a 30 point brush, low hardness (faded side to side) at about an 80 degree angle or is there a way to make a straight line with the brush tool using a mouse?
    i know this image is a bit blurry. what i want to do is replace the 2 white angled lines with the 30 point brush effect 230 pixels wide. the project on the left of the pic is a 2ft by 4ft canvas. any ideas? please help.

    Hello Mike, I wonder if you can help, no one else can. I asked this question on the forum in August Brush line fades on start with anchor points
    Only on Photoshop CC does this happen, drawing a diagonal line with shift key, instead of line starting dark & then fading out, it does the reverse, starts on nothing & then darkens towards anchor point. I am on trial versions & can't purchase until this is cleared up.

  • How to draw a straight  dotted line on Bar chart at 70%?

    Hi
    Could you please let me know how to draw a straight dotted line on BAR CHART at 70%?
    Thank you

    Hi,
    This may vary depending on what version of crystal you are using.
    Right click on the graph & go to 'chart options' & choose 'Grids'
    In the grids pane go to the grids tab.  From there check the 'draw custom line at' and specify where you want to draw the custom line.
    Once the line is drawn highlight the line, right click and go to 'chart options' & 'selected item'.
    select what format you want the line to look like (choose the dashed one).
    good luck!

  • Drawing a straight line

    Hello,
    I haven't been able to draw a straight line in a JPanel as a separator. I mean, I have several other componentes in the JPanel and I would like to use straight lines as separators between some of the componentes. Besides drawing the line, how could I set its length?
    Thank you,
    Alfredo

    You could use a JPanel and set its border to a LineBorder (or whatever border you desire. Then set the preferred size of the panel and all that gets painted is the border.

  • Is there a way to draw a straight line from one point to another?

    Is there a way of drawing a straight line from one point to another please?

    Yes.  First click on this icon:
    Now select the line drawing icon:
    Now press a shift key and drag your mouse on the image to draw a straight line.
    These instructions are for Windows system so you need to adapt the method for Macs.  I can't afford to by an Apple Mac!!!!!
    Good luck.

  • Drawing a straight line over a video

    Is it possible to draw a straight line over a video in CS6 and also to watch the video frame by frame to take exact timings?

    Hi Jeff,
    Back again! i have managed to put the line over the video and can have it on there as long or as short time as i wish, but it appears to be moving with the video and i need it to stay at a certain point and the video to carry on playing. Basically im trying to mark a point on a race track where the horse in the lead gets to, then i need the line to stay there for when the last horse comes to the line, with the lead horse moving on past. Currently the line doesnt stay on a specific point it on the video and go out of shot when the video moves, it appears to be moving with the video. I know the overlay is a static image but is there a way of making it look like it stays in a specific place on the video?
    Hope this makes sense!
    Thanks Kat

  • Any way to simulate a user drawing a straight line in Captivate 6?

    I'm trying to create a software simulation. While most of the user interaction with the software involves just clicking buttons and entering values in various fields, there is one place where the user has to draw a straight line from one point to another. Basically, I would like Captivate to dynamically display the line as it is being drawn (i.e., getting longer as the mouse moves away from the starting point).
    Is there any way this can be done in Captivate? Thanks.

    Hello,
    Welccome to Adobe Forums.
    Software Simulation (Automatic Recording) create slides on event based (Keyboard button press or Click on Mouse)
    When you draw something it will not show you the drawing at the time of recording, for that you can use Video Demo
    Thanks,
    Vikram

  • Can a Lightroom adjustment brush draw a straight line by clicking the start and stop points?

    Can a Lightroom adjustment brush draw a straight line by clicking the start and stop points?

    studioMac wrote:
    I'm trying to selectively adust areas of an image in Lighroom. eg: a window frame in an architectural photo, and so being able to make straight lines with the adjustment brush would be very useful.
    I agree it would be useful. It's something that's been asked for. The best thing is to keep requesting at the Lightroom feature request forum

  • How to display only Day value instead of DATE in Bex Report

    Hi Experts,
    We have a Month to date Report, in this report we need to display only day value instead of DATE value,
    Like
    if Date is 14.05.2010 we need to show only  14
    Regards,
    Chandra

    Hi ,
    Thanks for Quick Response
    we does have the option to create the char(calday or ...) value variable replacement with char (calday or ...) info object, we can  replace with Report r variable value only not with info object.
    i hope we can replace the with info object only with formula variable with replacement.
    My BEx Report is Designed like
    Columns
    0Calday
    Rows
    Plant
    Keyfigures
    Actual
    Plan
    Report output Looks like month to date
    0CALDAY            01.06.2010   02.06.2010  03.06.2010
    P1  ACTUAL            10                     8                    4
    P1  PLAN                 15                     6                    2
    P2  ACTUAL              5                   10                     7
    P2  PLAN                  4                      8                    3
    Report should be
    0CALDAY            1    2     3
    P1  ACTUAL      10     8      4
    P1  PLAN           15     6     2
    P2  ACTUAL        5    10    7
    P2  PLAN            4      8     3
    please let me know how can i achive this
    Regards
    Chandra

  • How to make a straight line of points in a curve in CS6

    In PSCS5 and earlier, I used to be able to make a straight line of points in a curve by placing 9 points on the straight line curve.  I did this by drawing a small straight line at the bottom of the curve using the pencil tool and then clicking the curve point icon.
    I can't seem to do this with CS6.  Any thoughts?
    Thanks,
    Matthew Kraus

    Did you not ask a similar question a while ago?
    http://forums.adobe.com/message/4524084#4524084

  • How do  put a straight line over an "o" such as in Roti Grille?

    How do I get a straight line over a letter "o" such as in Roti Grille?
    Thanks

    PeterBreis0807 wrote:
    Unless there is something else out there that I am unaware of, Roti grill is an Indian cooking method.
    Why the accent is needed I don't know, I was unaware it used one.
    One more time you read wrongly
    The OP wrote "*Roti Grille*" not "*Roti Grill*"
    In French rôti requires the accent and grillé requires its accent too !
    Yvan KOENIG (VALLAURIS, France) jeudi 28 janvier 2010 22:31:33

  • How to Draw a vertical line in flex

    I was just wondering the simplest way to draw a vertical line , preferably dashed.

    You could always just use the graphics class of your chart component.  Just access its graphics object, set the line style/thickness, move to the start point, and line to the end point.  Something like this,
    this.graphics.lineStyle(1, 0x000000);
    this.graphics.moveTo(startX, startY);
    this.graphics.lineTo(endX, endY);

  • ALV:   how to display only subtotals lines in theoutput

    hi
    in the alv list output
    if we display subtotals based on 3 feilds out of 10
    we see subtotals (sum) based on the end of each field
    now i want to display only the lines which are displayed as subtotals in the output
    we have parameter
    totals_only(1) type c,        " show only totals
    in the structrure slis_layout_alv
    i have used it but i can see no change in the output

    hai
    data : GT_SORT             TYPE SLIS_T_SORTINFO_ALV,
    ABAP List Viewer
    CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
    EXPORTING
    I_INTERFACE_CHECK = ' '
    I_BYPASSING_BUFFER =
    I_BUFFER_ACTIVE = ' '
    I_CALLBACK_PROGRAM = G_REPID
    I_CALLBACK_PF_STATUS_SET = ' '
    I_CALLBACK_USER_COMMAND = ' '
    I_STRUCTURE_NAME = 'ITAB1'
    IS_LAYOUT =  GS_LAYOUT
    IT_FIELDCAT = GT_FIELDCAT[]
    IT_EXCLUDING =
    IT_SPECIAL_GROUPS =
      IT_SORT = GT_SORT[]
    IT_FILTER =
    IS_SEL_HIDE =
    I_DEFAULT = 'X'
    I_SAVE = ' '
    IS_VARIANT =
      IT_EVENTS = GT_EVENTS[]
    IT_EVENT_EXIT =
      IS_PRINT = GS_PRINT
    IS_REPREP_ID =
    I_SCREEN_START_COLUMN = 0
    I_SCREEN_START_LINE = 0
    I_SCREEN_END_COLUMN = 0
    I_SCREEN_END_LINE = 0
    IMPORTING
    E_EXIT_CAUSED_BY_CALLER =
    ES_EXIT_CAUSED_BY_USER =
    TABLES
    T_OUTTAB = ITAB1
    EXCEPTIONS
    PROGRAM_ERROR = 1
    OTHERS = 2.
    ENDFORM.
    DATA SORTING AND SUBTOTAL
    DATA: GS_SORT TYPE SLIS_SORTINFO_ALV.
    CLEAR GS_SORT.
    GS_SORT-FIELDNAME = 'FIELD1'.
    GS_SORT-SPOS      = 1.
    GS_SORT-UP        = 'X'.
    GS_SORT-SUBTOT    = 'X'.
    APPEND GS_SORT TO GT_SORT.
    CLEAR GS_SORT.
    GS_SORT-FIELDNAME = 'FIELD2'.
    GS_SORT-SPOS      = 2.
    GS_SORT-UP        = 'X'.
    *GS_SORT-SUBTOT    = 'X'.
    APPEND GS_SORT TO GT_SORT.
    ENDFORM.
    regard
    nawa

  • I want to know how to draw arrows & dashed lines in a picture control

    I have to draw arrows & dashed lines in a picture control. Just like we can do that in word or paint etc. I need to do the same using the mouse and drag the line/arrow till I realease the mouse. I am able to this for a normal line ( it works perfectly) but when I have to draw an arrow or a line I am stumped.

    Unfortunately, you have to code your own VIs to do these. It's not going to be too complicated if you manage the animation (while dragging the mouse) with a normal line and draw the dashed line/arrow at the end (when releasing the mouse button).
    In both cases, you'll know start/end line coordinates, thus having the line equation. For arrows, you need to calculate the angle in order to draw it properly.
    A simpler solution may be an activeX control with these features (Paint like) already integrated or to develop one in Visual Basic (at least it will be simpler to manage mouse events and drawing tasks).
    Let's hope somebody already did it and wants to share.

  • How to Stop Flickering Straight Line in CS4

    Hi all,
    For some reason CS4 cause all my straight lines to flicker. For example, if I have a video of a form with lots of straight lines on it, the rendered video of the form flickers like crazy?? I've tried to use the Anti-Flicker Filter but it made it worse?
    Please!

    More information is good
    Read Bill Hunt on a file type as WRAPPER http://forums.adobe.com/thread/440037?tstart=0
    What is a CODEC... a Primer http://forums.adobe.com/thread/546811?tstart=0
    What CODEC is INSIDE that file? http://forums.adobe.com/thread/440037?tstart=0
    For PC http://www.headbands.com/gspot/ or http://mediainfo.sourceforge.net/en
    For Mac http://mediainfo.massanti.com/

Maybe you are looking for

  • Greyed out superscript/subscript buttons

    Hi, When I'm using pages '11 I seem to have no control over when I can use the superscript/subscript icons on the toolbar.  Most of the time they are greyed out and I cannot use them at all.  Every now and again they are able to be used without me ch

  • Why does my iPad flicker then go black?

    When using my iPad all of a sudden it started flickering then the screen went black, after about 5-10 minutes I could use it again.

  • Organising code in Tomcat 5.5

    Hi, I'm new to JSP and not all the experienced at Java, but I have a few burning questions about jsp's and Tomcat. I'm developing on a Windows machine before I deploy my code to a Linux machine. I'm using Tomcat 5.5 and building projects using NetBea

  • How to transfer work items from one user's inbox to other user,s inbox(UWL)

    Hello All We need to transfer existing  but  open work items from one user's inbox to other user,s inbox(UWL) How to go about it? These are the items from backend  R3. Thanking you Rajendra

  • What order do I install airport, iLife, iWork, MS Office, & do Migration

    I have an iMac and just bought a MacBook Pro. I used the setup assistant on the MacBook Pro and created a user account, but did not setup anything else (internet, email, etc -- will do later). The user account name & password is different from my iMa