SnmpSetUI.java.txt
上传用户:aonuowh
上传日期:2021-05-23
资源大小:35390k
文件大小:4k
- /* $Id: SnmpSetUI.java,v 1.2 2002/06/18 07:19:36 kousalya Exp $ */
- /* SnmpSetUI.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 com.adventnet.snmp.beans.*;
- import com.adventnet.snmp.ui.*;
- public class SnmpSetUI implements ActionListener {
-
- SnmpTarget target = new SnmpTarget();
- PropertySettings pptysettings = new PropertySettings();
- JTextArea textfield = new JTextArea();
- MibTree mibtree = new MibTree();
- JButton loadbutton = new JButton();
- JButton unloadbutton = new JButton();
- JButton setbutton = new JButton();
- JButton clearbutton = new JButton();
- JTextField textfield1 = new JTextField();
- JLabel label = new JLabel();
- public static void main(String args[]) {
-
- SnmpSetUI snmpops = new SnmpSetUI();
-
- JFrame frame = new JFrame();
- frame.setVisible(true);
- frame.addWindowListener(new WindowAdapter()
- {
- public void windowClosing(WindowEvent evt)
- {
- System.exit(0);
- }
- });
- frame.setSize(600,400);
- frame.setTitle( " AdventNet SNMP Tutorial - doing a SNMP Set operation" );
- frame.getContentPane().setLayout(null);
-
- frame.getContentPane().add(snmpops.label);
- snmpops.label.setBounds(105,40,105,25);
- snmpops.label.setText("SET Value");
- frame.getContentPane().add(snmpops.textfield1);
- snmpops.textfield1.setBounds(210,40,140,25);
- frame.getContentPane().add(snmpops.textfield);
- snmpops.textfield.setBounds(220,80,490,85);
-
- frame.getContentPane().add(snmpops.loadbutton);
- snmpops.loadbutton.setBounds(230,195,105,35);
- snmpops.loadbutton.setText("Load MIB");
- frame.getContentPane().add(snmpops.unloadbutton);
- snmpops.unloadbutton.setBounds(335,195,105,35);
- snmpops.unloadbutton.setText("Unload MIB");
- frame.getContentPane().add(snmpops.setbutton);
- snmpops.setbutton.setBounds(440,195,105,35);
- snmpops.setbutton.setText("SET");
-
- frame.getContentPane().add(snmpops.clearbutton);
- snmpops.clearbutton.setBounds(545,195,105,35);
- snmpops.clearbutton.setText("Clear");
- frame.getContentPane().add(snmpops.pptysettings);
- snmpops.pptysettings.setBounds(650,190,85,55);
- frame.getContentPane().add(snmpops.mibtree);
- snmpops.mibtree.setBounds(5,80,205,405);
-
- try {
- snmpops.mibtree.addMib("RFC1213-MIB");
- }
- catch (Exception ex) {
-
- }
-
- snmpops.target.setTargetHost("localhost");
- snmpops.pptysettings.addVetoableChangeListener(snmpops.target);
- snmpops.loadbutton.addActionListener(snmpops);
- snmpops.unloadbutton.addActionListener(snmpops);
- snmpops.setbutton.addActionListener(snmpops);
- snmpops.clearbutton.addActionListener(snmpops);
- 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("SET")) {
-
- target.setObjectID((mibtree.getSelectedMibNode().getNumberedOIDString().toString()+".0"));
- String response = null;
- try {
- response = target.snmpSet(textfield1.getText());
- }catch (Exception ex) {
- System.err.println("Set Error: "+ex.getMessage());
- }
- if(response == null) {
- textfield.setText("Response received from : " + target.getTargetHost() + " Error : " + target.getErrorString());
- }
- else {
- textfield.setText("Response PDU received from " +target.getTargetHost()+ ", community: " + target.getCommunity()+"n"+
- "OBJECT ID: "+target.getObjectID()+"n"+ "RESPONSE: "+ response);
- }
-
- }
- else if (e.getActionCommand().equals("Clear")) {
- textfield.setText("");
- }
- }
-
- }
-