# he graph continues to emerge each time the coordinates is calculated

• 12-19-2010, 02:50 PM
khiat
he graph continues to emerge each time the coordinates is calculated
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 ..

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;static int multi1;static int k;

/*factorial function*/
public static double factorial(int N){for (int i = 1; i <= N; i++){multi = multi*i;}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
*/
multi1=multi;
k=k+1;}
return 0;}

//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.
// draw horizontal axis.
// 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);