Hi guys, I am fairly new to JAVA and currently I am trying to do a couple of pre-set graphs. My first task is to create a graph of y=x^2.
The code below is what i have come up till now. I am sure that i need help in the for loop. I know that i need to do a for loop but im not understanding the process.
import java.awt.Graphics;
import java.awt.Graphics2D;
import javax.swing.JApplet;
public class graphic extends JApplet{
int noOfPoints = 100000;
int xPoints = 0;
int yPoints = 0;
public void paint(Graphics gr)
{
Graphics2D g = (Graphics2D)gr;
g.drawLine(575, 325, 825, 325); //drawing x-axis line
g.drawLine(700, 200, 700, 450); //drawing y-axis line
g.drawString("x-axis", 575, 335);//Label for x-axis
g.drawString("y-axis", 705, 200); //Label for y-axis
for (int i=-200;i<=500;i++) //Random figures please explian
{
xPoints = (int) (Math.pow(i,2));
yPoints = (int) (Math.pow(i+1,2));
g.drawLine(i,i,i,i); //Need help here as well
}
}
}
Thanks & Regards
almefab