wikiacademia

site
Back.

Node Creation and Information Retrieval

Application demonstrating the creation of nodes with attributes, and the retrieval and display of that information.
Screenshot

Explanation

buttonListener.java

Override the standard actionPerformed
public void actionPerformed(ActionEvent e){
If new button is pressed, get the value of the name and age fields and create a new table row
if ("new".equals(e.getActionCommand())){ int row = table.addRow(); String name = nameLabel.getText(); int age = Integer.parseInt(ageLabel.getText()); table.set(row, "Name", name); table.set(row, "Age", age); viz.run("draw"); }
If save button is pressed, open a JFileChooser to allow user to save, then use GraphMLWriter to write out file
if ("save".equals(e.getActionCommand())){ JFileChooser fs = new JFileChooser(); int returnval = fs.showSaveDialog(content); File save = fs.getSelectedFile(); System.out.println(save); GraphMLWriter write = new GraphMLWriter(); if (returnval == JFileChooser.APPROVE_OPTION) try{ write.writeGraph(graph, save); //tw.writeTable(table, save); }catch(Exception ex) { System.out.println("Unable to Save File! : " + ex.toString()); ex.printStackTrace(); } } }

GraphBuild

GraphBuild extends visualization, so it's actually a visualization itself. The process of creating the visualization is standard, but the following function is added to the end to allow for the updating of the graph :
public void addName(String newName, int newAge){ row = table.addRow(); table.set(row, "Name", newName); table.set(row, "Age", newAge); }

VizControlListener

overrides itemClicked. Retrives the name and age from the visualitem (the clicked node) and displays it in the displayfield.
public void itemClicked(VisualItem v, MouseEvent e){ String thisname = v.getString("Name"); String thisage = v.getString("Age"); displayField.setText(thisname + " is " + thisage); }

attachments [paper clip]

     name last modified size
[COD]application.java Dec 18 2006 11:08 am 201B [COD]buttonlistener.java Dec 18 2006 11:08 am 1.47kB [COD]graphbuild.java Dec 18 2006 11:08 am 3.63kB [COD]mainframe.java Dec 18 2006 11:08 am 3.90kB    nodecreate.jar Dec 18 2006 11:07 am 748kB [IMG]nodecreate.jpg Dec 18 2006 11:07 am 45.0kB [COD]vizcontrollistener.java Dec 18 2006 11:08 am 1.77kB