I created shopping cart using java Applets, PHP and HTML.
We need java run time to run the applet in browser. MS explorer has java console.
This is the HTML file--> In here each param value is passed according to a special format. That value tokenize using that format in the applet.
|
|
Java Applet -->
import java.util.*;
import java.awt.*;
import java.applet.Applet;
import java.applet.*;
import java.awt.event.*;
import javax.swing.*;
import java.net.*;
class Node extends Panel{
double x;
double y;
double dx;
double dy;
boolean fixed;
boolean visible=true;
boolean link=true;
String lbl;
}
class Edge {
int from;
int to;
double len;
}
class GraphPanel extends Panel
implements Runnable, MouseListener, MouseMotionListener {
Graph graph;
int nnodes;
Node nodes[] = new Node[100];
int nedges;
Edge edges[] = new Edge[200];
Thread relaxer;
GraphPanel(Graph graph) {
this.graph = graph;
addMouseListener(this);
}
int findNode(String lbl) {
for (int i = 0 ; i < nnodes ; i++) {
if (nodes[i].lbl.equals(lbl)) {
return i;
}
}
return addNode(lbl);
}
int addNode(String lbl) {
Node n = new Node();
n.x = 10 + 380*Math.random();
n.y = 10 + 380*Math.random();
n.lbl = lbl;
nodes[nnodes] = n;
nodes[nnodes].addMouseListener(this);
return nnodes++;
}
void addEdge(String from, String to, int len) {
Edge e = new Edge();
e.from = findNode(from);
e.to = findNode(to);
e.len = len;
edges[nedges++] = e;
}
public void run() {
Thread me = Thread.currentThread();
while (relaxer == me) {
relax();
//if (random && (Math.random() < 0.03)) {
if (Math.random() < 0.03) {
Node n = nodes[(int)(Math.random() * nnodes)];
if (!n.fixed) {
n.x += 100*Math.random() - 50;
n.y += 100*Math.random() - 50;
}
}
try {
Thread.sleep(100);
} catch (InterruptedException e) {
break;
}
}
}
synchronized void relax() {
for (int i = 0 ; i < nedges ; i++) {
Edge e = edges[i];
double vx = nodes[e.to].x - nodes[e.from].x;
double vy = nodes[e.to].y - nodes[e.from].y;
double len = Math.sqrt(vx * vx + vy * vy);
len = (len == 0) ? .0001 : len;
double f = (edges[i].len - len) / (len * 3);
double dx = f * vx;
double dy = f * vy;
nodes[e.to].dx += dx;
nodes[e.to].dy += dy;
nodes[e.from].dx += -dx;
nodes[e.from].dy += -dy;
}
for (int i = 0 ; i < nnodes ; i++) {
Node n1 = nodes[i];
double dx = 0;
double dy = 0;
for (int j = 0 ; j < nnodes ; j++) {
if (i == j) {
continue;
}
Node n2 = nodes[j];
double vx = n1.x - n2.x;
double vy = n1.y - n2.y;
double len = vx * vx + vy * vy;
if (len == 0) {
dx += Math.random();
dy += Math.random();
} else if (len < 100*100) {
dx += vx / len;
dy += vy / len;
}
}
double dlen = dx * dx + dy * dy;
if (dlen > 0) {
dlen = Math.sqrt(dlen) / 2;
n1.dx += dx / dlen;
n1.dy += dy / dlen;
}
}
Dimension d = getSize();
for (int i = 0 ; i < nnodes ; i++) {
Node n = nodes[i];
if (!n.fixed) {
n.x += Math.max(-5, Math.min(5, n.dx));
n.y += Math.max(-5, Math.min(5, n.dy));
}
if (n.x < 0) {
n.x = 0;
} else if (n.x > d.width) {
n.x = d.width;
}
if (n.y < 0) {
n.y = 0;
} else if (n.y > d.height) {
n.y = d.height;
}
n.dx /= 2;
n.dy /= 2;
}
repaint();
}
Node pick;
boolean pickfixed;
Image offscreen;
Dimension offscreensize;
Graphics offgraphics;
final Color fixedColor = Color.blue;
final Color selectColor = Color.gray;
final Color edgeColor = Color.black;
final Color nodeColor = new Color(100, 100, 100);
final Color arcColor1 = Color.black;
final Color arcColor2 = Color.pink;
final Color arcColor3 = Color.red;
public void paintNode(Graphics g, Node n, FontMetrics fm) {
int x = (int)n.x;
int y = (int)n.y;
g.setColor((n == pick) ? selectColor : (n.fixed ? fixedColor : nodeColor));
int w = fm.stringWidth(n.lbl) + 10;
int h = fm.getHeight() + 4;
g.fillRect(x - w/2, y - h / 2, w, h);
g.setColor(Color.black);
g.drawRect(x - w/2, y - h / 2, w-1, h-1);
g.drawString(n.lbl, x - (w-10)/2, (y - (h-4)/2) + fm.getAscent());
//this.update(g);
}
public synchronized void update(Graphics g) {
Dimension d = getSize();
if ((offscreen == null) || (d.width != offscreensize.width) || (d.height != offscreensize.height)) {
offscreen = createImage(d.width, d.height);
offscreensize = d;
if (offgraphics != null) {
offgraphics.dispose();
}
offgraphics = offscreen.getGraphics();
offgraphics.setFont(getFont());
}
offgraphics.setColor(getBackground());
offgraphics.fillRect(0, 0, d.width, d.height);
for (int i = 0 ; i < nedges ; i++) {
Edge e = edges[i];
if (nodes[e.from].visible==true && nodes[e.to].visible==true) {
int x1 = (int)nodes[e.from].x;
int y1 = (int)nodes[e.from].y;
int x2 = (int)nodes[e.to].x;
int y2 = (int)nodes[e.to].y;
int len = (int)Math.abs(Math.sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2)) - e.len);
offgraphics.setColor((len < 10) ? arcColor1 : (len < 20 ? arcColor2 : arcColor3)) ;
offgraphics.drawLine(x1, y1, x2, y2);}
}
FontMetrics fm = offgraphics.getFontMetrics();
for (int i = 0 ; i < nnodes ; i++) {
if(nodes[i].visible == true){
paintNode(offgraphics, nodes[i], fm);
}
}
g.drawImage(offscreen, 0, 0, null);
}
//1.1 event handling
//********************************************************************
public void mouseClicked(MouseEvent e) {
// nodes must visible here
}
public void setVisible(boolean b)
{
Node n1 = this.nodes[this.findNode(graph.center1)];
n1.visible=b;
Node n2 = this.nodes[this.findNode(graph.center2)];
n2.visible=b;
Node n3 = this.nodes[this.findNode(graph.center3)];
n3.visible=b;
Node n4 = this.nodes[this.findNode(graph.center4)];
n4.visible=b;
Node n5 = this.nodes[this.findNode(graph.center5)];
n5.visible=b;
Node n6 = this.nodes[this.findNode(graph.center6)];
n6.visible=b;
Node n7 = this.nodes[this.findNode(graph.center7)];
n7.visible=b;
Node n8 = this.nodes[this.findNode(graph.center8)];
n8.visible=b;
Node n9 = this.nodes[this.findNode(graph.center9)];
n9.visible=b;
Node n10 = this.nodes[this.findNode(graph.center10)];
n10.visible=b;
Node n11 = this.nodes[this.findNode(graph.center11)];
n11.visible=b;
Node n12 = this.nodes[this.findNode(graph.center12)];
n12.visible=b;
Node n13 = this.nodes[this.findNode(graph.center13)];
n13.visible=b;
Node n14 = this.nodes[this.findNode(graph.center14)];
n14.visible=b;
Node n15 = this.nodes[this.findNode(graph.center15)];
n15.visible=b;
Node n16 = this.nodes[this.findNode(graph.center16)];
n16.visible=b;
Node n17 = this.nodes[this.findNode(graph.center17)];
n17.visible=b;
}
public void hasLink()
{
Node n1 = this.nodes[this.findNode(graph.center1)];
n1.link=false;
Node n2 = this.nodes[this.findNode(graph.center2)];
n2.link=false;
Node n3 = this.nodes[this.findNode(graph.center3)];
n3.link=false;
Node n4 = this.nodes[this.findNode(graph.center4)];
n4.link=false;
Node n5 = this.nodes[this.findNode(graph.center5)];
n5.link=false;
Node n6 = this.nodes[this.findNode(graph.center6)];
n6.link=false;
Node n7 = this.nodes[this.findNode(graph.center7)];
n7.link=false;
Node n8 = this.nodes[this.findNode(graph.center8)];
n8.link=false;
Node n9 = this.nodes[this.findNode(graph.center9)];
n9.link=false;
Node n10 = this.nodes[this.findNode(graph.center10)];
n10.link=false;
Node n11 = this.nodes[this.findNode(graph.center11)];
n11.link=false;
Node n12 = this.nodes[this.findNode(graph.center12)];
n12.link=false;
Node n13 = this.nodes[this.findNode(graph.center13)];
n13.link=false;
Node n14 = this.nodes[this.findNode(graph.center14)];
n14.link=false;
Node n15 = this.nodes[this.findNode(graph.center15)];
n15.link=false;
Node n16 = this.nodes[this.findNode(graph.center16)];
n16.link=false;
Node n17 = this.nodes[this.findNode(graph.center17)];
n17.link=false;
}
public void mousePressed(MouseEvent e) {
this.setVisible(false);
this.hasLink();
//addMouseMotionListener(this);
double bestdist = Double.MAX_VALUE;
int x = e.getX();
int y = e.getY();
for (int i = 0 ; i < nnodes ; i++) {
Node n = nodes[i];
double dist = (n.x - x) * (n.x - x) + (n.y - y) * (n.y - y);
if (dist < bestdist) {
pick = n;
bestdist = dist;
}
else {
n.fixed = false;
n.visible=false;
}
}
pick.fixed = true;
pickfixed = pick.fixed;
pick.visible=true;
pick.x = x;
pick.y = y;
this.NodeDisplay(graph.center1, graph.edges1);
this.NodeDisplay(graph.center2, graph.edges2);
this.NodeDisplay(graph.center3, graph.edges3);
this.NodeDisplay(graph.center4, graph.edges4);
this.NodeDisplay(graph.center5, graph.edges5);
this.NodeDisplay(graph.center6, graph.edges6);
this.NodeDisplay(graph.center7, graph.edges7);
this.NodeDisplay(graph.center8, graph.edges8);
this.NodeDisplay(graph.center9, graph.edges9);
this.NodeDisplay(graph.center10, graph.edges10);
this.NodeDisplay(graph.center11, graph.edges11);
this.NodeDisplay(graph.center12, graph.edges12);
this.NodeDisplay(graph.center13, graph.edges13);
this.NodeDisplay(graph.center14, graph.edges14);
this.NodeDisplay(graph.center15, graph.edges15);
this.NodeDisplay(graph.center16, graph.edges16);
this.NodeDisplay(graph.center17, graph.edges17);
this.selectNode(pick);
repaint();
e.consume();
}
public void selectNode(Node n)
{
if(n.link == true)
{
if(pick.lbl.equals("Apples"))
{
try{
AppletContext a= graph.getAppletContext();
a.showDocument(new URL("http://charlie.it.uts.edu.au/ ~kgkmohan/Applet/index.php?pid=3007"),"_parent");
}
catch(Exception me)
{
JFrame frame = new JFrame("Show Message Dialog");
frame.setVisible(true);
JOptionPane.showMessageDialog(frame," Exception..... ");
}
}
else if(n.lbl.equals("Grapes"))
{
try{
AppletContext a= graph.getAppletContext();
a.showDocument(new URL("http://charlie.it.uts.edu.au/ ~kgkmohan/Applet/index.php?pid=3006"),"_parent");
}
catch(Exception me)
{
JFrame frame = new JFrame("Show Message Dialog");
frame.setVisible(true);
JOptionPane.showMessageDialog(frame," Exception..... ");
}
}
else if(n.lbl.equals("Peaches"))
{
try{
AppletContext a= graph.getAppletContext();
a.showDocument(new URL("http://charlie.it.uts.edu.au/ ~kgkmohan/Applet/index.php?pid=3005"),"_parent");
}
catch(Exception me)
{
JFrame frame = new JFrame("Show Message Dialog");
frame.setVisible(true);
JOptionPane.showMessageDialog(frame," Exception..... ");
}
}
else if(n.lbl.equals("Bananas"))
{
try{
AppletContext a= graph.getAppletContext();
a.showDocument(new URL("http://charlie.it.uts.edu.au/ ~kgkmohan/Applet/index.php?pid=3004"),"_parent");
}
catch(Exception me)
{
JFrame frame = new JFrame("Show Message Dialog");
frame.setVisible(true);
JOptionPane.showMessageDialog(frame," Exception..... ");
}
}
else if(n.lbl.equals("Navel_Oranges"))
{
try{
AppletContext a= graph.getAppletContext();
a.showDocument(new URL("http://charlie.it.uts.edu.au/ ~kgkmohan/Applet/index.php?pid=3003"),"_parent");
}
catch(Exception me)
{
JFrame frame = new JFrame("Show Message Dialog");
frame.setVisible(true);
JOptionPane.showMessageDialog(frame," Exception..... ");
}
}
else if(n.lbl.equals("Cheddar_Cheese(1000g)"))
{
try{
AppletContext a= graph.getAppletContext();
a.showDocument(new URL("http://charlie.it.uts.edu.au/ ~kgkmohan/Applet/index.php?pid=3000"),"_parent");
}
catch(Exception me)
{
JFrame frame = new JFrame("Show Message Dialog");
frame.setVisible(true);
JOptionPane.showMessageDialog(frame," Exception..... ");
}
}
else if(n.lbl.equals("Cheddar_Cheese(500g)"))
{
try{
AppletContext a= graph.getAppletContext();
a.showDocument(new URL("http://charlie.it.uts.edu.au/ ~kgkmohan/Applet/index.php?pid=3001"),"_parent");
}
catch(Exception me)
{
JFrame frame = new JFrame("Show Message Dialog");
frame.setVisible(true);
JOptionPane.showMessageDialog(frame," Exception..... ");
}
}
else if(n.lbl.equals("T'Bone_Steak(500g)"))
{
try{
AppletContext a= graph.getAppletContext();
a.showDocument(new URL("http://charlie.it.uts.edu.au/ ~kgkmohan/Applet/index.php?pid=3002"),"_parent");
}
catch(Exception me)
{
JFrame frame = new JFrame("Show Message Dialog");
frame.setVisible(true);
JOptionPane.showMessageDialog(frame," Exception..... ");
}
}
else if(n.lbl.equals("Fish_Fingers(S)"))
{
try{
AppletContext a= graph.getAppletContext();
a.showDocument(new URL("http://charlie.it.uts.edu.au/ ~kgkmohan/Applet/index.php?pid=1001"),"_parent");
}
catch(Exception me)
{
JFrame frame = new JFrame("Show Message Dialog");
frame.setVisible(true);
JOptionPane.showMessageDialog(frame," Exception..... ");
}
}
else if(n.lbl.equals("Fish_Fingers(L)"))
{
try{
AppletContext a= graph.getAppletContext();
a.showDocument(new URL("http://charlie.it.uts.edu.au/ ~kgkmohan/Applet/index.php?pid=1000"),"_parent");
}
catch(Exception me)
{
JFrame frame = new JFrame("Show Message Dialog");
frame.setVisible(true);
JOptionPane.showMessageDialog(frame," Exception..... ");
}
}
else if(n.lbl.equals("Shelled_Prawns"))
{
try{
AppletContext a= graph.getAppletContext();
a.showDocument(new URL("http://charlie.it.uts.edu.au/ ~kgkmohan/Applet/index.php?pid=1003"),"_parent");
}
catch(Exception me)
{
JFrame frame = new JFrame("Show Message Dialog");
frame.setVisible(true);
JOptionPane.showMessageDialog(frame," Exception..... ");
}
}
else if(n.lbl.equals("Tub_Ice_Cream(S)"))
{
try{
AppletContext a= graph.getAppletContext();
a.showDocument(new URL("http://charlie.it.uts.edu.au/ ~kgkmohan/Applet/index.php?pid=1004"),"_parent");
}
catch(Exception me)
{
JFrame frame = new JFrame("Show Message Dialog");
frame.setVisible(true);
JOptionPane.showMessageDialog(frame," Exception..... ");
}
}
else if(n.lbl.equals("Tub_Ice_Cream(L)"))
{
try{
AppletContext a= graph.getAppletContext();
a.showDocument(new URL("http://charlie.it.uts.edu.au/ ~kgkmohan/Applet/index.php?pid=1005"),"_parent");
}
catch(Exception me)
{
JFrame frame = new JFrame("Show Message Dialog");
frame.setVisible(true);
JOptionPane.showMessageDialog(frame," Exception..... ");
}
}
else if(n.lbl.equals("HamburgerPatties"))
{
try{
AppletContext a= graph.getAppletContext();
a.showDocument(new URL("http://charlie.it.uts.edu.au/ ~kgkmohan/Applet/index.php?pid=1002"),"_parent");
}
catch(Exception me)
{
JFrame frame = new JFrame("Show Message Dialog");
frame.setVisible(true);
JOptionPane.showMessageDialog(frame," Exception..... ");
}
}
else if(n.lbl.equals("Earl_Grey_Tea_Bags(S)"))
{
try{
AppletContext a= graph.getAppletContext();
a.showDocument(new URL("http://charlie.it.uts.edu.au/ ~kgkmohan/Applet/index.php?pid=4000"),"_parent");
}
catch(Exception me)
{
JFrame frame = new JFrame("Show Message Dialog");
frame.setVisible(true);
JOptionPane.showMessageDialog(frame," Exception..... ");
}
}
else if(n.lbl.equals("Earl_Grey_Tea_Bags(M)"))
{
try{
AppletContext a= graph.getAppletContext();
a.showDocument(new URL("http://charlie.it.uts.edu.au/ ~kgkmohan/Applet/index.php?pid=4001"),"_parent");
}
catch(Exception me)
{
JFrame frame = new JFrame("Show Message Dialog");
frame.setVisible(true);
JOptionPane.showMessageDialog(frame," Exception..... ");
}
}
else if(n.lbl.equals("Earl_Grey_Tea_Bags(L)"))
{
try{
AppletContext a= graph.getAppletContext();
a.showDocument(new URL("http://charlie.it.uts.edu.au/ ~kgkmohan/Applet/index.php?pid=4002"),"_parent");
}
catch(Exception me)
{
JFrame frame = new JFrame("Show Message Dialog");
frame.setVisible(true);
JOptionPane.showMessageDialog(frame," Exception..... ");
}
}
else if(n.lbl.equals("Earl_Grey_Tea_Bags(L)"))
{
try{
AppletContext a= graph.getAppletContext();
a.showDocument(new URL("http://charlie.it.uts.edu.au/ ~kgkmohan/Applet/index.php?pid=4002"),"_parent");
}
catch(Exception me)
{
JFrame frame = new JFrame("Show Message Dialog");
frame.setVisible(true);
JOptionPane.showMessageDialog(frame," Exception..... ");
}
}
else if(n.lbl.equals("Instant_Coffee(S)"))
{
try{
AppletContext a= graph.getAppletContext();
a.showDocument(new URL("http://charlie.it.uts.edu.au/ ~kgkmohan/Applet/index.php?pid=4003"),"_parent");
}
catch(Exception me)
{
JFrame frame = new JFrame("Show Message Dialog");
frame.setVisible(true);
JOptionPane.showMessageDialog(frame," Exception..... ");
}
}
else if(n.lbl.equals("Instant_Coffee(L)"))
{
try{
AppletContext a= graph.getAppletContext();
a.showDocument(new URL("http://charlie.it.uts.edu.au/ ~kgkmohan/Applet/index.php?pid=4004"),"_parent");
}
catch(Exception me)
{
JFrame frame = new JFrame("Show Message Dialog");
frame.setVisible(true);
JOptionPane.showMessageDialog(frame," Exception..... ");
}
}
else if(n.lbl.equals("Choclate_Bar"))
{
try{
AppletContext a= graph.getAppletContext();
a.showDocument(new URL("http://charlie.it.uts.edu.au/ ~kgkmohan/Applet/index.php?pid=4005"),"_parent");
}
catch(Exception me)
{
JFrame frame = new JFrame("Show Message Dialog");
frame.setVisible(true);
JOptionPane.showMessageDialog(frame," Exception..... ");
}
}
else if(n.lbl.equals("Panadol(L)"))
{
try{
AppletContext a= graph.getAppletContext();
a.showDocument(new URL("http://charlie.it.uts.edu.au/ ~kgkmohan/Applet/index.php?pid=2001"),"_parent");
}
catch(Exception me)
{
JFrame frame = new JFrame("Show Message Dialog");
frame.setVisible(true);
JOptionPane.showMessageDialog(frame," Exception..... ");
}
}
else if(n.lbl.equals("Panadol(S)"))
{
try{
AppletContext a= graph.getAppletContext();
a.showDocument(new URL("http://charlie.it.uts.edu.au/ ~kgkmohan/Applet/index.php?pid=2000"),"_parent");
}
catch(Exception me)
{
JFrame frame = new JFrame("Show Message Dialog");
frame.setVisible(true);
JOptionPane.showMessageDialog(frame," Exception..... ");
}
}
else if(n.lbl.equals("Bath_Soap"))
{
try{
AppletContext a= graph.getAppletContext();
a.showDocument(new URL("http://charlie.it.uts.edu.au/ ~kgkmohan/Applet/index.php?pid=2002"),"_parent");
}
catch(Exception me)
{
JFrame frame = new JFrame("Show Message Dialog");
frame.setVisible(true);
JOptionPane.showMessageDialog(frame," Exception..... ");
}
}
else if(n.lbl.equals("Garbage_Bags_Small"))
{
try{
AppletContext a= graph.getAppletContext();
a.showDocument(new URL("http://charlie.it.uts.edu.au/ ~kgkmohan/Applet/index.php?pid=2003"),"_parent");
}
catch(Exception me)
{
JFrame frame = new JFrame("Show Message Dialog");
frame.setVisible(true);
JOptionPane.showMessageDialog(frame," Exception..... ");
}
}
else if(n.lbl.equals("Garbage_Bags_Large"))
{
try{
AppletContext a= graph.getAppletContext();
a.showDocument(new URL("http://charlie.it.uts.edu.au/ ~kgkmohan/Applet/index.php?pid=2004"),"_parent");
}
catch(Exception me)
{
JFrame frame = new JFrame("Show Message Dialog");
frame.setVisible(true);
JOptionPane.showMessageDialog(frame," Exception..... ");
}
}
else if(n.lbl.equals("Washing_Powder"))
{
try{
AppletContext a= graph.getAppletContext();
a.showDocument(new URL("http://charlie.it.uts.edu.au/ ~kgkmohan/Applet/index.php?pid=2005"),"_parent");
}
catch(Exception me)
{
JFrame frame = new JFrame("Show Message Dialog");
frame.setVisible(true);
JOptionPane.showMessageDialog(frame," Exception..... ");
}
}
else if(n.lbl.equals("Laundry_Bleach"))
{
try{
AppletContext a= graph.getAppletContext();
a.showDocument(new URL("http://charlie.it.uts.edu.au/ ~kgkmohan/Applet/index.php?pid=2006"),"_parent");
}
catch(Exception me)
{
JFrame frame = new JFrame("Show Message Dialog");
frame.setVisible(true);
JOptionPane.showMessageDialog(frame," Exception..... ");
}
}
else if(n.lbl.equals("Dry_dog_food(L)"))
{
try{
AppletContext a= graph.getAppletContext();
a.showDocument(new URL("http://charlie.it.uts.edu.au/ ~kgkmohan/Applet/index.php?pid=5000"),"_parent");
}
catch(Exception me)
{
JFrame frame = new JFrame("Show Message Dialog");
frame.setVisible(true);
JOptionPane.showMessageDialog(frame," Exception..... ");
}
}
else if(n.lbl.equals("Dry_dog_food(s)"))
{
try{
AppletContext a= graph.getAppletContext();
a.showDocument(new URL("http://charlie.it.uts.edu.au/ ~kgkmohan/Applet/index.php?pid=5001"),"_parent");
}
catch(Exception me)
{
JFrame frame = new JFrame("Show Message Dialog");
frame.setVisible(true);
JOptionPane.showMessageDialog(frame," Exception..... ");
}
}
else if(n.lbl.equals("Bird_food"))
{
try{
AppletContext a= graph.getAppletContext();
a.showDocument(new URL("http://charlie.it.uts.edu.au/ ~kgkmohan/Applet/index.php?pid=5002"),"_parent");
}
catch(Exception me)
{
JFrame frame = new JFrame("Show Message Dialog");
frame.setVisible(true);
JOptionPane.showMessageDialog(frame," Exception..... ");
}
}
else if(n.lbl.equals("cat_food"))
{
try{
AppletContext a= graph.getAppletContext();
a.showDocument(new URL("http://charlie.it.uts.edu.au/ ~kgkmohan/Applet/index.php?pid=5003"),"_parent");
}
catch(Exception me)
{
JFrame frame = new JFrame("Show Message Dialog");
frame.setVisible(true);
JOptionPane.showMessageDialog(frame," Exception..... ");
}
}
else if(n.lbl.equals("Fish_food"))
{
try{
AppletContext a= graph.getAppletContext();
a.showDocument(new URL("http://charlie.it.uts.edu.au/ ~kgkmohan/Applet/index.php?pid=5004"),"_parent");
}
catch(Exception me)
{
JFrame frame = new JFrame("Show Message Dialog");
frame.setVisible(true);
JOptionPane.showMessageDialog(frame," Exception..... ");
}
}
}
}
public void mouseReleased(MouseEvent e) {
removeMouseMotionListener(this);
if (pick != null) {
pick.x = e.getX();
pick.y = e.getY();
pick.fixed = pickfixed;
pick = null;
pick.visible=false;
}
repaint();
e.consume();
}
//********************************************************************
public void NodeDisplay(String str,String edge)
{
if (str != null){
Node n = this.nodes[this.findNode(str)];
if (n.equals(pick))
{
graph.token(str,edge);
n.x = graph.d.width / 2;
n.y = graph.d.height / 2;
n.fixed = true;
}
}
}
public void mouseEntered(MouseEvent e) {
}
public void mouseExited(MouseEvent e) {
}
public void mouseDragged(MouseEvent e) {
pick.x = e.getX();
pick.y = e.getY();
repaint();
e.consume();
}
/******** Apear Disapear nodes ..... ********/
public void mouseMoved(MouseEvent e) {
}
public void start() {
relaxer = new Thread(this);
relaxer.start();
}
public void stop() {
relaxer = null;
}
}
public class Graph extends Applet implements ActionListener, ItemListener {
GraphPanel panel;
Panel controlPanel;
String edges1, edges2, edges3, edges4, edges5, edges6, edges7, edges8, edges9, edges10, edges11, edges12, edges13, edges14, edges15, edges16, edges17;
String center1, center2, center3, center4, center5, center6, center7, center8, center9, center10, center11, center12, center13, center14, center15, center16, center17;
Dimension d;
public void init() {
setLayout(new BorderLayout());
panel = new GraphPanel(this);
//....
add("Center", panel);
controlPanel = new Panel();
edges1 = getParameter("edges1");
center1 = getParameter("center1");
edges2 = getParameter("edges2");
center2 = getParameter("center2");
edges3 = getParameter("edges3");
center3 = getParameter("center3");
edges4 = getParameter("edges4");
center4 = getParameter("center4");
edges5 = getParameter("edges5");
center5 = getParameter("center5");
edges6 = getParameter("edges6");
center6 = getParameter("center6");
edges7 = getParameter("edges7");
center7 = getParameter("center7");
edges8 = getParameter("edges8");
center8 = getParameter("center8");
edges9 = getParameter("edges9");
center9 = getParameter("center9");
edges10 = getParameter("edges10");
center10 = getParameter("center10");
edges11 = getParameter("edges11");
center11 = getParameter("center11");
edges12 = getParameter("edges12");
center12 = getParameter("center12");
edges13 = getParameter("edges13");
center13 = getParameter("center13");
edges14 = getParameter("edges14");
center14 = getParameter("center14");
edges15 = getParameter("edges15");
center15 = getParameter("center15");
edges16 = getParameter("edges16");
center16 = getParameter("center16");
edges17 = getParameter("edges17");
center17 = getParameter("center17");
d = getSize();
if (center1 != null){
Node n = panel.nodes[panel.findNode(center1)];
{
n.visible=true;
this.token(center1,edges1);
n.x = d.width / 2;
n.y = d.height / 2;
n.fixed = true;
// n.visible=false;
}
}
}
public void token(String center, String edges)
{
for (StringTokenizer t = new StringTokenizer(edges, ",") ; t.hasMoreTokens() ; ) {
String str = t.nextToken();
int i = str.indexOf('-');
if (i > 0) {
int len = 50;
int j = str.indexOf('/');
if (j > 0) {
len = Integer.valueOf(str.substring(j+1)).intValue();
str = str.substring(0, j);
}
panel.addEdge(str.substring(0,i), str.substring(i+1), len);
Node n1 = panel.nodes[panel.findNode(str.substring(0,i))];
n1.visible=true;
Node n2 = panel.nodes[panel.findNode(str.substring(i+1))];
n2.visible=true;
}
}
}
public void destroy() {
remove(panel);
remove(controlPanel);
}
public void start() {
panel.start();
}
public void stop() {
panel.stop();
}
public void actionPerformed(ActionEvent e)
{
Node src = (Node)e.getSource();
}
public void itemStateChanged(ItemEvent e) {
Object src = e.getSource();
boolean on = e.getStateChange() == ItemEvent.SELECTED;
}
public String[][] getParameterInfo() {
String[][] info = {
{"edges", "delimited string", "A comma-delimited list of all the edges. It takes the form of 'C-N1,C-N2,C-N3,C-NX,N1-N2/M12,N2-N3/M23,N3-NX/M3X,...' where C is the name of center node (see 'center' parameter) and NX is a node attached to the center node. For the edges connecting nodes to eachother (and not to the center node) you may (optionally) specify a length MXY separated from the edge name by a forward slash."},
{"center", "string", "The name of the center node."}
};
return info;
}
}
No comments:
Post a Comment