1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
| package testjsp;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Image;
import java.io.IOException;
import javax.swing.JApplet;
public class TracerTraficTempRéel 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; // @jve:decl-index=0:
Image image; // @jve:decl-index=0:
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); // @jve:decl-index=0:
public void init() {
this.setSize(700, 210);
this.setBackground(Color.BLACK);
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 e2) {
// TODO Auto-generated catch block
e2.printStackTrace();
}
//try {
//th.sleep(10000);
//} catch (InterruptedException e2) {
// TODO Auto-generated catch block
// e2.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);
repaint();
try {
th.sleep(10000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
y0 = y1;
i = i + 10;
}
}
public void paint(Graphics g) {
System.out.println("paint()");
if(buffer==null){
image = createImage(700, 210);
buffer = image.getGraphics();
buffer.setColor(Color.GREEN);
buffer.drawLine(0, 200, 700, 200);
g.drawImage(image, 0, 0, this);
}
buffer.setColor(Color.RED);
buffer.drawLine(x1, 200 - point_T1, x2, 200 - point_T2);
g.drawImage(image, 0,0 , this);
System.out.println(point_T1 + " " + point_T2);
point_T1 = point_T2;
}
} // @jve:decl-index=0:visual-constraint="7,9" |
Partager