I am working on a dependancy graph that consists of multiple nodes and multiple directed edges from one node to another in the graph.
I am trying to draw a visualation of the graph by adding n number of nodes as circles and edges between those nodes as a line.
I a using Graphics library of Java along with JPanel and Jframe.
This is currently the code I have made:
public class LoopUnrolling extends JPanel{
static int length = 5;
static String graph[][] = new String[length][length];
@Override
public void paintComponent(Graphics g){
super.paintComponent(g);
Random random = new Random();
int x1 = random.nextInt(500);
int y1 = random.nextInt(100);
int x2 = random.nextInt(500);
int y2 = random.nextInt(100);
g.setColor(Color.red);
g.drawOval(x1,y1,30,40);
g.drawOval(x2,y2,30,40);
g.drawLine(x1, y1, x2, y2);
}
public static void main(String[] args) {
LoopUnrolling paintObject = new LoopUnrolling();
JFrame jf = new JFrame();
jf.setTitle("Dependancy Graph");
jf.setSize(600,400);
jf.setVisible(true);
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jf.add(paintObject);
}
}
I was able to draw two circles and a line but the problem I am getting is connecting those two circles with an edge.
I have drawn each node at a random place on the canvas and want to add a Line between those two nodes. The line has Point1(x1,y1) and Point2(x2,y2). These points should be the points on two different Node's(Circles) outline