/** Application to allows graphical representation of graphs and finds shortest path among nodes. **/ import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.event.*; import javax.swing.colorchooser.*; public class spApp extends JFrame { public spApp () { // Create a window super("Tree of Colors"); //Make the panel with operations options and a text area for directions. final JPanel Tpanel = new JPanel(new FlowLayout()); Tpanel.setBorder(BorderFactory.createTitledBorder("Choose Graph Operation")); //create text area final JTextField text=new JTextField(50); text.setText("Click to make nodes; Press/Release to make edges."); text.setForeground(Color.yellow); text.setBackground(Color.blue); text.setOpaque(true); //Create a combo-box for choosing the mode of operation on the graph final String[] optionNames = {"Create Graph", "Find SP"}; final JLabel optionLabel = new JLabel("Operation:"); final JComboBox optionChoices = new JComboBox(optionNames); optionChoices.setSelectedIndex(0); optionChoices.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { // Get the size (16) switch (optionChoices.getSelectedIndex()) { case 0: text.setText("Click to make nodes; Press/release to make edges."); break; case 1: text.setText("Press/Release to choose source/destination nodes."); break; default: text.setText("Unknown Operation."); return; } } }); Tpanel.setLayout(new FlowLayout()); Tpanel.add(optionLabel); Tpanel.add(optionChoices); Tpanel.add(text); // Create a chooser final JColorChooser c=new JColorChooser(Color.blue); c.setBorder(BorderFactory.createTitledBorder("Choose A Node Color")); //Create the tree and the treeImage object final graphImage g = new graphImage(c,optionChoices,text); //make scroll pane for the graphImage final JScrollPane scrollPane = new JScrollPane(g); JPanel drawingPanel = new JPanel(new BorderLayout()); drawingPanel.add(scrollPane, BorderLayout.CENTER); drawingPanel.setBorder(BorderFactory.createTitledBorder("Graph Image")); //add components getContentPane().add(Tpanel, BorderLayout.NORTH); getContentPane().add(drawingPanel, BorderLayout.CENTER); getContentPane().add(c, BorderLayout.SOUTH); } /** Create an instance of the application **/ public static void main(String args[]) { spApp app= new spApp(); //Finish setting up the frame, and show it. app.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }); try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName() // "com.sun.java.swing.plaf.motif.MotifLookAndFeel" // "com.sun.java.swing.plaf.windows.WindowsLookAndFeel" // "javax.swing.plaf.mac.MacLookAndFeel" ); } catch (Exception e) { System.err.println(e.getMessage()); } SwingUtilities.updateComponentTreeUI(app); app.pack(); app.setVisible(true); } }