settingsDemo.java
上传用户:aonuowh
上传日期:2021-05-23
资源大小:35390k
文件大小:3k
- /*
- $Id: settingsDemo.src,v 1.3 2002/09/09 05:35:19 tonyjpaul Exp $
- */
- /*
- * @(#)settingsDemo.java
- * Copyright (c) 1996-2002 AdventNet, Inc. All Rights Reserved.
- * Please read the COPYRIGHTS file for more details.
- */
- /**
- * An example of using the SnmpRequestServer with the PropertySettings bean in your code.
- * This is an applet example.
- * Please refer settingsDemo.html for parameters.
- **/
- import java.awt.*;
- import java.beans.*;
- import javax.swing.*;
- import java.awt.event.ActionListener;
- import java.awt.event.ActionEvent;
- import java.applet.Applet;
- import com.adventnet.snmp.beans.*;
- import com.adventnet.snmp.ui.*;
- public class settingsDemo extends Applet implements ActionListener
- {
-
- Label l1;
- Label l2;
- Button b1;
- TextField t1;
- TextField t2;
- SnmpRequestServer server; // The server class instance we'll use
- PropertySettings pass;
-
- /** The init method is first called for applets. **/
- public void init()
- {
-
- try {
- UIManager.setLookAndFeel( UIManager.getSystemLookAndFeelClassName());
- } catch (Exception e) {
- System.err.println("Couldn't use the system look and feel: "+ e);
- }
- setLayout(null);
- setBackground(Color.lightGray);
- pass = new PropertySettings(this);
-
-
- l1 = new Label( "OID" );
- l2 = new Label("Result");
- b1 = new Button();
- b1.setLabel("Get Agent Data");
- t1 = new TextField("The OID is shown here");
- t2 = new TextField("The data from the agent is shown here");
- //Listen for actions on button
- b1.addActionListener(this);
-
- pass.setBounds(70,20,100,45);
- add(pass);
-
- l1.reshape(30,90,100,35);
- this.add(l1);
- t1.reshape(150,90,250,35);
- this.add(t1);
- l2.reshape(30,140,100,35);
- this.add(l2);
- t2.reshape(150,140,250,35);
- this.add(t2);
-
- b1.setBounds(70, 200, 100, 25);
- add(b1);
-
-
-
-
- }
- /** The start method is called when page with applet is visited. **/
- public void start() {
- try {
- server = new SnmpRequestServer(this);
- pass.addVetoableChangeListener(server);
- // load MIBs to allow us to use names
- server.loadMibs( getParameter("MIBS") );
- server.setTargetHost( getParameter("HOSTNAME"));
- server.setObjectID( getParameter("OID") );
- t1.setText(server.getObjectID());
- server.setCommunity( getParameter("COMMUNITY") );
- } catch (Exception ex) {
- System.err.println("Error in starting applet: "+ex+":"+ex.getMessage());
- }
- // We need to add a listener to listen for responses
- ResultAdapter listener = new ResultAdapter() {
- // This method will be invoked when the response is received
- public void setResult( ResultEvent e ) {
- try
- {
-
- t2.setText(e.getStringValue());
- } catch (DataException de) {
- System.err.println("Error in getting agent data: "+de +
- e.getErrorString());
- }
- }
- };
- server.addResultListener(listener); // register for responses
- }
- /** This method is called when the button is clicked **/
- public void actionPerformed(ActionEvent e)
- {
- server.setObjectID(t1.getText());
- RequestEvent evt = new RequestEvent(b1, server.getObjectID(), RequestEvent.GET);
- server.addRequest(evt);
-
- }
-
-
- }