//******************************************************************** // The primary panel for the Graph program // Author: Zdravko Markov //******************************************************************** import java.util.ArrayList; import javax.swing.*; import java.awt.*; import java.awt.event.*; public class GraphPanel extends JPanel { private final int SIZE = 10; // radius of each node private Point point1 = null, point2 = null; private ArrayList nodeList; // Graph nodes private ArrayList edgeList; // Graph edges private int[][] a = new int[100][100]; // Graph adjacency matrix public GraphPanel() { nodeList = new ArrayList(); edgeList = new ArrayList(); GraphListener listener = new GraphListener(); addMouseListener (listener); addMouseMotionListener (listener); JButton print = new JButton("Print adjacency matrix"); print.addActionListener (new ButtonListener()); setBackground (Color.black); setPreferredSize (new Dimension(400, 300)); add(print); } // Draws the graph public void paintComponent (Graphics page) { super.paintComponent(page); // Draws the edge that is being dragged page.setColor (Color.green); if (point1 != null && point2 != null) { page.drawLine (point1.x, point1.y, point2.x, point2.y); page.fillOval (point2.x-3, point2.y-3, 6, 6); } // Draws the nodes for (int i=0; i"+k); a[j][k]=1; } } // Prints the graph adjacency matrix for (int i=0; i