CompleteExample.java.txt
上传用户:aonuowh
上传日期:2021-05-23
资源大小:35390k
文件大小:7k
- /* $Id: CompleteExample.java,v 1.2 2002/06/18 10:26:21 kousalya Exp $ */
- /* CompleteExample.java
- * Copyright (c) 1996-2003 AdventNet, Inc. All Rights Reserved.
- * Please read the associated COPYRIGHTS file for more details.
- */
- import javax.swing.*;
- import java.awt.*;
- import java.awt.event.*;
- import java.io.*;
- import com.adventnet.snmp.beans.*;
- import com.adventnet.snmp.ui.*;
- public class CompleteExample implements ResultListener, ActionListener {
-
- SnmpPoller poller = new SnmpPoller();
- SnmpTarget target = new SnmpTarget();
- PropertySettings pptysettings = new PropertySettings();
- LineGraphBean linegraph = new LineGraphBean();
- MibTree mibtree = new MibTree();
-
- JButton button = new JButton();
- JTextArea textfield = new JTextArea();
- JButton button1 = new JButton();
- JButton loadbutton = new JButton();
- JButton unloadbutton = new JButton();
- JButton describebutton = new JButton();
- JButton clearbutton = new JButton();
- JButton graphbutton = new JButton();
- JButton setbutton = new JButton();
- JTextField textfield1 = new JTextField();
- JLabel label = new JLabel();
- public static void main(String args[]) {
-
- CompleteExample builder = new CompleteExample();
- JFrame frame = new JFrame();
- frame.setVisible(true);
- frame.addWindowListener(new WindowAdapter()
- {
- public void windowClosing(WindowEvent evt)
- {
- System.exit(0);
- }
- });
- frame.setSize(800,600);
- frame.setTitle( " AdventNet SNMP Tutorial - Putting it all together" );
- frame.getContentPane().setLayout(null);
- frame.getContentPane().add(builder.textfield);
- builder.textfield.setBounds(220,180,390,235);
- frame.getContentPane().add(builder.loadbutton);
- builder.loadbutton.setBounds(10,10,105,35);
- builder.loadbutton.setText("Load MIB");
- frame.getContentPane().add(builder.unloadbutton);
- builder.unloadbutton.setBounds(115,10,105,35);
- builder.unloadbutton.setText("Unload MIB");
- frame.getContentPane().add(builder.button);
- builder.button.setBounds(220,10,105,35);
- builder.button.setText("GET");
- frame.getContentPane().add(builder.button1);
- builder.button1.setBounds(325,10,105,35);
- builder.button1.setText("GET NEXT");
- frame.getContentPane().add(builder.describebutton);
- builder.describebutton.setBounds(430,10,105,35);
- builder.describebutton.setText("Description");
-
- frame.getContentPane().add(builder.clearbutton);
- builder.clearbutton.setBounds(535,10,105,35);
- builder.clearbutton.setText("Clear");
-
- frame.getContentPane().add(builder.graphbutton);
- builder.graphbutton.setBounds(640,10,105,35);
- builder.graphbutton.setText("Graph");
-
- frame.getContentPane().add(builder.setbutton);
- builder.setbutton.setBounds(10,50,105,35);
- builder.setbutton.setText("SET");
-
- frame.getContentPane().add(builder.pptysettings);
- builder.pptysettings.setBounds(115,50,85,55);
- frame.getContentPane().add(builder.mibtree);
- builder.mibtree.setBounds(5,110,205,405);
-
- try {
- builder.mibtree.addMib("RFC1213-MIB");
- }
- catch (Exception ex) {
-
- }
-
- frame.getContentPane().add(builder.label);
- builder.label.setBounds(250,110,105,25);
- builder.label.setText("SET Value");
- frame.getContentPane().add(builder.textfield1);
- builder.textfield1.setBounds(330,110,140,25);
- builder.target.setTargetHost("localhost");
- builder.poller.setTargetHost("localhost");
-
- builder.pptysettings.addVetoableChangeListener(builder.target);
- builder.pptysettings.addVetoableChangeListener(builder.poller);
- builder.target.addResultListener(builder);
- builder.poller.addResultListener(builder.linegraph);
- builder.button.addActionListener(builder);
- builder.button1.addActionListener(builder);
- builder.loadbutton.addActionListener(builder);
- builder.unloadbutton.addActionListener(builder);
- builder.describebutton.addActionListener(builder);
- builder.clearbutton.addActionListener(builder);
- builder.graphbutton.addActionListener(builder);
- builder.setbutton.addActionListener(builder);
- frame.show();
- }
-
- public void actionPerformed(ActionEvent e) {
- if (e.getActionCommand().equals("Load MIB")) {
-
- JFileChooser filechooser = new JFileChooser();
- filechooser.showDialog(mibtree, "open");
- try {
- mibtree.addMib(filechooser.getSelectedFile().toString());
- }
- catch (Exception ex) {
- }
- }
- else if (e.getActionCommand().equals("Unload MIB")) {
-
- try {
- mibtree.deleteMib(mibtree.getSelectedMibModule().getName().toString());
- }
- catch (Exception ex) {
- }
-
- }
- else if (e.getActionCommand().equals("GET")) {
-
- target.setObjectID((mibtree.getSelectedMibNode().getNumberedOIDString().toString()+".0"));
- target.snmpGet();
- }
-
- else if (e.getActionCommand().equals("GET NEXT")) {
- target.snmpGetNext();
- }
- else if (e.getActionCommand().equals("Description")) {
-
- textfield.setText("Syntax:"+mibtree.getSelectedMibNode().getSyntax()+"n"+
- "Access:"+mibtree.getSelectedMibNode().printAccess()+"n"+
- "Status:"+mibtree.getSelectedMibNode().getStatus()+"n"+
- "Reference:"+mibtree.getSelectedMibNode().getReference()+"n"+
- "OID:"+mibtree.getSelectedMibNode().getNumberedOIDString()+"n"+
- "Node:"+mibtree.getSelectedMibNode().getOIDString()+"n"+
- "Description:"+mibtree.getSelectedMibNode().getDescription()+"n");
-
- }
- else if (e.getActionCommand().equals("Clear")) {
- textfield.setText("");
- textfield1.setText("");
- }
-
- else if (e.getActionCommand().equals("Graph")) {
-
-
- JFrame frame1 = new JFrame();
- frame1.setVisible(true);
- frame1.addWindowListener(new WindowAdapter()
- {
- public void windowClosing(WindowEvent evt)
- {
-
- }
- });
- frame1.setSize(247,228);
- frame1.setTitle( " Line Graph Bean" );
- frame1.getContentPane().setLayout(null);
- frame1.getContentPane().add(linegraph);
- linegraph.setBounds(5,10,230,205);
- poller.setObjectID((mibtree.getSelectedMibNode().getNumberedOIDString().toString()+".0"));
- }
-
- else if (e.getActionCommand().equals("SET")) {
-
- target.setObjectID((mibtree.getSelectedMibNode().getNumberedOIDString().toString()+".0"));
- try {
- target.snmpSet(textfield1.getText());
- }catch (Exception ex) {
- System.err.println("Set Error: "+ex.getMessage());
- }
- }
- }
-
-
- public void setNumericResult(long l){
-
- linegraph.setNumericResult(l);
- }
- public void setResult(ResultEvent result){
- try {
- System.out.println(result.getStringValue());
- textfield.setText("Response PDU received from " +target.getTargetHost()+ ", community: " + target.getCommunity()+"n"+
- "OBJECT ID: "+target.getObjectID()+"n"+
- "RESPONSE: "+result.getStringValue());
- } catch (DataException de) {
- System.out.println("Error in getting agent data: "+de +
- result.getErrorString());
- }
-
- }
-
-
- public void setStringResult(String s){
-
- }
- }
-