private void sendRequest(BlockPdu pdu) { setButton.setEnabled(false); getButton.setEnabled(false); getNextButton.setEnabled(false); lmessage.setText("Sending request .."); lmessage.setBackground(Color.white); try { varbind var = pdu.getResponseVariableBinding(); AsnObjectId oid = var.getOid(); AsnObject res = var.getValue(); if (res != null) { toid.setText(oid.toString()); tvalue.setText(res.toString()); lmessage.setText("Received aswer "); lmessage.setBackground(Color.white); } else { lmessage.setText("Received no aswer "); lmessage.setBackground(Color.red); } } catch (PduException exc) { lmessage.setText("PduException: " + exc.getMessage()); lmessage.setBackground(Color.red); exc.printStackTrace(); } catch (java.io.IOException exc) { lmessage.setText("IOException: " + exc.getMessage()); lmessage.setBackground(Color.red); exc.printStackTrace(); } setButton.setEnabled(true); getButton.setEnabled(true); getNextButton.setEnabled(true); }
private void createContext(String host, String portStr, String comm, String socketType) { int port = SnmpContextBasisFace.DEFAULT_PORT; try { port = Integer.valueOf(portStr).intValue(); } catch (NumberFormatException exc) { } if (context != null) { context.destroy(); // context.dumpContexts("destroy"); } try { context = new SnmpContextPool(host, port, socketType); context.setCommunity(comm); // context.dumpContexts("create:"); System.out.println(context); } catch (java.io.IOException exc) { exc.printStackTrace(); } }
/** * Gets an image resource. * * @param strResourceFilename Name of the image file. * @param srcClass Class from which the location of the resource is determined. * @return Instance of an <code>Image</code>. */ public static Image getImageResourceFile(String strResourceFilename, Class srcClass) { PngImage pngImage = null; Image image = null; try { BufferedInputStream in = new BufferedInputStream(srcClass.getResourceAsStream(strResourceFilename)); if (in == null) { System.err.println("Image not found:" + strResourceFilename); return null; } if (strResourceFilename.endsWith(".png")) { pngImage = new PngImage(in); image = Toolkit.getDefaultToolkit().createImage(pngImage); } else { ByteArrayOutputStream out = new ByteArrayOutputStream(); copy(in, out); image = Toolkit.getDefaultToolkit().createImage(out.toByteArray()); } } catch (java.io.IOException e) { System.err.println("Unable to read image " + strResourceFilename + "."); e.printStackTrace(); } return (image); }