Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 22 of 22

Thread: drawing a several lines from d bottom right corner of a JFrame

  1. #1
    Junior Member
    Join Date
    Dec 2013
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default drawing a several lines from d bottom right corner of a JFrame

    I want to draw several line from the lower right corner of my JFrame so it resembles a hand fan I know I have 2 use a for loop but I'm having problems with the co-ordinates I have set variable width=width() and variable height=height(). Of d JFrame I knw dat d co-ordinates of d upper left is (0,0,width,height) while dat of the top right is (0,height,width,0 )(bcos I tried it) but I can't jst seem 2 get dat of d bottom right corner I sincerely hope I'm not rambling and someone actually understands me thanks in advance.


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,165
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: drawing a several lines from d bottom right corner of a JFrame

    What is this d you keep talking about?

    Please use standard English when posting questions so that everyone will be able to understand them.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Dec 2013
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: drawing a several lines from d bottom right corner of a JFrame

    I'm so sorry hope this is better

    --- Update ---

    I want to draw several lines from the lower right corner of my JFrame so it resembles a hand fan I know I have to use a for loop but I'm having problems with the co-ordinates I have set variable width=width() and variable height=height() Of the JFrame I know that the co-ordinates of the upper left is (0,0,width,height) while that of the top right is (0,height,width,0 )(because I tried it) but I can't just seem to get that of d bottom right corner I sincerely hope I'm not rambling and someone actually understands me thanks in advance

    --- Update ---

    I want to draw several lines from the lower right corner of my JFrame so it resembles a hand fan I know I have to use a for loop but I'm having problems with the co-ordinates I have set variable width=width() and variable height=height() Of the JFrame I know that the co-ordinates of the upper left is (0,0,width,height) while that of the top right is (0,height,width,0 )(because I tried it) but I can't just seem to get that of the bottom right corner I sincerely hope I'm not rambling and someone actually understands me thanks in advance

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,165
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: drawing a several lines from d bottom right corner of a JFrame

    I can't just seem to get that of d bottom right corner
    What are the values that you get and what are the values that you expect?
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    Dec 2013
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: drawing a several lines from d bottom right corner of a JFrame

    My width and height have values of 250 and 300 respectively but if I use co-ordinates (0,0,width,height). It draws the fan from the top left and if I use co-ordinate (0,height,width,0 ) it draws the fan from the top right I would like to know what co-ordinates to use to enable it draw the fan from the bottom right corner

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,165
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: drawing a several lines from d bottom right corner of a JFrame

    Post the statements that you are using to draw the lines.
    What args to the draw method specify the starting point and what specify the ending point for the line?
    If you don't understand my answer, don't ignore it, ask a question.

  7. #7
    Junior Member
    Join Date
    Dec 2013
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: drawing a several lines from d bottom right corner of a JFrame

    import java.awt.Graphics; import javax.swing.JPanel; Public class Draing extends JPanel{ //Here is my method paint component wit some comments. Public void paintComponent(Graphics g){ super.paintComponent(g); int width =get Width; int height =get Height(); //This. code has its starting point at the top left corner of the JPanel and its end point is the bottom right corner. for(int j = 0; j< 10; j++) { //co-ordinates of the line that is their starting and end point respectively. g.drawLine(0,0,width,height); height-=25; width+=50; }//end for loop }//end method paintComponent }//end class Drawing. // the problem I have is I want the starting point to be at the bottom right corner and the end point to be at the top left corner

  8. #8
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,165
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: drawing a several lines from d bottom right corner of a JFrame

    I want the starting point to be at the bottom right corner and the end point to be at the top left corner
    What are the x,y values for the bottom right corner?

    The posted code is completely unreadable the way it is posted.
    When posting code Please wrap your code with code tags:
    [code=java]
    YOUR CODE HERE
    [/code]
    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

  9. #9
    Junior Member
    Join Date
    Dec 2013
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: drawing a several lines from d bottom right corner of a JFrame

                                                                           import java.awt.Graphics;                                         public class Drawing extends JPanel{                                                                                                public void paintComponent(Graphics g){                                                                                      super.paintComponent(g);                                                  int width=getWidth():                                               int height=getHeight();                                               for(int j=0;j<10;j++){                                                                                                                                                  g.drawLine(0,0,width,height);//starting and end point of the line respectively                             height-=25;                                                                      width +=5o; 
     
    }                                                                                                                                                                                   }                                                                                                }


    --- Update ---

    Sorry for being such a disturbance but I've wrapped my code with the code tags but its not displaying can someone please help me

  10. #10
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,165
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: drawing a several lines from d bottom right corner of a JFrame

    Something is wrong with the code that is posted. It has lost all of its formatting.

    You didn't answer this question:
    What are the x,y values for the bottom right corner?
    If you don't understand my answer, don't ignore it, ask a question.

  11. #11
    Junior Member
    Join Date
    Dec 2013
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: drawing a several lines from d bottom right corner of a JFrame

    I've tried using this but it keeps on drawing. From the top left.
                                       super.paintComponent(g);                                                        int width =getWidth().                                             int height=getHeight.                            g.drawLine(width,height,0,0) ;

  12. #12
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,165
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: drawing a several lines from d bottom right corner of a JFrame

    Something is wrong with the formatting of the code in the post.

    Can you answer this simple question:
    What are the x,y values for the bottom right corner?

    it keeps on drawing. From the top left.
    How can you tell that?
    If you don't understand my answer, don't ignore it, ask a question.

  13. #13
    Junior Member
    Join Date
    Dec 2013
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: drawing a several lines from d bottom right corner of a JFrame

    I can tell because I have run the code and it is working x =0,y=0

  14. #14
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,165
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: drawing a several lines from d bottom right corner of a JFrame

    Strange that you think the x,y values for the lower right corner is 0,0.
    That looks like the coordinates for the upper left corner.
    If you don't understand my answer, don't ignore it, ask a question.

  15. #15
    Junior Member
    Join Date
    Dec 2013
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: drawing a several lines from d bottom right corner of a JFrame

    If that's for the upper left what do I use for the bottom right

  16. #16
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,165
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: drawing a several lines from d bottom right corner of a JFrame

    To see what the coordinates are for any of the corners of a rectangle, draw a rectangle on a piece of paper and label each of the corners with their coordinates.
    Java has the top side be at y=0 and the left side be x=0. The y values increase going down and the x values increase going to the right.

    Can you make a list of the 4 corners and give the x,y values for each. Here is the first of 4:
    Upperleft: 0,0

    What are the coordinates for the other 3?
    If you don't understand my answer, don't ignore it, ask a question.

  17. #17
    Junior Member
    Join Date
    Dec 2013
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: drawing a several lines from d bottom right corner of a JFrame

    Upper right :width,0 bottom left:0,-height, bottom right:width,-height

  18. #18
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,165
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: drawing a several lines from d bottom right corner of a JFrame

    Upper right :width,0
    bottom left:0,height,
    bottom right:width,height
    There are no negative values:
    Java has the top side be at y=0 and the left side be x=0. The y values increase going down and the x values increase going to the right.
    If you don't understand my answer, don't ignore it, ask a question.

  19. #19
    Junior Member
    Join Date
    Dec 2013
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: drawing a several lines from d bottom right corner of a JFrame

    But even when I specify the starting point as width,height and the end point as 0,0 it still ends up drawing the lines from the top left

    --- Update ---

    /*I used*/ g.drawLine(width,height,0,0); width-=15; height+=20;

    --- Update ---

    And I placed it all in a for loop

    --- Update ---

    But it ends up drawing the lines from the top left corner

  20. #20
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,165
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: drawing a several lines from d bottom right corner of a JFrame

    If you want all the lines to start at the point at the location x=width and y=height, why is the code changing the values of width and height?
    They shouldn't be changed if you want all the lines to start at the same location.
    The code should change the location of the second point (the one that starts at 0,0)
    If you don't understand my answer, don't ignore it, ask a question.

  21. #21
    Junior Member
    Join Date
    Dec 2013
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: drawing a several lines from d bottom right corner of a JFrame

    Thanks norm you're a life saver I've finally gotten it I simply created variables and set them to 0 and used them in my code thank u very much once again I really appreciate the time and effort

  22. #22
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,165
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: drawing a several lines from d bottom right corner of a JFrame

    That sounds like the solution. Glad you got it working.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Drawing Lines Loop
    By 02s2k in forum Loops & Control Statements
    Replies: 1
    Last Post: May 3rd, 2013, 11:17 AM
  2. [SOLVED] Drawing lines using angles in Java HELP
    By shadysback in forum What's Wrong With My Code?
    Replies: 7
    Last Post: October 8th, 2012, 02:10 PM
  3. Replies: 1
    Last Post: September 23rd, 2012, 01:02 PM
  4. Drawing Rectangles and Lines
    By andreizeus in forum AWT / Java Swing
    Replies: 21
    Last Post: October 28th, 2010, 12:59 PM
  5. Drawing circles with smoother lines?
    By tabutcher in forum Java Theory & Questions
    Replies: 4
    Last Post: April 18th, 2010, 10:12 AM