Results 1 to 1 of 1
  1. #1
    koddy is offline Member
    Join Date
    Apr 2010
    Posts
    20
    Rep Power
    0

    Default drawing three (or more) lines with input of coordinat

    Hi,

    I have problem with how to make 3 lines with an input of coordinat.
    Ive made the GUI and the ActionListener for that. Ive already made the array too for that.
    But the line wont draw :(

    The line should be from (x1,y1) - (x2,y2) ; (x3,y3) - (x4,y4) ; (x5,y5) - (x6,y6)

    Here is the code of my ActionsListener:
    Java Code:
        private void DrawButtonActionPerformed(java.awt.event.ActionEvent evt) {                                           
            try
            {
                Point [] points = new Point[6];
                points [0] = new Point();
                points [0].x = Integer.parseInt(inputx1.getText());
                points [0].y = Integer.parseInt(inputy1.getText());
                points [1] = new Point();
                points [1].x = Integer.parseInt(inputx2.getText());
                points [1].y = Integer.parseInt(inputy2.getText());
    
                points [2] = new Point();
                points [2].x = Integer.parseInt(inputx3.getText());
                points [2].y = Integer.parseInt(inputy3.getText());
                points [3] = new Point();
                points [3].x = Integer.parseInt(inputx4.getText());
                points [3].x = Integer.parseInt(inputy4.getText());
    
                points [4] = new Point();
                points [4].x = Integer.parseInt(inputx5.getText());
                points [4].y = Integer.parseInt(inputy5.getText());
                points [5] = new Point();
                points [5].x = Integer.parseInt(inputx6.getText());
                points [5].y = Integer.parseInt(inputy6.getText());
    
                JDesktopPane dreilinear = new DreiLinear(new Point(points[0].x, points[0].y), new Point(points[1].x, points[1].y));
                JDesktopPane dreilinear2 = new DreiLinear(new Point(points[2].x, points[2].y), new Point(points[3].x, points[3].y));
                JDesktopPane dreilinear3 = new DreiLinear(new Point(points[4].x, points[4].y), new Point(points[5].x, points[5].y));
                dreilinear.setBounds(0, 0, DesktopPanel.getWidth(), DesktopPanel.getHeight());
                DesktopPanel.setOpaque(true);
                DesktopPanel.add(dreilinear);
                DesktopPanel.add(dreilinear2);
                DesktopPanel.add(dreilinear3);
                dreilinear.repaint();
                dreilinear2.repaint();
                dreilinear3.repaint();
            }
            catch (NumberFormatException e1)
            {
            }
        }
    and here is the class of DreiLinear, which I think its should be changed
    Java Code:
    public class DreiLinear extends JDesktopPane {
    
        private Point startCoordinats ;
        private Point endCoordinats ;
    
        Line2D.Double[] lines;
        int sequenceNumber = 0;
        int lineNumber = 0;
    
        public DreiLinear(Point startCoordinats, Point endCoordinats) {
            super();
            this.startCoordinats = startCoordinats;
            this.endCoordinats = endCoordinats;
    
            lines = new Line2D.Double[3];
            lines[0] = new Line2D.Double(startCoordinats.x, startCoordinats.y, endCoordinats.x, endCoordinats.y);
            lines[1] = new Line2D.Double(startCoordinats.x, startCoordinats.y, endCoordinats.x, endCoordinats.y);
            lines[2] = new Line2D.Double(startCoordinats.x, startCoordinats.y, endCoordinats.x, endCoordinats.y);
    
            setVisible(true);
        }
    
        @Override
        public void paint(Graphics g)
        {
            Graphics2D g2d = (Graphics2D)g;
            super.paint(g2d);
            for(int i = 0; i < sequenceNumber; i++) {
            g2d.draw(lines[i]);}}}
    Can anyone help me, how can I changed it, so that I can draw 3 lines at once?

    Thank you very much in advance.
    Last edited by koddy; 04-20-2010 at 09:57 AM.

Similar Threads

  1. Input technique for unknown lines of input
    By ducreative in forum New To Java
    Replies: 16
    Last Post: 09-23-2009, 10:26 AM
  2. Count lines cointaining "word" in input file
    By gwithey in forum New To Java
    Replies: 5
    Last Post: 04-02-2009, 06:23 AM
  3. Getting User Input to Drawing Shapes
    By mlfatty in forum AWT / Swing
    Replies: 2
    Last Post: 03-04-2009, 07:36 AM
  4. Replies: 0
    Last Post: 07-02-2008, 08:50 PM
  5. Demonstration of drawing lines in SWT
    By Java Tip in forum SWT Tips
    Replies: 0
    Last Post: 06-28-2008, 10:27 PM

Tags for this Thread

Posting Permissions

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