Probleme graph courbe applet java

thesnake201 Messages postés 5 Date d'inscription dimanche 21 octobre 2007 Statut Membre Dernière intervention 8 juin 2009 - 31 mai 2009 à 02:36
laguchori Messages postés 62 Date d'inscription mardi 26 octobre 2010 Statut Membre Dernière intervention 13 janvier 2012 - 28 oct. 2010 à 04:13
Bonjour
j'ai un ptit probleme dans mon applet java. Elle me permet de faire tracer une courbe pour le trafic réseau (j'utilise snmp pour faire ca)
mon probleme c'est que je n'ai pas su comment faire tracer des ligne en % de la valeur maximale eu
ca veut dire si il y a un grand trafic sur le réseau (valeur trés grande) la ligne peut dépassé la taille maximale de mon applet
voila mon code stp aide moi c'est dans le cadre de mon projet de fin d'étude et je n'ai plus beaucoup de temp


package testjsp;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Image;
import java.io.IOException;

import javax.swing.JApplet;

public class TracerTraficTempReel extends JApplet implements Runnable {
    int i = 0;    int x1 0, x2 0, y1 = 0, y2 = 0, y0 = 0;    int point_T1 0, point_T2 0;
    int result = 0;
    Graphics buffer;
    Image image;
    Thread th = null;
    boolean threadSuspended;
    static final int[] Tab_OID_IfinOctet = new int[] { 1, 3, 6, 1, 2, 1, 2, 2,
            1, 10, 5 };
    static EnvoieRequete Envoyer_Requete_Inoctet = new EnvoieRequete(
            "udp:127.0.0.1/161", "public", Tab_OID_IfinOctet);

    public void init() {
        this.setSize(700, 210);
        this.setBackground(Color.BLACK);
        image = createImage(this.getWidth(), this.getHeight());
        buffer = image.getGraphics();
        System.out.println("Init()");
    }

    public void start() {
        if (th == null) {
            System.out.println("start(): creating thread");
            th = new Thread(this);
            System.out.println("start(): starting thread");
            threadSuspended = false;
            th.start();
        } else {
            if (threadSuspended) {
                threadSuspended = false;
                System.out.println("start(): notifying thread");
                synchronized (this) {
                    notify();
                }
            }
        }

    }

    public void run() {
        point_T2 = 0;
        System.out.println("run()");
        try {
            y0 = Envoyer_Requete_Inoctet.SendRequest("udp:127.0.0.1/161",
                    "public", Tab_OID_IfinOctet);
        } catch (IOException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }
        while (true) {
            System.out.println(i);

            try {
                y1 = Envoyer_Requete_Inoctet.SendRequest("udp:127.0.0.1/161",
                        "public", Tab_OID_IfinOctet);
            } catch (IOException e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            }
            System.out.println(" y1  " + y1);
            x1 = x2;

            System.out.println("Somme = " + (((y1 - y0) / 5) * 0.0009765625));
            x2 = i + 10;
            point_T2 = (int) (((y1 - y0) / (x2 - x1)) * 0.0009765625);
            showStatus("i is " + i);
            buffer.translate(0, 0);
            dessine();

            try {
                th.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            y0 = y1;
            i = i + 10;
        }
    }

    private void dessine() {
        buffer.setColor(Color.RED);
        buffer.drawLine(x1, 200 - point_T1, x2, 200 - point_T2);
        
        repaint();

        System.out.println(point_T1 + "    " + point_T2);
        point_T1 = point_T2;
    }

    public void paint(Graphics g) {
        if (i == 0) {
            System.out.println("paint()");
            buffer.setColor(Color.GREEN);
            buffer.drawLine(0, 200, 700, 200);
            buffer.setColor(Color.DARK_GRAY);
            for(int j = 0 ;j<200;j=j+10)
            {
                buffer.drawLine(0, j, 700, j);
            }
            for(int j = 0 ;j<700;j=j+10)
            {
                buffer.drawLine(j, 0, j, 200);
            }
        }
        g.drawImage(image, 0, 0, this);
        
    }
}



et merci encore

1 réponse

laguchori Messages postés 62 Date d'inscription mardi 26 octobre 2010 Statut Membre Dernière intervention 13 janvier 2012
28 oct. 2010 à 04:13
bonjour
ton probleme dans ce programme c'est que tu n'as meme pas definit l'objet envoieRequete et tu as fait un heritage de celle ci envoyer_requete_incorect et merci
0
Rejoignez-nous