I have a project i am struggling to get started with, the core of it is around drawing lines recursively perpendicular to one another. I am rather terrible at GUIs for a start. This is what i have so far but i don't know how to implement a recursive method that will draw the lines. This is what i have so far, just simple code to draw a line:
import java.awt.Graphics;
import javax.swing.JFrame;
import javax.swing.JPanel;
import java.awt.*;
import java.awt.geom.*;
public class Test extends JPanel{
private static String n;
private static String r;
public static void main(String[] args){
//n = args[0];
//r = args[1];
//System.out.println("THIS IS MY N: " + n);
//System.out.println("THIS IS MY R: " + r);
JFrame frame = new JFrame();
frame.setSize(400, 400);
frame.add(new Test());
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
public void paint(Graphics g){
int nn = 10;
for(int i = 0; i < nn; i++){
g.drawLine(400, 200, 50, 250);
}
}
}
So i was thinking along the lines of something like this to do the recursive drawing of the lines:
public static void drawLine(int x1, int y1, int x2, int y2){
if(count == 20){
//Stop or some other condition
}else{
g.drawLine(x1, y1, x2, y2);
drawLine(x1+5, y1+5, x2+10, y2+10);
}
}
I'm not sure how the paint method actually works into it. I don't think i fully grasp what the paint method is actually doing