Thursday, March 17, 2011

Scabies Worsening After Treatment

Dynamic Graph

Dynamic Graph

will now see how we can start building our simple graph step by step, our nodes can be placed and then go assigning the edges. This project was contributed by Michael Manjarres . Images







Code


Master Class



Classes package;


import javax.swing.JApplet;


public class Main extends JApplet {

public void init () {
l canvas = new Canvas (this);
l.setBounds (0, 0, 400, 400);
add (l);
}}


Canvas Class

Classes package;

import java.awt.Graphics;
import java.awt.Image;
import java.awt.event.MouseEvent;
java.awt.event.MouseListener import, import
java.awt.event.MouseMotionListener;
import java.util.ArrayList;
import java.util.List;
import javax.swing.JOptionPane;
import javax.swing.JPanel;

public class Canvas extends JPanel implements MouseListener, MouseMotionListener {

int x = 0, y = 0;
line line;
circle circle;
circle pulled = null;
List \u0026lt; circle> = new ArrayList ListCirculo \u0026lt; circle> ();
List \u0026lt; Online> will list = new ArrayList \u0026lt; Online> (); Home
p;

public Canvas (Principal prin) {
     p=prin;
        this.addMouseListener(this);
        this.addMouseMotionListener(this);
        this.setVisible(true);
        this.setDoubleBuffered(true);
    }

    public void anadirCirculo(int x, int y){
        circulo = new circulo(ListCirculo.size(),x,y);
        ListCirculo.add(circulo);
        repaint();
        p.repaint();
    }

    public void anadirLinea( int x, int y){
        try{
            linea = new linea (ListCirculo.get(x),ListCirculo.get(y));
            this.ListArista.add(linea);
repaint ();
p.repaint ();
} catch (IndexOutOfBoundsException e) {
JOptionPane.showMessageDialog (null, "In that meeting circle");
   }
    }

    @Override
    public void paintComponent(Graphics g){
     super.paintComponents(g);
     for (linea f:ListArista)
     {
     f.painter(g);
     }

     for (circulo f:ListCirculo)
     {
     f.painter(g,this);
     }

    }

    public void mouseClicked(MouseEvent e) {
        try{
         if(e.getButton()==1){
             x = e.getX();
             y = e.getY();
             anadirCirculo(x,y);
         }else
         {
             if(e.getButton()==3)
         {Int
ini = Integer.parseInt (JOptionPane.showInputDialog ("Number of inicual circle"));
int end = Integer.parseInt (JOptionPane.showInputDialog ("Number of final circle"));
; anadirLinea (ini, end);}
}
;} catch (Exception ex) {
}
;}

    public void mousePressed(MouseEvent e) {}

    public void mouseReleased(MouseEvent e) {}

    public void mouseEntered(MouseEvent e) {}

    public void mouseExited(MouseEvent e) {}

    public void mouseDragged(MouseEvent e) {
       if(jalada==null)
        {
           for (circulo f:ListCirculo)
           {
             if(f.jaladopor(e.getPoint()))
               {
                 jalada=f;
               }
             x=e.getPoint().x;
             y=e.getPoint().y;
             repaint();
             p.repaint();
            }
       }
       else{
           jalada.transladar(e.getPoint().x-x,e.getPoint().y-y);
           x=e.getPoint().x;
           y=e.getPoint().y;
           repaint();
           p.repaint();
           }
    }

    public void mouseMoved(MouseEvent e){
        jalada=null;
    }

}

Class
circle

Classes package;

import java.awt .*;
import javax.swing.ImageIcon;

public class circle {

int x, y, n;
Image image;

 public circulo(int n, int x, int y) {
        this.n=n;
        this.x=x;
        this.y=y;
        image = new ImageIcon(getClass().getResource("../Imagenes/esfera.png")).getImage();
    }

    public void painter(Graphics g,lienzo l) {
            g.drawImage(image, x-15, y-15, l);
            g.setColor(Color.RED);
            g.drawString(""+n, x-15, y-15);
            g.drawString(""+n, x-14, y-14);
        }

    public int getX() {
        return x;
    }

    public int getY() {
return y;}

getN public int () {
return n;}
transladar public void (int dx, int two) {
        this.x+=dx; this.y+=dy;
    }

    public void setImage(Image image) {
        this.image = image;
    }

    public boolean jaladopor(Point d) {
        if(d.distance(x, y) < =15) {
            return true;
        }
         else {
                return false;
}}}

Online Class

Classes package;

import java.awt.Color;
import java.awt.Graphics;

line {public class

initial circle, circle
ffinal;
Color color = Color.Black;

public line (initial circle, circle ffinal) {
this.inicial = initial
; this.ffinal = ffinal;
    }

    public void painter(Graphics g) {
        g.setColor(Color.BLUE);
        g.setColor(color);
        g.drawLine(inicial.getX(), inicial.getY(), ffinal.getX(), ffinal.getY());
    }

    public void setColor(Color color) {
        this.color = color;
    }

    public circulo getFfinal() {
        return ffinal;
    }

public
getInicial circle () {return
initial
}
}

Main class just creates a canvas and adds it to be shown. The Canvas class is responsible for displaying the graph, there are two lists which store the nodes and lines that have created, only to be drawn in the paintComponent method.

The class circle is the image that represents a node, also displays the node index. The online class has two nodes the initial and the final order to draw the line between these nodes.

Applet



The applet has a white background so the limit is not the applet on the page.

0 comments:

Post a Comment