Page 3 of 3 FirstFirst 123
Results 41 to 48 of 48
  1. #41
    only1zster is offline Member
    Join Date
    Dec 2011
    Posts
    24
    Rep Power
    0

    Default Re: How do you graph a simple line with user inputed slope and intercept?

    I think I'm completely lost now. Correct me if I'm wrong.
    1) Java opens the graphAttempt and initializes the variables at the top.
    2) The main method then starts
    3) new graphAttempt starts and it goes to get the variables (calculateY for now) but doesn't do anything with those variables.
    4) JFrame then starts up and starts a new graphAttempt (which resets all the variables), but doesn't go through the calculateY.
    5) JFrame then sets the frame at 450,450, and location at 200,200, with the information drawn up in paintComponent(Graphics g)

    I'm guessing at this point. Do I create a method with the JFrame section in it, and call it in the main method graphAttempt? ie:
    grph.caluclateY();
    grph.'JFrame name'();

  2. #42
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,816
    Rep Power
    25

    Default Re: How do you graph a simple line with user inputed slope and intercept?

    your 5 steps look like a correct description of what the code is doing.
    What you need to do is replace the use of a new graphAttempt in step 4 with the use of the one created in step 3.
    Do not create a second new graphAttempt, use the one that was created earlier.

  3. #43
    only1zster is offline Member
    Join Date
    Dec 2011
    Posts
    24
    Rep Power
    0

    Default Re: How do you graph a simple line with user inputed slope and intercept?

    I changed it to :
    graphAttempt grph = new graphAttempt();
    //grph.getSlope();
    //grph.getIntercept();
    grph.calculateY();

    JFrame f = new JFrame();
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.add(grph);
    f.setSize(450,450);//sets the size of the window
    f.setLocation(200,200); //sets the location 200,200 of the window from the upper left corner of the screen
    f.setVisible(true);
    and it seems to work. I even adjusted some of the values to change the plotted line to see watch it change, and it did. Now, I think (famous last words?) that I just need to figure out how to do the math to correctly plot the line. Or is there something else that I need to do? (wouldn't doubt it for a second)

  4. #44
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,816
    Rep Power
    25

    Default Re: How do you graph a simple line with user inputed slope and intercept?

    f.add(grph);
    Yes, That uses the one object with the data in the GUI.
    Now to work out the math to get the line drawn where you want it.

  5. #45
    only1zster is offline Member
    Join Date
    Dec 2011
    Posts
    24
    Rep Power
    0

    Default Re: How do you graph a simple line with user inputed slope and intercept?

    Working with you on this has definately helped me understand what the program is doing. again, I really appreciate it.

  6. #46
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,816
    Rep Power
    25

    Default Re: How do you graph a simple line with user inputed slope and intercept?

    You're welcome.

  7. #47
    only1zster is offline Member
    Join Date
    Dec 2011
    Posts
    24
    Rep Power
    0

    Default Re: How do you graph a simple line with user inputed slope and intercept?

    given a slope of +1, and an intercept of +3, the correct graph would show a line from (-3,0) to (0,+3). the values for that in the graph that I drew up is (80,200) to (200,80).
    and it appears to graph backward or upside down. If I adjust y2, the front of the line slides left or right.

  8. #48
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,816
    Rep Power
    25

    Default Re: How do you graph a simple line with user inputed slope and intercept?

    Time for a piece of paper and a pencil.

Page 3 of 3 FirstFirst 123

Similar Threads

  1. How do i delete a section of a user inputed string that i input
    By DevenGosalia514 in forum New To Java
    Replies: 8
    Last Post: 03-18-2011, 05:02 AM
  2. Replies: 5
    Last Post: 10-01-2010, 10:26 PM
  3. help in line graph in jsp page
    By javastuden in forum JavaServer Pages (JSP) and JSTL
    Replies: 0
    Last Post: 02-15-2010, 05:20 AM
  4. Plotting a line graph
    By revilo in forum New To Java
    Replies: 1
    Last Post: 10-11-2009, 01:07 AM
  5. Averages of user inputed values (Need Help)
    By Zebra in forum New To Java
    Replies: 2
    Last Post: 04-16-2008, 02:51 PM

Posting Permissions

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