Results 1 to 2 of 2
  1. #1
    khiat is offline Member
    Join Date
    Dec 2010
    Posts
    17
    Rep Power
    0

    Red face graph continues to emerge each time the coordinates is calculated

    hello, please i need your help please help me

    I want the window remains open and the graph continues to emerge each time the coordinates is calculated the first step: the window opens and there's just ordinate and abscissa. the second stage: once the factorial function computes factorial (k = 2) then the window displays the graph (k = 1, fact (k = 1) = 1) (k = 2, fact (k = 2) = 2) (the line) (as it did the update to the window and it displays the line and the window remains open after the factorial function computes factorial (k = 3) while the window displays the graph (k = 2, fact (k = 2) = 2) (k = 3, fact (k = 3) = 6) (line) ex ..
    /*I do not want the loop
    you then you calculate the poster I want to draw each time for giving and its factorial k
    */


    import java.awt.*;
    import java.awt.font.*;
    import java.awt.geom.*;
    import javax.swing.*;

    public class GraphingData11 extends JPanel {
    final int PAD = 20;
    /*3 variables to draw the line
    (k = 1, fact (k = 1) = 1) (k = 2, fact (k = 2) = 2)*/


    static int multi=1;static int multi1;static int k;

    /*factorial function*/
    public static double factorial(int N){
    multi=1;
    for (int i = 1; i <= N; i++){multi = multi*i;}
    System.out.println(multi);
    return multi;}

    /*a function that calculates the factorial of k = 1 to 100, and I draw the graph
    for each k*/

    public static double FUNCTION(){
    int k=1;multi1=0;
    while (k<=100){factorial(k);

    /*can not with the method paintComponent (Graphics g)
    paintComponent (Graphics g) I want to call the paintComponent (Graphics g) each time with new cords (k = 1, fact (k = 1) = 1) (k = 2, fact (k = 2) = 2 ) fact (k = 1) is variable and MULTI1 fact (k = 2) is the multi-variable
    */

    // wait for a while and then compute factorial k(
    ////////////////////////////////////////////
    t0 = System.currentTimeMillis ();
    do {t1 = System.currentTimeMillis ();} while (t1 - t0 <10000);
    ///////////////////////////////////////



    multi1=multi;
    k=k+1;}
    return 0;}

    /*I do not want the loop
    you then you calculate the poster I want to draw each time for giving and its factorial k
    */
    //the function that draws the dots and lines
    protected void paintComponent1(Graphics g) {
    Graphics2D g2 = (Graphics2D)g;
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASIN G,RenderingHints.VALUE_ANTIALIAS_ON);
    int w = getWidth(); // Window Width
    // Window height
    int h = getHeight();

    // draw axis.
    g2.draw(new Line2D.Double(PAD, PAD, PAD, h-PAD));
    // draw horizontal axis.
    g2.draw(new Line2D.Double(PAD, h-PAD, w-PAD, h-PAD));
    // line color
    g2.setPaint(Color.red);
    // draw the line
    g2.draw(new Line2D.Double(PAD + (20*(k-1)),h - (PAD +multi1), PAD + (20*(k)), h - (PAD + multi)));
    // color dot
    g2.setPaint(Color.red);
    // draw point
    g2.fill(new Ellipse2D.Double(PAD +(20*(k-1)),h - (PAD + multi1),2,2));
    }

    public static void main(String[] args) {
    FUNCTION();
    JFrame f = new JFrame();
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.add(new GraphingData11());
    f.setSize(400,400);
    f.setLocation(200,200);
    f.setVisible(true);
    }
    }


    I give you another example as the task manager----->Performance
    you see the pattern I want my program to do exactly

    In fact I want the same result (a visual standpoint), but I used what has already been drawn before, just by adding new lines ...

    please i need your help ,please

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

Similar Threads

  1. Replies: 13
    Last Post: 02-01-2011, 02:34 AM
  2. Replies: 0
    Last Post: 12-19-2010, 02:50 PM
  3. real time graph plotting in swing
    By elsanthosh in forum AWT / Swing
    Replies: 1
    Last Post: 11-22-2010, 05:06 PM
  4. Replies: 5
    Last Post: 10-09-2010, 06:22 AM
  5. Replies: 5
    Last Post: 10-01-2010, 10:26 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
  •