/* * DFS_GUI.java * * Created on December 2, 2008, 1:38 PM */ package graph; /** * * @author suchenek */ //Copyright Dr. Marek A. Suchenek, 2005, 2006, 2007, 2008 public class DFS_GUI extends javax.swing.JApplet { /** Initializes the applet DFS_GUI */ public void init() { try { java.awt.EventQueue.invokeAndWait(new Runnable() { public void run() { initComponents(); } }); } catch (Exception ex) { ex.printStackTrace(); } } /** This method is called from within the init() method to * initialize the form. * WARNING: Do NOT modify this code. The content of this method is * always regenerated by the Form Editor. */ // //GEN-BEGIN:initComponents private void initComponents() { jButton1 = new javax.swing.JButton(); jButton2 = new javax.swing.JButton(); jButton3 = new javax.swing.JButton(); jButton1.setText("Clear"); jButton1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton1ActionPerformed(evt); } }); jButton2.setText("DFS"); jButton2.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton2ActionPerformed(evt); } }); jButton3.setText("Acyclic?"); jButton3.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton3ActionPerformed(evt); } }); org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) .add(layout.createSequentialGroup() .add(27, 27, 27) .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) .add(jButton3) .add(jButton2) .add(jButton1)) .addContainerGap(39, Short.MAX_VALUE)) ); layout.setVerticalGroup( layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) .add(layout.createSequentialGroup() .add(24, 24, 24) .add(jButton1) .add(19, 19, 19) .add(jButton2) .add(14, 14, 14) .add(jButton3) .addContainerGap(53, Short.MAX_VALUE)) ); }// //GEN-END:initComponents private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed // TODO add your handling code here: if (G.cycle) { System.out.println("A cycle"); return; } int v = G.FirstUnvisited(); while (v != -1) { DiGraph.CycleDFS(G, v); v = G.NextUnvisited(v); } if (!G.cycle) System.out.println("No cycle"); }//GEN-LAST:event_jButton3ActionPerformed private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed // TODO add your handling code here: // for (int i = 0; i < G.Size(); i++) DiGraph.DFS(G, 0); // DiGraph.DFS(G, G.FirstUnvisited()); }//GEN-LAST:event_jButton2ActionPerformed private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed // TODO add your handling code here: G = new DiGraph(10); G.InsertEdge(0,1); // G.InsertEdge(1, 0); G.InsertEdge(0,2); // G.InsertEdge(1,2); //loop - makes (4,1) a back edge // G.InsertEdge(1,0); //back edge G.InsertEdge(1,3); G.InsertEdge(2,3); G.InsertEdge(2,4); G.InsertEdge(4,1); G.InsertEdge(4,0); //back edge G.InsertEdge(4,3); G.InsertEdge(6,5); G.InsertEdge(6,8); G.InsertEdge(8,9); G.InsertEdge(9,6); G.InsertEdge(5,7); G.InsertEdge(7,6); G.Dump(); }//GEN-LAST:event_jButton1ActionPerformed // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton jButton1; private javax.swing.JButton jButton2; private javax.swing.JButton jButton3; // End of variables declaration//GEN-END:variables DiGraph G; }