/* * 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_BFS_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(); jButton4 = new javax.swing.JButton(); jButton5 = new javax.swing.JButton(); jButton6 = 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); } }); jButton4.setText("DFSnrec"); jButton4.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton4ActionPerformed(evt); } }); jButton5.setText("BFS"); jButton5.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton5ActionPerformed(evt); } }); jButton6.setText("DFSnrecRev"); jButton6.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton6ActionPerformed(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(jButton6) .add(jButton5) .add(jButton4) .add(jButton3) .add(jButton2) .add(jButton1)) .addContainerGap(56, 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(18, 18, 18) .add(jButton4) .add(30, 30, 30) .add(jButton6) .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 31, Short.MAX_VALUE) .add(jButton5) .add(18, 18, 18) .add(jButton3) .add(29, 29, 29)) ); }// //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 private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed // TODO add your handling code here: DiGraph.DFSnrec(G, 0); }//GEN-LAST:event_jButton4ActionPerformed private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton5ActionPerformed // TODO add your handling code here: DiGraph.BFS(G, 0); }//GEN-LAST:event_jButton5ActionPerformed private void jButton6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton6ActionPerformed // TODO add your handling code here: DiGraph.DFSnrecRev(G, 0); }//GEN-LAST:event_jButton6ActionPerformed // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton jButton1; private javax.swing.JButton jButton2; private javax.swing.JButton jButton3; private javax.swing.JButton jButton4; private javax.swing.JButton jButton5; private javax.swing.JButton jButton6; // End of variables declaration//GEN-END:variables DiGraph G; }