info_nadia
Messages postés15Date d'inscriptionvendredi 4 novembre 2011StatutMembreDernière intervention 9 mai 2012
-
28 mars 2012 à 11:25
Bonjour,
j'ai un problème avec l'affichage dans l'interface graphique,j'utilise netbeans 6.9.1,je n'arrive pas à afficher le contenu de la variable trap.getObject(0) dans le JLabel (si je reçois une trap snmp j'affiche une lampe rouge sinon une lampe verte) voila
netbeans me demande que la variable HumLbl il faut qu'elle soit static et non pas private mais il me donne pas la main pour modifier le type
voici le code source:
/** Creates new form trap */
public void afficherphoto(){
ImageIcon tof1=new ImageIcon("C:/Documents and Settings/Administrator/Desktop/rouge.png");
TempLbl.setIcon(tof1);
ImageIcon tof2=new ImageIcon("C:/Documents and Settings/Administrator/Desktop/rouge.png");
HumLbl.setIcon(tof2);
}
public trap() {
initComponents();
ImageIcon tof1=new ImageIcon("C:/Documents and Settings/Administrator/Desktop/vert.png");
TempLbl.setIcon(tof1);
ImageIcon tof2=new ImageIcon("C:/Documents and Settings/Administrator/Desktop/vert.png");
HumLbl.setIcon(tof2);
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
TempLbl = new javax.swing.JLabel();
HumLbl = new javax.swing.JLabel();
private void TempLblAncestorAdded(javax.swing.event.AncestorEvent evt) {
// TODO add your handling code here:
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new trap().setVisible(true);
// instantiate a receiver object
SnmpTrapReceiver receiver = new SnmpTrapReceiver();
receiver.setPort( 162 );
// we need to instantiate a trap listener to listen for trap events
TrapListener listener = new TrapListener() {
//cette methode est appele lorsque la capture dune trap par SnmpTrapReceiver
public void receivedTrap(TrapEvent trap) {
System.out.println("Got a trap from: "+trap.getRemoteHost());
// print PDU details
/* System.out.println( ((SnmpTrapReceiver)trap.getSource())
.getMibOperations().toString(trap.getTrapPDU()) );*/
//cette instruction affiche ke le OID ca marche tres bien
System.out.println(trap.getObjectID(0));
if (trap.getObjectID(0).equals(".1.3.6.1.4.1.3699.1.1.3.100.2.0")){
ImageIcon tof3=new ImageIcon("C:/Documents and Settings/Administrator/Desktop/rouge.png");
HumLbl.setIcon(tof3);
}