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 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209
| import java.awt.Graphics;
import java.awt.Point;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.image.BufferedImage;
import java.awt.image.Raster;
import java.io.File;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.FileReader;
import javax.imageio.ImageIO;
import javax.swing.JComponent;
import javax.swing.JFrame;
import java.util.StringTokenizer;
public class Teste extends JFrame implements Runnable {
private static final long serialVersionUID = 4983727800375272097L;
int g=0;
int id=0;
BufferedImage img = null;
public Teste(int id) {
this.id=id;
System.out.println(id);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setSize(800, 600);
setLocationRelativeTo(null);
}
public void run()
{
try {
img = ImageIO.read(new File("c:/pc.jpeg"));//image a l'etat initiale
} catch (IOException e) {
e.printStackTrace();
}
setContentPane(new MyCanvas(img));
setVisible(true);
}
public static void main(String[] args) { int id=0;
Teste v=new Teste(0);
v.changeetat(id);
}
private class MyCanvas extends JComponent implements MouseListener {
private static final long serialVersionUID = 8845913940083986438L;
private BufferedImage buff = null;
private Raster data = null;
public MyCanvas(BufferedImage img) {
this.addMouseListener(this);
this.buff = img;
this.data = img.getData();
}
public void paintComponent(Graphics g) {
g.drawImage(buff, 0, 0, buff.getWidth(), buff.getHeight(), this);
}
private void testLocation(Point mouse, String text) {
if(data.getBounds().contains(mouse))
{
//Thread po=new Thread(new Interfacepc(id));c'est une classe ou il y a des autres interfaces
System.out.println("image"+id);
//po.start();
g++;
//po.setVisible(true);
}
}
public void mouseClicked(MouseEvent e) {
Point p = e.getPoint();
testLocation(p, "mouseClicked");
}
public void mousePressed(MouseEvent e) {
Point p = e.getPoint();
testLocation(p, "mousePressed");
}
public void mouseReleased(MouseEvent e) {
Point p = e.getPoint();
testLocation(p, "mouseReleased");
}
public void mouseEntered(MouseEvent e) { }
public void mouseExited(MouseEvent e) { }
}
public void changeetat( int id){
String ligne,ligne1;
String motA="";
String mot="";
String mott="";
String mot1="";
String mot2="";
String mot3="";
String mot4="";
String mot5="";
String com="";
String com1="";
try{
BufferedImage img = null;
BufferedReader fin1 = new BufferedReader(new FileReader("Test1.txt"));//le fichier test1 : fichier texte ou il y a
//la configuration de lhote c comme une basse de donnée
while((ligne1=fin1.readLine())!=null)
{ StringTokenizer st1=new StringTokenizer(ligne1," ,.;: ");
while(st1.hasMoreTokens())
{mot=st1.nextToken();
if(mot.equals("host_name"))
{ com=st1.nextToken();
System.out.println(com);
}
ligne1 +=ligne1+"\n";
if(mot.equals("HOST_ID"))
{ com1=st1.nextToken();
BufferedReader fin = new BufferedReader(new FileReader("log2.txt"));//le log file c est un fichier texte ou il y a l'etat des
//des hotes et des services
while((ligne=fin.readLine())!=null)
{StringTokenizer st=new StringTokenizer(ligne," ,.;: ");
System.out.println(ligne);
while(st.hasMoreTokens())
{
motA=st.nextToken();//motA contient [124542204] (exemple)
mott=st.nextToken();//mott contient CURREN
mot1=st.nextToken();//mot1 contient soit "HOST" soit "SERVICE"
mot2=st.nextToken();//mot2 contient "STAT"
mot3=st.nextToken();//le nom du host
mot4=st.nextToken();//ici si mot1= host alor mot4=etat(up or down)et si mot1=service alor mot4=nom de service
mot5=st.nextToken();//ici si mot1= host alor mot4=hard ou soft et si mot1=service alor mot4=etat du service(ok,warning,critial,unknown)
if(mot1.equals("host"))
{ if(mot3.equals(com))
{ if(mot4.equals("DOWN"))
{
try {
img = ImageIO.read(new File("c:/down.jpeg"));
} catch (IOException e) {e.printStackTrace();}
}
else if(mot4.equals("UP"))
{ try {
img = ImageIO.read(new File("c:/up.jpeg"));
} catch (IOException e) {e.printStackTrace();}
}
}
else if(mot4.equals("UP")&&(mot1.equals("SERVICE"))&&(mot3.equals("mot3")))//on peut avoir une hote est up mais elle a un service
// qui ne fonctionne pas
{if((mot5.equals("CRIICAL"))||(mot5.equals("UNKNOWN"))||(mot5.equals("WARNING")))
{ try {
img = ImageIO.read(new File("c:/panne.jpeg"));
} catch (IOException e) {e.printStackTrace();}
}
}
}
}
}
}
}
}
//fin.close();
fin1.close();
}
catch(IOException e)
{System.out.println(e.getMessage());}
}
} |
Partager