001: package com.dwipal;
002:
003: import javax.swing.*;
004: import java.awt.event.*;
005: import java.util.*;
006: import java.awt.GridLayout;
007:
008: public class DwSnmpSelectServerDialog {
009:
010: DwSnmpSelectServerDialogImpl db;
011:
012: public static void main(String s[]) {
013: DwSnmpSelectServerDialog sd = new DwSnmpSelectServerDialog();
014: System.out.println(sd.show());
015: }
016:
017: public DwSnmpSelectServerDialog() {
018: }
019:
020: public String[] show() {
021: db = new DwSnmpSelectServerDialogImpl();
022: return db.getUserData();
023: }
024:
025: public String[] show(String ip, int port, String get, String set) {
026: db = new DwSnmpSelectServerDialogImpl(ip, port, get, set);
027: //System.out.println("Showing for " + ip);
028: return db.getUserData();
029: }
030:
031: /*
032: public IPRecord getIPRec() {
033: String ip[]=db.getUserData();
034: if(ip==null) return null;
035: IPRecord ipRec=new IPRecord(ip[0],ip[1],ip[2],ip[3]);
036: return ipRec;
037: }
038: */
039:
040: }
041:
042: class DwSnmpSelectServerDialogImpl extends JDialog implements
043: ActionListener {
044: JButton ipButtonOK;
045: JButton ipButtonCl;
046: JFrame ipFrame;
047: JTextField ipText1;
048: JTextField ipText2;
049: JTextField ipText3;
050: JTextField ipText4;
051: String returnString[];
052: boolean flag;
053:
054: public DwSnmpSelectServerDialogImpl() {
055: DwSnmpSelectServerDialogImplFunc("192.168.2.9", 161, "public",
056: "private");
057:
058: }
059:
060: public DwSnmpSelectServerDialogImpl(String ip, int port,
061: String get, String set) {
062: DwSnmpSelectServerDialogImplFunc(ip, port, get, set);
063: }
064:
065: public void DwSnmpSelectServerDialogImplFunc(String ip, int port,
066: String get, String set) {
067:
068: this .setModal(true);
069: returnString = null;
070: flag = false;
071: try {
072:
073: JPanel ipPane = new JPanel(new GridLayout(6, 2));
074: JLabel ipLabel1 = new JLabel("IP Address ");
075: JLabel ipLabel2 = new JLabel("Port ");
076: JLabel ipLabel3 = new JLabel("Get Community ");
077: JLabel ipLabel4 = new JLabel("Set Community ");
078: JLabel ipLabel5 = new JLabel(" ");
079: JLabel ipLabel6 = new JLabel(" ");
080:
081: ipText1 = new JTextField(ip);
082: ipText2 = new JTextField(String.valueOf(port));
083: ipText3 = new JTextField(get);
084: ipText4 = new JTextField(set);
085:
086: ipPane.add(ipLabel1);
087: ipPane.add(ipText1);
088: ipPane.add(ipLabel2);
089: ipPane.add(ipText2);
090: ipPane.add(ipLabel3);
091: ipPane.add(ipText3);
092: ipPane.add(ipLabel4);
093: ipPane.add(ipText4);
094: ipPane.add(ipLabel5);
095: ipPane.add(ipLabel6);
096:
097: ipButtonOK = new JButton("OK");
098: ipButtonCl = new JButton("Cancel");
099: ipPane.add(ipButtonOK);
100: ipPane.add(ipButtonCl);
101:
102: ipButtonOK.addActionListener(this );
103: ipButtonCl.addActionListener(this );
104:
105: this .setLocation(200, 200);
106: this .setTitle("Please select a SNMP Server..");
107: this .setContentPane(ipPane);
108: this .setSize(250, 170);
109: this .setVisible(true);
110: } catch (Exception e) {
111: e.printStackTrace();
112: }
113: }
114:
115: public String[] getUserData() {
116: if (returnString == null)
117: return null;
118: return returnString;
119: }
120:
121: public void actionPerformed(ActionEvent evt) {
122: Object source = evt.getSource();
123: if (source == ipButtonOK) {
124: returnString = new String[] { ipText1.getText(),
125: ipText2.getText(), ipText3.getText(),
126: ipText4.getText() };
127: } else
128: returnString = null;
129: this .setVisible(false);
130: }
131: }
|