<?xml version="1.0" encoding="ISO-8859-1"?>

<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/">
	<channel>
		<title>DevX.com Forums - Java</title>
		<link>http://forums.devx.com</link>
		<description>From language syntax to enterprise platform implementation
problems.</description>
		<language>en</language>
		<lastBuildDate>Sun, 22 Nov 2009 01:39:57 GMT</lastBuildDate>
		<generator>vBulletin</generator>
		<ttl>60</ttl>
		<image>
			<url>http://forums.devx.com/images/misc/rss.jpg</url>
			<title>DevX.com Forums - Java</title>
			<link>http://forums.devx.com</link>
		</image>
		<item>
			<title>Ford-Fulkerson Algorithm</title>
			<link>http://forums.devx.com/showthread.php?t=173421&amp;goto=newpost</link>
			<pubDate>Sat, 21 Nov 2009 21:36:47 GMT</pubDate>
			<description><![CDATA[I have a program that reads in a graph from a file and builds an adjacency list from it. The adjacency list consists of an ArrayList of FlowEdges. A flow edge is represented as source vertex, destination vertex, weight/capacity, and flow. The flow is initially 0. The adjacency list (network) is displayed, the adjacency list is reversed and displayed, the augmenting path from source to sink is diaplayed, and the modified network is diplayed. I have to write some methods but I'm not sure what each method is doing. Can someone please explain them to me and also explain the Ford-Fulkerson algorithm since I don't quite understand it.

Here are the methods I have to write:

Code:
---------
class FlowNetwork extends WeightedDigraph
{
    /**
     * Finds an augmenting path from the source to the sink and returns
     * it as a list (stack) of oriented edges. Returns null if there is no
     * augmenting path.
     * @param source
     * @param sink
     * @return
     */
    List<OrientedFlowEdge> getAugmentingPath(int source, int sink)
    {        
         throw new UnsupportedOperationException("Write this method.");
    }

    /**
     * This method is initially called with an augmenting path consisting
     * of just one forward edge emanating from the start vertex. The method
     * implements a backtracking dfs type search to extend the augmenting
     * path all the way to the source. If no augmenting path can be found the
     * method returns false with the stack of edges left in the same state
     * as at the time of the call. If an augmenting path is found, it is
     * stored in the stack of oriented flow edges augPath and the method
     * returns true.
     * @param augPath    
     * @param visited An array of boolean indicating which vertices have
     * already been visited in an attempt to find an augmenting path.
     * When the method backtracks, the visited vertices remain marked.
     * @param sink

     * @return true if an augmenting path is found, false otherwise.
     */
    boolean dfs(Stack<OrientedFlowEdge> augPath, boolean [] visited, int sink)
    {       
       throw new UnsupportedOperationException("Write this method.");
    }
    /**
     * returns the maximum additional flow that can be pushed through
     * an augmenting path
     * @param path
     * @return
     */
    int getIncrementalFlow(List<OrientedFlowEdge> path)
    {
       throw new UnsupportedOperationException("Write this method.");    
    }
    /**
     * Modify the flow in the network along the augmenting path
     * @param augPath
     * @return the incremental flow used that  pushed through the path
     */
    int augmentFlow(List<OrientedFlowEdge> augPath)
    {
            throw new UnsupportedOperationException("Write this method.");
    }
}
---------
So in the getAugmentingPath method do I call the dfs method to find a path from source to sink and if the dfs method returns true I add that path to the stack in getAugmentingPath?

Not sure how to do getIncrementalFlow and augmentalFlow methods.

In main if the total flow is initialized to 0 how would I find the total flow?

Please help. I really need to get this done but I just don't know how to do this. I don't want someone to do this for me. Just explain this to me. Thanks.]]></description>
			<content:encoded><![CDATA[<div>I have a program that reads in a graph from a file and builds an adjacency list from it. The adjacency list consists of an ArrayList of FlowEdges. A flow edge is represented as source vertex, destination vertex, weight/capacity, and flow. The flow is initially 0. The adjacency list (network) is displayed, the adjacency list is reversed and displayed, the augmenting path from source to sink is diaplayed, and the modified network is diplayed. I have to write some methods but I'm not sure what each method is doing. Can someone please explain them to me and also explain the Ford-Fulkerson algorithm since I don't quite understand it.<br />
<br />
Here are the methods I have to write:<br />
<div style="margin:20px; margin-top:5px">
	<div class="smallfont" style="margin-bottom:2px">Code:</div>
	<hr /><code style="margin:0px" dir="ltr" style="text-align:left">class FlowNetwork extends WeightedDigraph<br />
{<br />
&nbsp; &nbsp; /**<br />
&nbsp; &nbsp;  * Finds an augmenting path from the source to the sink and returns<br />
&nbsp; &nbsp;  * it as a list (stack) of oriented edges. Returns null if there is no<br />
&nbsp; &nbsp;  * augmenting path.<br />
&nbsp; &nbsp;  * @param source<br />
&nbsp; &nbsp;  * @param sink<br />
&nbsp; &nbsp;  * @return<br />
&nbsp; &nbsp;  */<br />
&nbsp; &nbsp; List&lt;OrientedFlowEdge&gt; getAugmentingPath(int source, int sink)<br />
&nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp;  throw new UnsupportedOperationException(&quot;Write this method.&quot;);<br />
&nbsp; &nbsp; }<br />
<br />
&nbsp; &nbsp; /**<br />
&nbsp; &nbsp;  * This method is initially called with an augmenting path consisting<br />
&nbsp; &nbsp;  * of just one forward edge emanating from the start vertex. The method<br />
&nbsp; &nbsp;  * implements a backtracking dfs type search to extend the augmenting<br />
&nbsp; &nbsp;  * path all the way to the source. If no augmenting path can be found the<br />
&nbsp; &nbsp;  * method returns false with the stack of edges left in the same state<br />
&nbsp; &nbsp;  * as at the time of the call. If an augmenting path is found, it is<br />
&nbsp; &nbsp;  * stored in the stack of oriented flow edges augPath and the method<br />
&nbsp; &nbsp;  * returns true.<br />
&nbsp; &nbsp;  * @param augPath&nbsp; &nbsp; <br />
&nbsp; &nbsp;  * @param visited An array of boolean indicating which vertices have<br />
&nbsp; &nbsp;  * already been visited in an attempt to find an augmenting path.<br />
&nbsp; &nbsp;  * When the method backtracks, the visited vertices remain marked.<br />
&nbsp; &nbsp;  * @param sink<br />
<br />
&nbsp; &nbsp;  * @return true if an augmenting path is found, false otherwise.<br />
&nbsp; &nbsp;  */<br />
&nbsp; &nbsp; boolean dfs(Stack&lt;OrientedFlowEdge&gt; augPath, boolean [] visited, int sink)<br />
&nbsp; &nbsp; {&nbsp; &nbsp; &nbsp;  <br />
&nbsp; &nbsp; &nbsp;  throw new UnsupportedOperationException(&quot;Write this method.&quot;);<br />
&nbsp; &nbsp; }<br />
&nbsp; &nbsp; /**<br />
&nbsp; &nbsp;  * returns the maximum additional flow that can be pushed through<br />
&nbsp; &nbsp;  * an augmenting path<br />
&nbsp; &nbsp;  * @param path<br />
&nbsp; &nbsp;  * @return<br />
&nbsp; &nbsp;  */<br />
&nbsp; &nbsp; int getIncrementalFlow(List&lt;OrientedFlowEdge&gt; path)<br />
&nbsp; &nbsp; {<br />
&nbsp; &nbsp; &nbsp;  throw new UnsupportedOperationException(&quot;Write this method.&quot;);&nbsp; &nbsp; <br />
&nbsp; &nbsp; }<br />
&nbsp; &nbsp; /**<br />
&nbsp; &nbsp;  * Modify the flow in the network along the augmenting path<br />
&nbsp; &nbsp;  * @param augPath<br />
&nbsp; &nbsp;  * @return the incremental flow used that&nbsp; pushed through the path<br />
&nbsp; &nbsp;  */<br />
&nbsp; &nbsp; int augmentFlow(List&lt;OrientedFlowEdge&gt; augPath)<br />
&nbsp; &nbsp; {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; throw new UnsupportedOperationException(&quot;Write this method.&quot;);<br />
&nbsp; &nbsp; }<br />
}</code><hr />
</div>So in the getAugmentingPath method do I call the dfs method to find a path from source to sink and if the dfs method returns true I add that path to the stack in getAugmentingPath?<br />
<br />
Not sure how to do getIncrementalFlow and augmentalFlow methods.<br />
<br />
In main if the total flow is initialized to 0 how would I find the total flow?<br />
<br />
Please help. I really need to get this done but I just don't know how to do this. I don't want someone to do this for me. Just explain this to me. Thanks.</div>

]]></content:encoded>
			<category domain="http://forums.devx.com/forumdisplay.php?f=104">Java</category>
			<dc:creator>justinsbabe5000</dc:creator>
			<guid isPermaLink="true">http://forums.devx.com/showthread.php?t=173421</guid>
		</item>
		<item>
			<title>Urgent! What is wrong with this program? Part 1</title>
			<link>http://forums.devx.com/showthread.php?t=173400&amp;goto=newpost</link>
			<pubDate>Wed, 18 Nov 2009 06:33:38 GMT</pubDate>
			<description><![CDATA[Please, i am writing a project on implementation of Rivest-Shamir-Adleman(RSA) algorithm on local area network(LAN).But the JAVA program i wrote refused to work. please, can anyone help me with this.The program is given below is only a part of the entire program due to space constraint. The remain program will be sent in the next post.Thanks

Code:
---------
  import java.awt.*;
   import java.awt.event.*;
   import javax.swing.*;
   import java.lang.*;
public class My_RSA extends JFrame {
               private Container  container;
               private JFrame iFrame,jFrame, kFrame;
               private GridBagLayout layout;
               private GridBagConstraints constraints;
               private JTextField nField, dField;
               private JTextArea messageArea, cypherArea, plainArea,keysArea;
               private  JScrollPane messagescroll, cypherScroll, plainScroll;
               private JButton readButton, sendButton, okButton, cancelButton;
               private JPanel jPanel, nPanel,dPanel, okPanel,myPanel, mePanel,
   statusPanel, progressPanel,cancelPanel;
               private JPanel boardPanel1, boardPanel2, cypherPanel,plainPanel, 
  messagePanel, readPanel, sendPanel;
               private JLabel emptyLabel, jLabel, nLabel, dLabel, dumLabel1, dumLabel2, 
   statusLabel;
               private  JLabel emptyLabel1,  emptyLabel2 , emptyLabel3, emptyLabel4;
               private  JPanel emptyPanel,  emptyPanel1, emptyPanel2, emptyPanel3,
    emptyPanel4;
                private String message = "", plaintext = "", cyphertext = "", publish = "";
                private long d, e, m, n, p, q;
                 private final JProgressBar  current = new JProgressBar(0, 100);
           
                     private  KeyGenerator gen;
                     private  Encryption enc;
                     private  Decryption dec;
                     private  Sending go;
  public My_RSA()
   {
                Super("RSA Encryption System");

                 Container = getContentPane();
                 layout = new GridBagLayout();
                 container.setLayout(layout);
                 constraints = new GridBagConstraints();
                 gen = new KeyGenerator();
                 kFrame = new JFrame("Sending...");
                 mePanel = new JPanel();
                 mePanel.setLayout(layout);
                 progressPanel = new JPanel();
                 progressPanel.add(current);
                   cancelPanel = new JPanel();
                   statusPanel = new JPanel();
                   statusPanel = new JLabel(" From A to B");
                   statusPanel.add(statusLabel);
                   cancelButton = new JButton("cancel");
                   cancelButton.addActionListener(
              new ActionListener() {
                             public void actionPerformed(ActionEvent event)
                             {
                                            Current.setValue(0);
                                             kFrame.setVisible(false);
                                }
                     }
  );
   Current.setSize(100, 5);
   cancelPanel.add(cancelButton);
   emptyLabel1 = new JLabel("");
   emptyLabel2 = new JLabel("");
   emptyLabel3 = new JLabel("");
   emptyLabel4 = new JLabel("");
    emptyPanel1 = new JPanel();
    emptyPanel2 = new JPanel();
    emptyPanel3 = new JPanel();
    emptyPanel4= new JPanel();
        readPanel = new JPanel();
        sendPanel = new JPanel();
        messagePanel = new JPanel();
        cypherPanel = new JPanel();
        plainPanel = new JPanel()
         boardPanel1 = new JPanel();
         boardPanel1.setLayout(new FlowLayout()); 
         boardPanel2 = new JPanel();
         boardPanel2.setLayout(new FlowLayout());
           messageArea = new JTextArea(5,60);
           messageArea.setLineWrap(true);
           messageArea.setWrapStyleWord(true);
           messageArea.setFont(new Font("Monospaced",  Font.PLAIN, 12));
           messageArea.setEditable(true);
          cypherArea = new JTextArea(20,20);
          cypherArea.setLineWrap(true);
          cypherArea.setWrapStyleWord(true);
          cypherArea.setFont(new Font(" Serif",  Font.PLAIN, 12));
           cypherArea.setEditable(false);
           plainArea = new JTextArea(20,22);
           plainArea.setLineWrap(true);
           plainArea.setWrapStyleWord(true);
           plainArea.setFont(new Font(" Monospaced",  Font.PLAIN, 12));
           plainArea.setEditable(false);
           messageScroll = new JScrollPane(messageArea,
  ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
  ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEVER);
              cypherScroll = new JScrollPane(cypherArea,
ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
 ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
             plainScroll = new JScrollPane(plainArea, 
 ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
 ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
             readButton = new JButton("read>>>");
             readButton.addActionListener(
                         new  ActionListener()  {
                                        public void actionPerformed(ActionEvent event)
                                         {
                                                      secretKey();
                                          }
                          }
 );
 sendButton = new JButton("send");
sendButton.addActionListener(
              new ActionListner() {
                            public void actionPerformed(ActionEvent event)
                            {
                                              kFrame.setVisible(false);
                                              publish = "";
                                              do {
                                                              p = gen.primeNumber();
                                             }while(!(p > 10)  || !(p < 26) );
                                             do {
                                                           q = gen.primeNumber();

                                              }while( (q <=p)  || !((q-p) >2) );
                                              n  = p*q;
                                              m = (p-1) * (q-1);
                                              e = gen.coprime(m);
                                              d = gen.find_d(m,e);
                                               message = messageArea.getText();
                                               enc = new Encryption(message);
                                                cyphertext = enc.encrypt(e,n);
                                                publish_Keys();
                                                kFrame.setVisible(true);
                                                go = newSending(cyphertext,kFrame,iFrame, 
     cypherArea, current, container);
                                                go.start();
                 kFrame.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
                 container.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
                                             }
                                }
                  );
                 cypherPanel.add(cypherScroll);
                 cypherPanel.setBorder(BorderFactory.createTitledBorder("cyphertext"));
                 readPanel.add(readButton);
                 plainPanel.add(plainScroll);
                plainPanel.setBorder(BorderFactory.createTitledBorder("recovered plaintext")); 
                  messagePanel.add(messageScroll);
                       sendPanel.add(sendButton);
                       emptyPanel1.add(emptyLabel1);
                       emptyPanel2.add(emptyLabel2);
                       emptyPanel3.add(emptyLabel3);
                       emptyPanel4.add(emptyLabel4);
                       boardPanel1.add(cypherPanel);
                       boardPanel1.add(readPanel);
                       boardPanel1.add(plainPanel);
---------
]]></description>
			<content:encoded><![CDATA[<div>Please, i am writing a project on implementation of Rivest-Shamir-Adleman(RSA) algorithm on local area network(LAN).But the JAVA program i wrote refused to work. please, can anyone help me with this.The program is given below is only a part of the entire program due to space constraint. The remain program will be sent in the next post.Thanks<br />
<div style="margin:20px; margin-top:5px">
	<div class="smallfont" style="margin-bottom:2px">Code:</div>
	<hr /><code style="margin:0px" dir="ltr" style="text-align:left">&nbsp; import java.awt.*;<br />
&nbsp;  import java.awt.event.*;<br />
&nbsp;  import javax.swing.*;<br />
&nbsp;  import java.lang.*;<br />
public class My_RSA extends JFrame {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  private Container&nbsp; container;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  private JFrame iFrame,jFrame, kFrame;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  private GridBagLayout layout;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  private GridBagConstraints constraints;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  private JTextField nField, dField;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  private JTextArea messageArea, cypherArea, plainArea,keysArea;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  private&nbsp; JScrollPane messagescroll, cypherScroll, plainScroll;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  private JButton readButton, sendButton, okButton, cancelButton;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  private JPanel jPanel, nPanel,dPanel, okPanel,myPanel, mePanel,<br />
&nbsp;  statusPanel, progressPanel,cancelPanel;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  private JPanel boardPanel1, boardPanel2, cypherPanel,plainPanel, <br />
&nbsp; messagePanel, readPanel, sendPanel;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  private JLabel emptyLabel, jLabel, nLabel, dLabel, dumLabel1, dumLabel2, <br />
&nbsp;  statusLabel;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  private&nbsp; JLabel emptyLabel1,&nbsp; emptyLabel2 , emptyLabel3, emptyLabel4;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  private&nbsp; JPanel emptyPanel,&nbsp; emptyPanel1, emptyPanel2, emptyPanel3,<br />
&nbsp; &nbsp; emptyPanel4;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; private String message = &quot;&quot;, plaintext = &quot;&quot;, cyphertext = &quot;&quot;, publish = &quot;&quot;;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; private long d, e, m, n, p, q;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  private final JProgressBar&nbsp; current = new JProgressBar(0, 100);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  private&nbsp; KeyGenerator gen;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  private&nbsp; Encryption enc;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  private&nbsp; Decryption dec;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  private&nbsp; Sending go;<br />
&nbsp; public My_RSA()<br />
&nbsp;  {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Super(&quot;RSA Encryption System&quot;);<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  Container = getContentPane();<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  layout = new GridBagLayout();<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  container.setLayout(layout);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  constraints = new GridBagConstraints();<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  gen = new KeyGenerator();<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  kFrame = new JFrame(&quot;Sending...&quot;);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  mePanel = new JPanel();<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  mePanel.setLayout(layout);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  progressPanel = new JPanel();<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  progressPanel.add(current);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  cancelPanel = new JPanel();<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  statusPanel = new JPanel();<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  statusPanel = new JLabel(&quot; From A to B&quot;);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  statusPanel.add(statusLabel);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  cancelButton = new JButton(&quot;cancel&quot;);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  cancelButton.addActionListener(<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; new ActionListener() {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  public void actionPerformed(ActionEvent event)<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Current.setValue(0);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  kFrame.setVisible(false);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  }<br />
&nbsp; );<br />
&nbsp;  Current.setSize(100, 5);<br />
&nbsp;  cancelPanel.add(cancelButton);<br />
&nbsp;  emptyLabel1 = new JLabel(&quot;&quot;);<br />
&nbsp;  emptyLabel2 = new JLabel(&quot;&quot;);<br />
&nbsp;  emptyLabel3 = new JLabel(&quot;&quot;);<br />
&nbsp;  emptyLabel4 = new JLabel(&quot;&quot;);<br />
&nbsp; &nbsp; emptyPanel1 = new JPanel();<br />
&nbsp; &nbsp; emptyPanel2 = new JPanel();<br />
&nbsp; &nbsp; emptyPanel3 = new JPanel();<br />
&nbsp; &nbsp; emptyPanel4= new JPanel();<br />
&nbsp; &nbsp; &nbsp; &nbsp; readPanel = new JPanel();<br />
&nbsp; &nbsp; &nbsp; &nbsp; sendPanel = new JPanel();<br />
&nbsp; &nbsp; &nbsp; &nbsp; messagePanel = new JPanel();<br />
&nbsp; &nbsp; &nbsp; &nbsp; cypherPanel = new JPanel();<br />
&nbsp; &nbsp; &nbsp; &nbsp; plainPanel = new JPanel()<br />
&nbsp; &nbsp; &nbsp; &nbsp;  boardPanel1 = new JPanel();<br />
&nbsp; &nbsp; &nbsp; &nbsp;  boardPanel1.setLayout(new FlowLayout()); <br />
&nbsp; &nbsp; &nbsp; &nbsp;  boardPanel2 = new JPanel();<br />
&nbsp; &nbsp; &nbsp; &nbsp;  boardPanel2.setLayout(new FlowLayout());<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  messageArea = new JTextArea(5,60);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  messageArea.setLineWrap(true);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  messageArea.setWrapStyleWord(true);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  messageArea.setFont(new Font(&quot;Monospaced&quot;,&nbsp; Font.PLAIN, 12));<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  messageArea.setEditable(true);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; cypherArea = new JTextArea(20,20);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; cypherArea.setLineWrap(true);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; cypherArea.setWrapStyleWord(true);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; cypherArea.setFont(new Font(&quot; Serif&quot;,&nbsp; Font.PLAIN, 12));<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  cypherArea.setEditable(false);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  plainArea = new JTextArea(20,22);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  plainArea.setLineWrap(true);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  plainArea.setWrapStyleWord(true);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  plainArea.setFont(new Font(&quot; Monospaced&quot;,&nbsp; Font.PLAIN, 12));<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  plainArea.setEditable(false);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  messageScroll = new JScrollPane(messageArea,<br />
&nbsp; ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,<br />
&nbsp; ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEVER);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; cypherScroll = new JScrollPane(cypherArea,<br />
ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,<br />
&nbsp;ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  plainScroll = new JScrollPane(plainArea, <br />
&nbsp;ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,<br />
&nbsp;ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  readButton = new JButton(&quot;read&gt;&gt;&gt;&quot;);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  readButton.addActionListener(<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  new&nbsp; ActionListener()&nbsp; {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; public void actionPerformed(ActionEvent event)<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; secretKey();<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br />
&nbsp;);<br />
&nbsp;sendButton = new JButton(&quot;send&quot;);<br />
sendButton.addActionListener(<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; new ActionListner() {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; public void actionPerformed(ActionEvent event)<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; kFrame.setVisible(false);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; publish = &quot;&quot;;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; do {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; p = gen.primeNumber();<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  }while(!(p &gt; 10)&nbsp; || !(p &lt; 26) );<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  do {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  q = gen.primeNumber();<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }while( (q &lt;=p)&nbsp; || !((q-p) &gt;2) );<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; n&nbsp; = p*q;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; m = (p-1) * (q-1);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; e = gen.coprime(m);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; d = gen.find_d(m,e);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  message = messageArea.getText();<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  enc = new Encryption(message);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; cyphertext = enc.encrypt(e,n);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; publish_Keys();<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; kFrame.setVisible(true);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; go = newSending(cyphertext,kFrame,iFrame, <br />
&nbsp; &nbsp;  cypherArea, current, container);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; go.start();<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  kFrame.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  container.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  }<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; );<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  cypherPanel.add(cypherScroll);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  cypherPanel.setBorder(BorderFactory.createTitledBorder(&quot;cyphertext&quot;));<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  readPanel.add(readButton);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  plainPanel.add(plainScroll);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; plainPanel.setBorder(BorderFactory.createTitledBorder(&quot;recovered plaintext&quot;)); <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; messagePanel.add(messageScroll);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  sendPanel.add(sendButton);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  emptyPanel1.add(emptyLabel1);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  emptyPanel2.add(emptyLabel2);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  emptyPanel3.add(emptyLabel3);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  emptyPanel4.add(emptyLabel4);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  boardPanel1.add(cypherPanel);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  boardPanel1.add(readPanel);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  boardPanel1.add(plainPanel);</code><hr />
</div></div>

]]></content:encoded>
			<category domain="http://forums.devx.com/forumdisplay.php?f=104">Java</category>
			<dc:creator>kayode</dc:creator>
			<guid isPermaLink="true">http://forums.devx.com/showthread.php?t=173400</guid>
		</item>
		<item>
			<title>Spiral Array Matrix</title>
			<link>http://forums.devx.com/showthread.php?t=173391&amp;goto=newpost</link>
			<pubDate>Tue, 17 Nov 2009 07:53:30 GMT</pubDate>
			<description>Hei master ... please help me, i wanna know how print a spiral order number like this :

05 04 03 02 01
06 19 18 17 16
07 20 25 24 15
08 21 22 23 14
09 10 11 12 13

Please help me ... :WAVE: :confused:</description>
			<content:encoded><![CDATA[<div>Hei master ... please help me, i wanna know how print a spiral order number like this :<br />
<br />
05 04 03 02 01<br />
06 19 18 17 16<br />
07 20 25 24 15<br />
08 21 22 23 14<br />
09 10 11 12 13<br />
<br />
Please help me ... :WAVE: :confused:</div>

]]></content:encoded>
			<category domain="http://forums.devx.com/forumdisplay.php?f=104">Java</category>
			<dc:creator>rendra</dc:creator>
			<guid isPermaLink="true">http://forums.devx.com/showthread.php?t=173391</guid>
		</item>
		<item>
			<title>To the administrator.</title>
			<link>http://forums.devx.com/showthread.php?t=173380&amp;goto=newpost</link>
			<pubDate>Mon, 16 Nov 2009 06:30:26 GMT</pubDate>
			<description>Hello, 
      Please, i have a JAVA  program that i want to submit but it is too long (26478 characters). It contains a program for my project work which i want to post so that anyone out there can help me to correct the mistakes. Please how do i post it? because i have tried to post it but it just would not go. Thanks. Please reply!</description>
			<content:encoded><![CDATA[<div>Hello, <br />
      Please, i have a JAVA  program that i want to submit but it is too long (26478 characters). It contains a program for my project work which i want to post so that anyone out there can help me to correct the mistakes. Please how do i post it? because i have tried to post it but it just would not go. Thanks. Please reply!</div>

]]></content:encoded>
			<category domain="http://forums.devx.com/forumdisplay.php?f=104">Java</category>
			<dc:creator>kayode</dc:creator>
			<guid isPermaLink="true">http://forums.devx.com/showthread.php?t=173380</guid>
		</item>
		<item>
			<title><![CDATA[Help with Dijkstra's Algorithm]]></title>
			<link>http://forums.devx.com/showthread.php?t=173375&amp;goto=newpost</link>
			<pubDate>Sun, 15 Nov 2009 06:03:06 GMT</pubDate>
			<description><![CDATA[I have a program and am supposed to write dijkstra's method. The program reads a file consisting of a weighted digraph and asks user for starting vertex. It then use Dijkstra's algorithm to find the shortest path to all other vertices. Can someone take a look at what I've written (the shortestPaths method in dijkstra.java) and let me know where I went wrong. I'm not really sure how to implement Dijkstra's algorithm.

*File: input.graph*

Code:
---------
6
a : b 5 c  13 \
b : c 1 d 10 \
c : b 2 d 7 e 5 \
d : f 7 \
e : d 3 f 4 \
f : \
---------
*WeightedDigraph.java*

Code:
---------
public class WeightedDigraph
{
  int numberVertices;
  List<List<WeightedEdge>> adjList = new ArrayList<List<WeightedEdge>>(); 
  List<String> vertexName = new ArrayList<String>();
  Map<String, Integer> nameToVertex = new HashMap<String, Integer>();
  List<WeightedEdge> getNeighbors(int vertexNumber) 
      { return adjList.get(vertexNumber);}
  public int getNumberVertices() { return numberVertices; }
  void buildGraph(Scanner sc)
  {   
      numberVertices = sc.nextInt();
      for (int k = 0; k < numberVertices; k++)
      {
          adjList.add(new ArrayList<WeightedEdge>());
      }
      
      String initVertexName, endVertexName;
      int weight;
      for (int k = 0; k < numberVertices; k++)
      {
          initVertexName = sc.next();        

          int initVertexIndex = vertexName.indexOf(initVertexName);
          if (initVertexIndex == -1)
          {
              // Add the new vertex to the array list and the map
              initVertexIndex = vertexName.size();
              vertexName.add(initVertexName);
              nameToVertex.put(initVertexName, initVertexIndex);
          }
          String separator = sc.next();
          if (! (separator.equals(":"))) throw new RuntimeException("Missing :" + 
                  " after initial vertex.");
          String nextToken = sc.next();
          while (!nextToken.equals("\\"))
          {
              endVertexName = nextToken;           

              if (!sc.hasNextInt()) throw new RuntimeException("Missing edge weight");
              weight = sc.nextInt();           
              
              int endVertexIndex = vertexName.indexOf(endVertexName);
              if (endVertexIndex == -1)
              {
                  endVertexIndex = vertexName.size();
                  vertexName.add(endVertexName);
                  nameToVertex.put(endVertexName, endVertexIndex);
              }
              adjList.get(initVertexIndex).add(new WeightedEdge(endVertexIndex, weight));
              nextToken = sc.next();
          }          
      }      
  }
  @Override
  public String toString()
  {
    StringBuilder sB = new StringBuilder();
    for (int k = 0; k < vertexName.size(); k++)
    {
        sB.append(vertexName.get(k) + " : ");
        for (WeightedEdge wE : adjList.get(k))
        {
           sB.append( " (" + vertexName.get(wE.dest) + " " + wE.weight + ") " );
        }
        sB.append(" \\\n");
    }
    return sB.toString();
  }
}

class WeightedEdge
{
   public final int dest;
   public final int weight;
   public WeightedEdge(int dest, int weight)
   {
       this.dest = dest;  this.weight = weight;
   }
   @Override
   public boolean equals(Object other)
   {
      if (other == null) return false;
      if (!(other instanceof WeightedEdge)) return false;
      WeightedEdge wE = (WeightedEdge)other;
      return dest == wE.dest && weight == wE.weight;
   }
}
---------
]]></description>
			<content:encoded><![CDATA[<div>I have a program and am supposed to write dijkstra's method. The program reads a file consisting of a weighted digraph and asks user for starting vertex. It then use Dijkstra's algorithm to find the shortest path to all other vertices. Can someone take a look at what I've written (the shortestPaths method in dijkstra.java) and let me know where I went wrong. I'm not really sure how to implement Dijkstra's algorithm.<br />
<br />
<b>File: input.graph</b><br />
<div style="margin:20px; margin-top:5px">
	<div class="smallfont" style="margin-bottom:2px">Code:</div>
	<hr /><code style="margin:0px" dir="ltr" style="text-align:left">6<br />
a : b 5 c&nbsp; 13 \<br />
b : c 1 d 10 \<br />
c : b 2 d 7 e 5 \<br />
d : f 7 \<br />
e : d 3 f 4 \<br />
f : \</code><hr />
</div><b>WeightedDigraph.java</b><br />
<div style="margin:20px; margin-top:5px">
	<div class="smallfont" style="margin-bottom:2px">Code:</div>
	<hr /><code style="margin:0px" dir="ltr" style="text-align:left">public class WeightedDigraph<br />
{<br />
&nbsp; int numberVertices;<br />
&nbsp; List&lt;List&lt;WeightedEdge&gt;&gt; adjList = new ArrayList&lt;List&lt;WeightedEdge&gt;&gt;(); <br />
&nbsp; List&lt;String&gt; vertexName = new ArrayList&lt;String&gt;();<br />
&nbsp; Map&lt;String, Integer&gt; nameToVertex = new HashMap&lt;String, Integer&gt;();<br />
&nbsp; List&lt;WeightedEdge&gt; getNeighbors(int vertexNumber) <br />
&nbsp; &nbsp; &nbsp; { return adjList.get(vertexNumber);}<br />
&nbsp; public int getNumberVertices() { return numberVertices; }<br />
&nbsp; void buildGraph(Scanner sc)<br />
&nbsp; {&nbsp;  <br />
&nbsp; &nbsp; &nbsp; numberVertices = sc.nextInt();<br />
&nbsp; &nbsp; &nbsp; for (int k = 0; k &lt; numberVertices; k++)<br />
&nbsp; &nbsp; &nbsp; {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; adjList.add(new ArrayList&lt;WeightedEdge&gt;());<br />
&nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; String initVertexName, endVertexName;<br />
&nbsp; &nbsp; &nbsp; int weight;<br />
&nbsp; &nbsp; &nbsp; for (int k = 0; k &lt; numberVertices; k++)<br />
&nbsp; &nbsp; &nbsp; {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; initVertexName = sc.next();&nbsp; &nbsp; &nbsp; &nbsp; <br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; int initVertexIndex = vertexName.indexOf(initVertexName);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (initVertexIndex == -1)<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // Add the new vertex to the array list and the map<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; initVertexIndex = vertexName.size();<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; vertexName.add(initVertexName);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; nameToVertex.put(initVertexName, initVertexIndex);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; String separator = sc.next();<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (! (separator.equals(&quot;:&quot;))) throw new RuntimeException(&quot;Missing :&quot; + <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &quot; after initial vertex.&quot;);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; String nextToken = sc.next();<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; while (!nextToken.equals(&quot;\\&quot;))<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; endVertexName = nextToken;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  <br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (!sc.hasNextInt()) throw new RuntimeException(&quot;Missing edge weight&quot;);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; weight = sc.nextInt();&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; int endVertexIndex = vertexName.indexOf(endVertexName);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (endVertexIndex == -1)<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; endVertexIndex = vertexName.size();<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; vertexName.add(endVertexName);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; nameToVertex.put(endVertexName, endVertexIndex);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; adjList.get(initVertexIndex).add(new WeightedEdge(endVertexIndex, weight));<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; nextToken = sc.next();<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; <br />
&nbsp; }<br />
&nbsp; @Override<br />
&nbsp; public String toString()<br />
&nbsp; {<br />
&nbsp; &nbsp; StringBuilder sB = new StringBuilder();<br />
&nbsp; &nbsp; for (int k = 0; k &lt; vertexName.size(); k++)<br />
&nbsp; &nbsp; {<br />
&nbsp; &nbsp; &nbsp; &nbsp; sB.append(vertexName.get(k) + &quot; : &quot;);<br />
&nbsp; &nbsp; &nbsp; &nbsp; for (WeightedEdge wE : adjList.get(k))<br />
&nbsp; &nbsp; &nbsp; &nbsp; {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  sB.append( &quot; (&quot; + vertexName.get(wE.dest) + &quot; &quot; + wE.weight + &quot;) &quot; );<br />
&nbsp; &nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; &nbsp; &nbsp; sB.append(&quot; \\\n&quot;);<br />
&nbsp; &nbsp; }<br />
&nbsp; &nbsp; return sB.toString();<br />
&nbsp; }<br />
}<br />
<br />
class WeightedEdge<br />
{<br />
&nbsp;  public final int dest;<br />
&nbsp;  public final int weight;<br />
&nbsp;  public WeightedEdge(int dest, int weight)<br />
&nbsp;  {<br />
&nbsp; &nbsp; &nbsp;  this.dest = dest;&nbsp; this.weight = weight;<br />
&nbsp;  }<br />
&nbsp;  @Override<br />
&nbsp;  public boolean equals(Object other)<br />
&nbsp;  {<br />
&nbsp; &nbsp; &nbsp; if (other == null) return false;<br />
&nbsp; &nbsp; &nbsp; if (!(other instanceof WeightedEdge)) return false;<br />
&nbsp; &nbsp; &nbsp; WeightedEdge wE = (WeightedEdge)other;<br />
&nbsp; &nbsp; &nbsp; return dest == wE.dest &amp;&amp; weight == wE.weight;<br />
&nbsp;  }<br />
}</code><hr />
</div></div>

]]></content:encoded>
			<category domain="http://forums.devx.com/forumdisplay.php?f=104">Java</category>
			<dc:creator>justinsbabe5000</dc:creator>
			<guid isPermaLink="true">http://forums.devx.com/showthread.php?t=173375</guid>
		</item>
		<item>
			<title>implementation of nearest neighbour clustering algorithm using java</title>
			<link>http://forums.devx.com/showthread.php?t=173347&amp;goto=newpost</link>
			<pubDate>Tue, 10 Nov 2009 04:56:28 GMT</pubDate>
			<description>I have got a project on effect of noice using various clustering algorithm..I m ant able to implement nearest neighbour..Do help</description>
			<content:encoded><![CDATA[<div>I have got a project on effect of noice using various clustering algorithm..I m ant able to implement nearest neighbour..Do help</div>

]]></content:encoded>
			<category domain="http://forums.devx.com/forumdisplay.php?f=104">Java</category>
			<dc:creator>rose21</dc:creator>
			<guid isPermaLink="true">http://forums.devx.com/showthread.php?t=173347</guid>
		</item>
		<item>
			<title>Source code for implementation of rivest-shamir-adleman algorithm on lan using java</title>
			<link>http://forums.devx.com/showthread.php?t=173342&amp;goto=newpost</link>
			<pubDate>Mon, 09 Nov 2009 23:24:14 GMT</pubDate>
			<description><![CDATA[Hello,
       Please, is anyone out there that can be me out with the source code for implementation of RIVEST-SHAMIR-ADLEMAN ALGORITHM ON A LOCAL AREA NETWORK using JAVA. I'm a  final year computer science student working on my project which has to do with implementation of RSA ALGORITHM on a LAN. But i only have a little knowledge about JAVA programming. Please,i would be glad if anyone can help me out. Thanks.


Edit by admin: no contact info permitted on the forum, thank you]]></description>
			<content:encoded><![CDATA[<div>Hello,<br />
       Please, is anyone out there that can be me out with the source code for implementation of RIVEST-SHAMIR-ADLEMAN ALGORITHM ON A LOCAL AREA NETWORK using JAVA. I'm a  final year computer science student working on my project which has to do with implementation of RSA ALGORITHM on a LAN. But i only have a little knowledge about JAVA programming. Please,i would be glad if anyone can help me out. Thanks.<br />
<br />
<br />
Edit by admin: no contact info permitted on the forum, thank you</div>

]]></content:encoded>
			<category domain="http://forums.devx.com/forumdisplay.php?f=104">Java</category>
			<dc:creator>kayode</dc:creator>
			<guid isPermaLink="true">http://forums.devx.com/showthread.php?t=173342</guid>
		</item>
		<item>
			<title>desparate.....need help Enabling/disabling style sheets remotely..... how to do it?</title>
			<link>http://forums.devx.com/showthread.php?t=173331&amp;goto=newpost</link>
			<pubDate>Sun, 08 Nov 2009 04:39:33 GMT</pubDate>
			<description><![CDATA[Hi all,  

The standard method for enabling (showing) and disabling (hiding) a css style sheet is this:


document.styleSheets[0].disabled=true;


This method is used to change background pictures on a web page to other ones, say, if a user clicks a button or selects a drop-down option.
You can have two css files with two different pictures, styleSheets[0] and styleSheets[1], and hide and swap them to make the picture change.

However, "document" always refers to the current window you are in. If a web page has multiple windows (controlled by different css files), does anyone know how to disable the stylesheet of a Different window than the one you are in?

For example:

[the other window on the page].document.stylesheets[0].disabled=true??

? ? ? ? ?

That way, you can click a button or change the drop down on one window, and have it affect the PICTURE in the other window.

I have an application written by other people (who can't be reached ever) and it has multiple windows on it......each with its own css file.
I want to do something on one window (change a drop-down box), and have it enable/disable stylesheets with their background pictures on the other.

I've been stuck on this for days.
Thanks for any help!]]></description>
			<content:encoded><![CDATA[<div>Hi all,  <br />
<br />
The standard method for enabling (showing) and disabling (hiding) a css style sheet is this:<br />
<br />
<br />
document.styleSheets[0].disabled=true;<br />
<br />
<br />
This method is used to change background pictures on a web page to other ones, say, if a user clicks a button or selects a drop-down option.<br />
You can have two css files with two different pictures, styleSheets[0] and styleSheets[1], and hide and swap them to make the picture change.<br />
<br />
However, &quot;document&quot; always refers to the current window you are in. If a web page has multiple windows (controlled by different css files), does anyone know how to disable the stylesheet of a Different window than the one you are in?<br />
<br />
For example:<br />
<br />
[the other window on the page].document.stylesheets[0].disabled=true??<br />
<br />
? ? ? ? ?<br />
<br />
That way, you can click a button or change the drop down on one window, and have it affect the PICTURE in the other window.<br />
<br />
I have an application written by other people (who can't be reached ever) and it has multiple windows on it......each with its own css file.<br />
I want to do something on one window (change a drop-down box), and have it enable/disable stylesheets with their background pictures on the other.<br />
<br />
I've been stuck on this for days.<br />
Thanks for any help!</div>

]]></content:encoded>
			<category domain="http://forums.devx.com/forumdisplay.php?f=104">Java</category>
			<dc:creator>jeffery1493</dc:creator>
			<guid isPermaLink="true">http://forums.devx.com/showthread.php?t=173331</guid>
		</item>
		<item>
			<title>Need Help: Adding a day in a variable using Jasper Reports</title>
			<link>http://forums.devx.com/showthread.php?t=173318&amp;goto=newpost</link>
			<pubDate>Fri, 06 Nov 2009 01:42:21 GMT</pubDate>
			<description><![CDATA[I'm a newbie in java programming and I would like to ask solutions to my development problem.

I would to ask if I could possibly *add one day* to a date variable or date field in Jasper Report?
and my date format is 'yyyy-MM-d'.
ex.
2009-11-6 + 1 day = 2009-11-7


Thank you.]]></description>
			<content:encoded><![CDATA[<div>I'm a newbie in java programming and I would like to ask solutions to my development problem.<br />
<br />
I would to ask if I could possibly <b>add one day</b> to a <i>date variable or date field</i> in Jasper Report?<br />
and my date format is 'yyyy-MM-d'.<br />
ex.<br />
2009-11-6 + 1 day = 2009-11-7<br />
<br />
<br />
Thank you.</div>

]]></content:encoded>
			<category domain="http://forums.devx.com/forumdisplay.php?f=104">Java</category>
			<dc:creator>bischmarck</dc:creator>
			<guid isPermaLink="true">http://forums.devx.com/showthread.php?t=173318</guid>
		</item>
		<item>
			<title><![CDATA[How to extract the server Host/IP from the CORBA IOR & NamingContextExt? [Java]]]></title>
			<link>http://forums.devx.com/showthread.php?t=173302&amp;goto=newpost</link>
			<pubDate>Wed, 04 Nov 2009 05:46:20 GMT</pubDate>
			<description><![CDATA[I've got a Client who needs to send a UDP packet to a server and the only reference he has to the Server is through the CORBA naming service (IOR). I know the IOR has the Server Information embedded but is there an easy way for me to extract it?

This is the code I have so far:

Code:
---------
   Object objRef = orb.resolve_initial_references("NameService");
   NamingContextExt ncRef = NamingContextExtHelper.narrow(objRef);
   Object o = ncRef.resolve_str(Name);
---------
After this Object o contains the IOR (if I do o.toString() it sure looks like a valid IOR), so from this what can I do to get the corresponding Servers IP/PORT so I can send it a UDP packet?

I know this sounds odd - why not just invoke the remote method, well this is for a school project and the professor recommended simply storing another table with all the sever information - but I am trying to be creative and since I was reading about the IOR I thought maybe I could do something with it ...

Any help would be much appreciated.
Thanks,]]></description>
			<content:encoded><![CDATA[<div>I've got a Client who needs to send a UDP packet to a server and the only reference he has to the Server is through the CORBA naming service (IOR). I know the IOR has the Server Information embedded but is there an easy way for me to extract it?<br />
<br />
This is the code I have so far:<br />
<div style="margin:20px; margin-top:5px">
	<div class="smallfont" style="margin-bottom:2px">Code:</div>
	<hr /><code style="margin:0px" dir="ltr" style="text-align:left">&nbsp;  Object objRef = orb.resolve_initial_references(&quot;NameService&quot;);<br />
&nbsp;  NamingContextExt ncRef = NamingContextExtHelper.narrow(objRef);<br />
&nbsp;  Object o = ncRef.resolve_str(Name);</code><hr />
</div>After this Object o contains the IOR (if I do o.toString() it sure looks like a valid IOR), so from this what can I do to get the corresponding Servers IP/PORT so I can send it a UDP packet?<br />
<br />
I know this sounds odd - why not just invoke the remote method, well this is for a school project and the professor recommended simply storing another table with all the sever information - but I am trying to be creative and since I was reading about the IOR I thought maybe I could do something with it ...<br />
<br />
Any help would be much appreciated.<br />
Thanks,</div>

]]></content:encoded>
			<category domain="http://forums.devx.com/forumdisplay.php?f=104">Java</category>
			<dc:creator>Shaitan00</dc:creator>
			<guid isPermaLink="true">http://forums.devx.com/showthread.php?t=173302</guid>
		</item>
		<item>
			<title>syntax error</title>
			<link>http://forums.devx.com/showthread.php?t=173289&amp;goto=newpost</link>
			<pubDate>Mon, 02 Nov 2009 23:41:42 GMT</pubDate>
			<description><![CDATA[also plz tell if there is nething wrong in this piece of code-

Code:
---------
public static final Integer multiply(Integer x, Integer y) {
return (y == 0) ? 0 : multiply(x, y - 1) + x;
}
---------
I think as the return type is static and final we can't return different value everytime?]]></description>
			<content:encoded><![CDATA[<div>also plz tell if there is nething wrong in this piece of code-<br />
<div style="margin:20px; margin-top:5px">
	<div class="smallfont" style="margin-bottom:2px">Code:</div>
	<hr /><code style="margin:0px" dir="ltr" style="text-align:left">public static final Integer multiply(Integer x, Integer y) {<br />
return (y == 0) ? 0 : multiply(x, y - 1) + x;<br />
}</code><hr />
</div>I think as the return type is static and final we can't return different value everytime?</div>

]]></content:encoded>
			<category domain="http://forums.devx.com/forumdisplay.php?f=104">Java</category>
			<dc:creator>gaurav_kl</dc:creator>
			<guid isPermaLink="true">http://forums.devx.com/showthread.php?t=173289</guid>
		</item>
		<item>
			<title>is there syntax error</title>
			<link>http://forums.devx.com/showthread.php?t=173288&amp;goto=newpost</link>
			<pubDate>Mon, 02 Nov 2009 23:38:14 GMT</pubDate>
			<description><![CDATA[hi,someone plz tell if thr is any syntax error in the following code-


Code:
---------
public LinkedList findOrdersForProduct(Product p, boolean debug) {
ArrayList l = new ArrayList();
ArrayList list = getAllOrders();
for (int i=0; i<list.size(); i++) {
Order order = (Order) list.get(0);
boolean found = false;
if (order.getProducts().size() > 0) {
for (int j=0; j<=order.getProducts().size(); j++) {
Product p2 = order.getProducts().get(j);
found = (p2 == p);
}
if (found && order != null)
l.add(order);
}
}
return new LinkedList(l);
}
---------
]]></description>
			<content:encoded><![CDATA[<div>hi,someone plz tell if thr is any syntax error in the following code-<br />
<br />
<div style="margin:20px; margin-top:5px">
	<div class="smallfont" style="margin-bottom:2px">Code:</div>
	<hr /><code style="margin:0px" dir="ltr" style="text-align:left">public LinkedList findOrdersForProduct(Product p, boolean debug) {<br />
ArrayList l = new ArrayList();<br />
ArrayList list = getAllOrders();<br />
for (int i=0; i&lt;list.size(); i++) {<br />
Order order = (Order) list.get(0);<br />
boolean found = false;<br />
if (order.getProducts().size() &gt; 0) {<br />
for (int j=0; j&lt;=order.getProducts().size(); j++) {<br />
Product p2 = order.getProducts().get(j);<br />
found = (p2 == p);<br />
}<br />
if (found &amp;&amp; order != null)<br />
l.add(order);<br />
}<br />
}<br />
return new LinkedList(l);<br />
}</code><hr />
</div></div>

]]></content:encoded>
			<category domain="http://forums.devx.com/forumdisplay.php?f=104">Java</category>
			<dc:creator>gaurav_kl</dc:creator>
			<guid isPermaLink="true">http://forums.devx.com/showthread.php?t=173288</guid>
		</item>
		<item>
			<title>Triangular N Queens Problem</title>
			<link>http://forums.devx.com/showthread.php?t=173245&amp;goto=newpost</link>
			<pubDate>Tue, 27 Oct 2009 09:14:53 GMT</pubDate>
			<description><![CDATA[I have the following code:


Code:
---------
import javax.swing.*;
import java.util.*;
import java.awt.*;
import java.util.List;

public class Main
{

    // This is a list of all possible positions on the
    // triangular N-queens. Positions are 1-based.
    static List<Position> boardPositions;
    public static void main(String[] args)
    {
       String input = JOptionPane.showInputDialog(null,
                   "Triangular Queens: Enter a positive integer", "6" );
       int n = Integer.parseInt(input.trim());

       boardPositions = getBoardPositions(n);
       Stack<Position> partialSol = new Stack<Position>();
       System.out.println("Size of maximal placement is " + (2*n + 1)/3);
       extendQueensPlacement(partialSol, 0, n);

       System.out.println("Size of solution is " + partialSol.size());
       for (Position p : partialSol)
           System.out.print(p + "   ");
       Board queensDisplay = new Board(n, partialSol);
       JOptionPane.showMessageDialog(null, queensDisplay, "Triangular N Queens",
               JOptionPane.INFORMATION_MESSAGE);
    }
    /**
     *
     * @param partialSol
     * @param k the index of the boardPosition we are about to try to include
     * in partialSol. This is an index into the static class member boardPositions
     * whick is a List of Position objects.
     * @param n
     * @return true if the partial solution is successfully extended to a
     * complete solution, and returns false otherwise. If the false is returned, then
     * the partial solution with the same value it had at the call.
     */
    public static boolean extendQueensPlacement(Stack<Position> partialSol,
                                                int k, int n)
    {
        if(isComplete(partialSol, n))
            return true;

        for(k = 0; k < boardPositions.size(); k++)
        {
            if(!attacks(boardPositions.get(k), partialSol))
                partialSol.add(boardPositions.get(k));
        }

        return false;
    }

    /**
     * Checks to see if a partial solution is a complete solution.
     * @param partialSolution
     * @param n The size of the board.
     * @return true or false as appropriate
     */
    static boolean isComplete(Stack<Position> partialSolution, int n)
    {
        return partialSolution.size() == (2*n + 1)/3;
    }

    /**
     * Check to see if two position attack each other
     * @param p A position on the board (1-based)
     * @param q A position on the board (1-based)
     * @return true if they attack each other, false otherwise.
     */
    static boolean attacks(Position p, Position q)
    {
        return p.row == q.row || p.col == q.col || p.row - p.col == q.row - q.col;
    }

    /**
     * Checks to see a position attacks and position in a given list of
     * positions.
     * @param p a single position
     * @param posList a list of positions
     * @return true if p attacks at least one position in posList
     */
    static boolean attacks(Position p, List<Position> posList)
    {
        for (Position pos : posList)
        {
            if (attacks(p, pos)) return true;
        }
        return false;
    }
    /**
     * This method may not be needed. It removes from posList all positions
     * that attack pos. It returns the list of positions removed in this manner.
     * @param pos
     * @param posList
     * @return a list of all positions in posList, OTHER THAN pos, that attack
     * pos.
     */
    static List<Position> removeAttackers(Position pos, List<Position> posList)
    {
        List<Position> attackers = new ArrayList<Position>();
        for (int k = 0; k < posList.size(); )
        {
            Position p = posList.get(k);
            if (attacks(pos, p))
            {
                posList.remove(p);
                if (p != pos) attackers.add(p);
            }
            else k++;
        }
        return attackers;
    }
    /**
     * Used to generate the list of 1-based triangular board positions.
     * 1, 1 through n, n
     * @param n
     * @return list of triangular board positions.
     */
    static List<Position> getBoardPositions(int n)
    {
        List<Position> boardPosition = new ArrayList<Position>();
        for (int row = 1; row <= n; row ++)
            for (int col = 1; col <= row; col++)
                boardPosition.add(new Position(row, col));
        return boardPosition;
    }

    /** Used for debugging
     * Prints all Positions in a list
     * @param posList
     */
    static void println(List<Position>posList)
    {
        for (Position p : posList)
            System.out.print(p + " ");
        System.out.println();
    }
}

/**
 * A position indicating on the board for the triangular
 * N queens problem.
 * @author gcm
 */
class Position
{
    public final int row, col;
    public Position(int row, int col)
    {
        this.row = row; 
        this.col = col;
    }
    public String toString()
    {
        return "[" + row + "," + col + "]";        
    }
}

// A Graphical view of the triangular board with the queens placed.
// The constructor takes a list of queen positions and a board size
// and creates a JPanel neatly showing the placement of the queens.
class Board extends JPanel
{
    private int n; // size of board
    Board(int n, List<Position> placements)
    {
        super(new GridLayout(n, 2*n-1));
        this.n = n;
        // create the labels to diplay the placements
        JTextField labels [][] = new JTextField[n][2*n-1];
        for (int row = 0; row < n; row++)
            for (int col = 0; col < 2*n-1; col++)
            {
                labels[row][col] = new JTextField(" ");               
                add(labels[row][col]);
                labels[row][col].setEditable(false);
            }

        for (int r = 0; r < n; r++)
        {
            int startCol = n-1-r;
            for (int k = 0; k < r+1; k++)
            {
                labels[r][startCol + 2*k].setBackground(Color.YELLOW);
            }
        }
        // place the queens
        for (Position p : placements)
        {
            int r = p.row-1;
            int c = p.col-1;
            //labels[r][c].setForeground(Color.RED);
            //labels[r][c].setText("Q");
            labels[r][n-1 -r + 2*c].setForeground(Color.RED);
            labels[r][n-1 -r + 2*c].setText("Q");
            labels[r][n-1 -r + 2*c].setToolTipText(p.toString());

        }
    }

}
---------
What I can't figure out how to do is the public static boolean extendQueensPlacement(Stack<Position> partialSol, int k, int n) method. I check to see if it is a complete solution and if it is I return true and if it is not a complete solution then I go through each board position and add to partialSol if it does not attack any position in partialSol.

Now what I can't figure out how to do is when all board positions have been checked and partialSol is not a complete solution so backtrack and try another boardPosition. Not really sure how to do the backtracking.]]></description>
			<content:encoded><![CDATA[<div>I have the following code:<br />
<br />
<div style="margin:20px; margin-top:5px">
	<div class="smallfont" style="margin-bottom:2px">Code:</div>
	<hr /><code style="margin:0px" dir="ltr" style="text-align:left">import javax.swing.*;<br />
import java.util.*;<br />
import java.awt.*;<br />
import java.util.List;<br />
<br />
public class Main<br />
{<br />
<br />
&nbsp; &nbsp; // This is a list of all possible positions on the<br />
&nbsp; &nbsp; // triangular N-queens. Positions are 1-based.<br />
&nbsp; &nbsp; static List&lt;Position&gt; boardPositions;<br />
&nbsp; &nbsp; public static void main(String[] args)<br />
&nbsp; &nbsp; {<br />
&nbsp; &nbsp; &nbsp;  String input = JOptionPane.showInputDialog(null,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  &quot;Triangular Queens: Enter a positive integer&quot;, &quot;6&quot; );<br />
&nbsp; &nbsp; &nbsp;  int n = Integer.parseInt(input.trim());<br />
<br />
&nbsp; &nbsp; &nbsp;  boardPositions = getBoardPositions(n);<br />
&nbsp; &nbsp; &nbsp;  Stack&lt;Position&gt; partialSol = new Stack&lt;Position&gt;();<br />
&nbsp; &nbsp; &nbsp;  System.out.println(&quot;Size of maximal placement is &quot; + (2*n + 1)/3);<br />
&nbsp; &nbsp; &nbsp;  extendQueensPlacement(partialSol, 0, n);<br />
<br />
&nbsp; &nbsp; &nbsp;  System.out.println(&quot;Size of solution is &quot; + partialSol.size());<br />
&nbsp; &nbsp; &nbsp;  for (Position p : partialSol)<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  System.out.print(p + &quot;&nbsp;  &quot;);<br />
&nbsp; &nbsp; &nbsp;  Board queensDisplay = new Board(n, partialSol);<br />
&nbsp; &nbsp; &nbsp;  JOptionPane.showMessageDialog(null, queensDisplay, &quot;Triangular N Queens&quot;,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  JOptionPane.INFORMATION_MESSAGE);<br />
&nbsp; &nbsp; }<br />
&nbsp; &nbsp; /**<br />
&nbsp; &nbsp;  *<br />
&nbsp; &nbsp;  * @param partialSol<br />
&nbsp; &nbsp;  * @param k the index of the boardPosition we are about to try to include<br />
&nbsp; &nbsp;  * in partialSol. This is an index into the static class member boardPositions<br />
&nbsp; &nbsp;  * whick is a List of Position objects.<br />
&nbsp; &nbsp;  * @param n<br />
&nbsp; &nbsp;  * @return true if the partial solution is successfully extended to a<br />
&nbsp; &nbsp;  * complete solution, and returns false otherwise. If the false is returned, then<br />
&nbsp; &nbsp;  * the partial solution with the same value it had at the call.<br />
&nbsp; &nbsp;  */<br />
&nbsp; &nbsp; public static boolean extendQueensPlacement(Stack&lt;Position&gt; partialSol,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; int k, int n)<br />
&nbsp; &nbsp; {<br />
&nbsp; &nbsp; &nbsp; &nbsp; if(isComplete(partialSol, n))<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return true;<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; for(k = 0; k &lt; boardPositions.size(); k++)<br />
&nbsp; &nbsp; &nbsp; &nbsp; {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if(!attacks(boardPositions.get(k), partialSol))<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; partialSol.add(boardPositions.get(k));<br />
&nbsp; &nbsp; &nbsp; &nbsp; }<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; return false;<br />
&nbsp; &nbsp; }<br />
<br />
&nbsp; &nbsp; /**<br />
&nbsp; &nbsp;  * Checks to see if a partial solution is a complete solution.<br />
&nbsp; &nbsp;  * @param partialSolution<br />
&nbsp; &nbsp;  * @param n The size of the board.<br />
&nbsp; &nbsp;  * @return true or false as appropriate<br />
&nbsp; &nbsp;  */<br />
&nbsp; &nbsp; static boolean isComplete(Stack&lt;Position&gt; partialSolution, int n)<br />
&nbsp; &nbsp; {<br />
&nbsp; &nbsp; &nbsp; &nbsp; return partialSolution.size() == (2*n + 1)/3;<br />
&nbsp; &nbsp; }<br />
<br />
&nbsp; &nbsp; /**<br />
&nbsp; &nbsp;  * Check to see if two position attack each other<br />
&nbsp; &nbsp;  * @param p A position on the board (1-based)<br />
&nbsp; &nbsp;  * @param q A position on the board (1-based)<br />
&nbsp; &nbsp;  * @return true if they attack each other, false otherwise.<br />
&nbsp; &nbsp;  */<br />
&nbsp; &nbsp; static boolean attacks(Position p, Position q)<br />
&nbsp; &nbsp; {<br />
&nbsp; &nbsp; &nbsp; &nbsp; return p.row == q.row || p.col == q.col || p.row - p.col == q.row - q.col;<br />
&nbsp; &nbsp; }<br />
<br />
&nbsp; &nbsp; /**<br />
&nbsp; &nbsp;  * Checks to see a position attacks and position in a given list of<br />
&nbsp; &nbsp;  * positions.<br />
&nbsp; &nbsp;  * @param p a single position<br />
&nbsp; &nbsp;  * @param posList a list of positions<br />
&nbsp; &nbsp;  * @return true if p attacks at least one position in posList<br />
&nbsp; &nbsp;  */<br />
&nbsp; &nbsp; static boolean attacks(Position p, List&lt;Position&gt; posList)<br />
&nbsp; &nbsp; {<br />
&nbsp; &nbsp; &nbsp; &nbsp; for (Position pos : posList)<br />
&nbsp; &nbsp; &nbsp; &nbsp; {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (attacks(p, pos)) return true;<br />
&nbsp; &nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; &nbsp; &nbsp; return false;<br />
&nbsp; &nbsp; }<br />
&nbsp; &nbsp; /**<br />
&nbsp; &nbsp;  * This method may not be needed. It removes from posList all positions<br />
&nbsp; &nbsp;  * that attack pos. It returns the list of positions removed in this manner.<br />
&nbsp; &nbsp;  * @param pos<br />
&nbsp; &nbsp;  * @param posList<br />
&nbsp; &nbsp;  * @return a list of all positions in posList, OTHER THAN pos, that attack<br />
&nbsp; &nbsp;  * pos.<br />
&nbsp; &nbsp;  */<br />
&nbsp; &nbsp; static List&lt;Position&gt; removeAttackers(Position pos, List&lt;Position&gt; posList)<br />
&nbsp; &nbsp; {<br />
&nbsp; &nbsp; &nbsp; &nbsp; List&lt;Position&gt; attackers = new ArrayList&lt;Position&gt;();<br />
&nbsp; &nbsp; &nbsp; &nbsp; for (int k = 0; k &lt; posList.size(); )<br />
&nbsp; &nbsp; &nbsp; &nbsp; {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Position p = posList.get(k);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (attacks(pos, p))<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; posList.remove(p);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (p != pos) attackers.add(p);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; else k++;<br />
&nbsp; &nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; &nbsp; &nbsp; return attackers;<br />
&nbsp; &nbsp; }<br />
&nbsp; &nbsp; /**<br />
&nbsp; &nbsp;  * Used to generate the list of 1-based triangular board positions.<br />
&nbsp; &nbsp;  * 1, 1 through n, n<br />
&nbsp; &nbsp;  * @param n<br />
&nbsp; &nbsp;  * @return list of triangular board positions.<br />
&nbsp; &nbsp;  */<br />
&nbsp; &nbsp; static List&lt;Position&gt; getBoardPositions(int n)<br />
&nbsp; &nbsp; {<br />
&nbsp; &nbsp; &nbsp; &nbsp; List&lt;Position&gt; boardPosition = new ArrayList&lt;Position&gt;();<br />
&nbsp; &nbsp; &nbsp; &nbsp; for (int row = 1; row &lt;= n; row ++)<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; for (int col = 1; col &lt;= row; col++)<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; boardPosition.add(new Position(row, col));<br />
&nbsp; &nbsp; &nbsp; &nbsp; return boardPosition;<br />
&nbsp; &nbsp; }<br />
<br />
&nbsp; &nbsp; /** Used for debugging<br />
&nbsp; &nbsp;  * Prints all Positions in a list<br />
&nbsp; &nbsp;  * @param posList<br />
&nbsp; &nbsp;  */<br />
&nbsp; &nbsp; static void println(List&lt;Position&gt;posList)<br />
&nbsp; &nbsp; {<br />
&nbsp; &nbsp; &nbsp; &nbsp; for (Position p : posList)<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; System.out.print(p + &quot; &quot;);<br />
&nbsp; &nbsp; &nbsp; &nbsp; System.out.println();<br />
&nbsp; &nbsp; }<br />
}<br />
<br />
/**<br />
&nbsp;* A position indicating on the board for the triangular<br />
&nbsp;* N queens problem.<br />
&nbsp;* @author gcm<br />
&nbsp;*/<br />
class Position<br />
{<br />
&nbsp; &nbsp; public final int row, col;<br />
&nbsp; &nbsp; public Position(int row, int col)<br />
&nbsp; &nbsp; {<br />
&nbsp; &nbsp; &nbsp; &nbsp; this.row = row; <br />
&nbsp; &nbsp; &nbsp; &nbsp; this.col = col;<br />
&nbsp; &nbsp; }<br />
&nbsp; &nbsp; public String toString()<br />
&nbsp; &nbsp; {<br />
&nbsp; &nbsp; &nbsp; &nbsp; return &quot;[&quot; + row + &quot;,&quot; + col + &quot;]&quot;;&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; }<br />
}<br />
<br />
// A Graphical view of the triangular board with the queens placed.<br />
// The constructor takes a list of queen positions and a board size<br />
// and creates a JPanel neatly showing the placement of the queens.<br />
class Board extends JPanel<br />
{<br />
&nbsp; &nbsp; private int n; // size of board<br />
&nbsp; &nbsp; Board(int n, List&lt;Position&gt; placements)<br />
&nbsp; &nbsp; {<br />
&nbsp; &nbsp; &nbsp; &nbsp; super(new GridLayout(n, 2*n-1));<br />
&nbsp; &nbsp; &nbsp; &nbsp; this.n = n;<br />
&nbsp; &nbsp; &nbsp; &nbsp; // create the labels to diplay the placements<br />
&nbsp; &nbsp; &nbsp; &nbsp; JTextField labels [][] = new JTextField[n][2*n-1];<br />
&nbsp; &nbsp; &nbsp; &nbsp; for (int row = 0; row &lt; n; row++)<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; for (int col = 0; col &lt; 2*n-1; col++)<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; labels[row][col] = new JTextField(&quot; &quot;);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; add(labels[row][col]);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; labels[row][col].setEditable(false);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; for (int r = 0; r &lt; n; r++)<br />
&nbsp; &nbsp; &nbsp; &nbsp; {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; int startCol = n-1-r;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; for (int k = 0; k &lt; r+1; k++)<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; labels[r][startCol + 2*k].setBackground(Color.YELLOW);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; &nbsp; &nbsp; // place the queens<br />
&nbsp; &nbsp; &nbsp; &nbsp; for (Position p : placements)<br />
&nbsp; &nbsp; &nbsp; &nbsp; {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; int r = p.row-1;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; int c = p.col-1;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //labels[r][c].setForeground(Color.RED);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //labels[r][c].setText(&quot;Q&quot;);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; labels[r][n-1 -r + 2*c].setForeground(Color.RED);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; labels[r][n-1 -r + 2*c].setText(&quot;Q&quot;);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; labels[r][n-1 -r + 2*c].setToolTipText(p.toString());<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; }<br />
<br />
}</code><hr />
</div>What I can't figure out how to do is the public static boolean extendQueensPlacement(Stack&lt;Position&gt; partialSol, int k, int n) method. I check to see if it is a complete solution and if it is I return true and if it is not a complete solution then I go through each board position and add to partialSol if it does not attack any position in partialSol.<br />
<br />
Now what I can't figure out how to do is when all board positions have been checked and partialSol is not a complete solution so backtrack and try another boardPosition. Not really sure how to do the backtracking.</div>

]]></content:encoded>
			<category domain="http://forums.devx.com/forumdisplay.php?f=104">Java</category>
			<dc:creator>justinsbabe5000</dc:creator>
			<guid isPermaLink="true">http://forums.devx.com/showthread.php?t=173245</guid>
		</item>
		<item>
			<title>What is Instance, Empty Constructor ....</title>
			<link>http://forums.devx.com/showthread.php?t=173219&amp;goto=newpost</link>
			<pubDate>Fri, 23 Oct 2009 13:48:55 GMT</pubDate>
			<description><![CDATA[K I did something like this and all ok now it return the true compare value


Code:
---------
public boolean equals(Object o)
{
System.out.println(o instanceof Moof);
System.out.println(((Moof)o).getMoofValue());
System.out.println(this.moofValue); //XXX
if ((o instanceof Moof) && (((Moof)o).getMoofValue() == this.moofValue))
{
return true;
}
else
{
return false;
}
---------
]]></description>
			<content:encoded><![CDATA[<div>K I did something like this and all ok now it return the true compare value<br />
<br />
<div style="margin:20px; margin-top:5px">
	<div class="smallfont" style="margin-bottom:2px">Code:</div>
	<hr /><code style="margin:0px" dir="ltr" style="text-align:left">public boolean equals(Object o)<br />
{<br />
System.out.println(o instanceof Moof);<br />
System.out.println(((Moof)o).getMoofValue());<br />
System.out.println(this.moofValue); //XXX<br />
if ((o instanceof Moof) &amp;&amp; (((Moof)o).getMoofValue() == this.moofValue))<br />
{<br />
return true;<br />
}<br />
else<br />
{<br />
return false;<br />
}</code><hr />
</div></div>

]]></content:encoded>
			<category domain="http://forums.devx.com/forumdisplay.php?f=104">Java</category>
			<dc:creator>tking88</dc:creator>
			<guid isPermaLink="true">http://forums.devx.com/showthread.php?t=173219</guid>
		</item>
	</channel>
</rss>
