SnmpTrapdUI.java.txt
上传用户:aonuowh
上传日期:2021-05-23
资源大小:35390k
文件大小:2k
- /* $Id: SnmpTrapdUI.java,v 1.2 2002/06/18 07:20:13 kousalya Exp $ */
- /* SnmpTrapdUI.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 SnmpTrapdUI implements TrapListener, ActionListener
- {
- SnmpTrapReceiver trapreceiver = new SnmpTrapReceiver ();
- JTextArea textfield = new JTextArea ();
- JButton clearbutton = new JButton ();
- public static void main (String args[])
- {
- SnmpTrapdUI snmpops = new SnmpTrapdUI ();
- JFrame frame = new JFrame ();
- frame.setVisible (true);
- frame.addWindowListener (new WindowAdapter ()
- {
- public void windowClosing (WindowEvent evt)
- {
- System.exit (0);
- }
- }
- );
- frame.setSize (615, 400);
- frame.setTitle (" Tutorial Example for receiving SNMP Traps");
- frame.getContentPane ().setLayout (null);
- snmpops.trapreceiver.setPort (8001);
- frame.getContentPane ().add (snmpops.textfield);
- snmpops.textfield.setBounds (30, 80, 490, 120);
- snmpops.textfield.setText ("Waiting to receive traps in the port " + snmpops.trapreceiver.getPort () + ".......");
- frame.getContentPane ().add (snmpops.clearbutton);
- snmpops.clearbutton.setBounds (185, 225, 105, 35);
- snmpops.clearbutton.setText ("Clear");
- snmpops.trapreceiver.addTrapListener (snmpops);
- snmpops.clearbutton.addActionListener (snmpops);
- frame.show();
- }
- public void actionPerformed (ActionEvent e)
- {
- textfield.setText ("Waiting to receive traps in the port " + trapreceiver.getPort () + ".......");
- }
- public void receivedTrap (TrapEvent trapEvent)
- {
- textfield.setText ("TrapEvent received." + "n" +
- "Received a trap from:" + trapEvent.getRemoteHost () + " in the port " + trapreceiver.getPort () + "n" +
- "Community is:" + trapEvent.getCommunity () + "n" +
- "Agent Address is:" + trapEvent.getAgentAddress () + "n" +
- "Enterprise OID:" + trapEvent.getEnterprise () + "n" +
- "Trap Variable OID:" + trapEvent.getObjectID (0) + "n" +
- "Continues waiting to receive traps in the port " + trapreceiver.getPort () + ".......");
- }
- }