saslookup.java
上传用户:aonuowh
上传日期:2021-05-23
资源大小:35390k
文件大小:4k
- /* $Id: saslookup.java,v 1.3 2002/09/09 05:39:09 parasuraman Exp $ */
- /*
- * @(#)saslookup.java
- * Copyright (c) 1996-2002 AdventNet, Inc. All Rights Reserved.
- * Please read the associated COPYRIGHTS file for more details.
- */
- /**
- * This Applet does Address and Name Lookup.
- */
- import java.applet.*;
- import java.lang.*;
- import java.awt.*;
- import java.awt.event.*;
- import com.adventnet.snmp.snmp2.*;
- public class saslookup extends Applet implements ActionListener {
-
- TextArea text;
- TextField nameField, addressField, timeoutField;
- Button nameButton, addressButton;
- SASClient sasclient;
-
- public void init() {
-
- text = new TextArea( 10, 20);
- text.setEditable(false);
- Label nameLabel = new Label("HostName : ");
- Label addressLabel = new Label("Address : ");
- Label timeoutLabel = new Label("Timeout : ");
- Label unitLabel = new Label("MilliSeconds");
- nameField = new TextField(20);
- addressField = new TextField(20);
- timeoutField = new TextField("2000", 20);
- nameButton = new Button("Address Lookup");
- nameButton.addActionListener(this);
- addressButton = new Button(" Name Lookup ");
- addressButton.setActionCommand("Name Lookup");
- addressButton.addActionListener(this);
-
- GridBagLayout gridbag = new GridBagLayout();
- GridBagConstraints gc = new GridBagConstraints();
- Panel northPanel = new Panel();
- northPanel.setLayout(gridbag);
-
- gc.gridx = 0;
- gc.gridy = 0;
- gc.insets = new Insets(0, 0, 0, 0);
- gridbag.setConstraints(nameLabel, gc);
- northPanel.add(nameLabel);
-
- gc.gridx = 1;
- gc.gridy = 0;
- gc.insets = new Insets(0, 5, 0, 0);
- gridbag.setConstraints(nameField, gc);
- northPanel.add(nameField);
-
- gc.gridx = 2;
- gc.gridy = 0;
- gc.insets = new Insets(0, 5, 0, 0);
- gridbag.setConstraints(nameButton, gc);
- northPanel.add(nameButton);
-
- gc.gridx = 0;
- gc.gridy = 1;
- gc.insets = new Insets(5, 0, 0, 0);
- gridbag.setConstraints(addressLabel, gc);
- northPanel.add(addressLabel);
-
- gc.gridx = 1;
- gc.gridy = 1;
- gc.insets = new Insets(5, 5, 0, 0);
- gridbag.setConstraints(addressField, gc);
- northPanel.add(addressField);
-
- gc.gridx = 2;
- gc.gridy = 1;
- gc.insets = new Insets(5, 5, 0, 0);
- gridbag.setConstraints(addressButton, gc);
- northPanel.add(addressButton);
-
- gc.gridx = 0;
- gc.gridy = 2;
- gc.insets = new Insets(5, 0, 5, 0);
- gridbag.setConstraints(timeoutLabel, gc);
- northPanel.add(timeoutLabel);
-
- gc.gridx = 1;
- gc.gridy = 2;
- gc.insets = new Insets(5, 5, 5, 0);
- gridbag.setConstraints(timeoutField, gc);
- northPanel.add(timeoutField);
-
- gc.gridx = 2;
- gc.gridy = 2;
- gc.insets = new Insets(5, 0, 5, 0);
- gridbag.setConstraints(unitLabel, gc);
- northPanel.add(unitLabel);
-
- Panel southPanel = new Panel();
- Button clearButton = new Button("Clear");
- southPanel.add(clearButton);
- clearButton.addActionListener(this);
- setLayout(new BorderLayout());
- add("North", northPanel);
- add("Center", text);
- add("South", southPanel);
-
- try {
- sasclient = new SASClient(this, false);
- sasclient.start();
- }
- catch(SnmpException se) {
- text.append("Error : " + se.getMessage() + "n");
- }
- //SASClient is null if not connected to SAServer
- if(sasclient == null) {
- nameButton.setEnabled(false);
- addressButton.setEnabled(false);
- }
- }
-
- public void actionPerformed(ActionEvent e) {
-
- if(e.getActionCommand().equals("Address Lookup")) {
- int timeout = 0;
- try {
- timeout = Integer.parseInt(timeoutField.getText());
- }
- catch (Exception ex) {
- text.append("Invalid timeout. Default Timeout(2 Secs.) is set.n");
- }
- try {
- String address = sasclient.getHostAddress(nameField.getText(), timeout);
- text.append(nameField.getText() + ":" + address + "n");
- }
- catch (Exception ex) {
- text.append("Address Lookup failed. " + nameField.getText() + "n");
- }
- }
- else if(e.getActionCommand().equals("Name Lookup")) {
- int timeout = 0;
- try {
- timeout = Integer.parseInt(timeoutField.getText());
- }
- catch (Exception ex) {
- text.append("Invalid timeout. Default Timeout(2 Secs.) is set.n");
- }
- try {
- String name = sasclient.getHostName(addressField.getText(), timeout);
- text.append(name + ":" + addressField.getText() + "n");
- }
- catch (Exception ex) {
- text.append("Address Lookup failed. " + addressField.getText() + "n");
- }
- }
- else if(e.getActionCommand().equals("Clear")) {
- text.setText("");
- }
- }
-
- public void stop() {
-
- sasclient.stop();
- sasclient = null;
- }
-
- }