i started learning c++ but have switched to Java for the moment cos it seems a lot easier to get into.
Can someone please explain to me how this paintcomponent function runs without ever being called strictly in the main fuction???
package javaapplication3;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.geom.Line2D;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class JavaApplication3 extends JPanel{
public void paintComponent(Graphics g) {
super.paintComponent(g);
Graphics2D g2d = (Graphics2D) g;
g2d.setColor(Color.blue);
double y, x, z, q;
int amp = 30;
int amp2 = 50;
for(x = 0; x < 1000; x += .01){
q = amp * Math.sin(.05 * x);
z = amp2 * Math.sin(q + x);
g2d.draw(new Line2D.Double(x ,(z + 100) ,x ,(z + 100)));
}
}
public static void main(String[] args) {
JavaApplication3 points = new JavaApplication3();
JFrame frame = new JFrame("Sine");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.add(points);
frame.setSize(1000, 250);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
}