1 package com.dwipal; 2 3 import javax.swing.*; 4 import java.awt.event.*; 5 import java.util.*; 6 import java.awt.GridLayout ; 7 8 public class DwSnmpSelectServerDialog { 9 10 DwSnmpSelectServerDialogImpl db; 11 12 public static void main(String s[]) { 13 DwSnmpSelectServerDialog sd=new DwSnmpSelectServerDialog(); 14 System.out.println(sd.show()); 15 } 16 17 public DwSnmpSelectServerDialog() { 18 } 19 20 21 public String [] show() { 22 db=new DwSnmpSelectServerDialogImpl(); 23 return db.getUserData(); 24 } 25 26 public String [] show(String ip,int port,String get,String set) { 27 db=new DwSnmpSelectServerDialogImpl(ip,port,get,set); 28 return db.getUserData(); 30 } 31 32 40 41 } 42 43 44 class DwSnmpSelectServerDialogImpl extends JDialog 45 implements ActionListener 46 { 47 JButton ipButtonOK; 48 JButton ipButtonCl; 49 JFrame ipFrame; 50 JTextField ipText1; 51 JTextField ipText2; 52 JTextField ipText3; 53 JTextField ipText4; 54 String returnString[]; 55 boolean flag; 56 57 public DwSnmpSelectServerDialogImpl() { 58 DwSnmpSelectServerDialogImplFunc("192.168.2.9",161,"public","private"); 59 60 } 61 62 public DwSnmpSelectServerDialogImpl(String ip,int port,String get,String set) { 63 DwSnmpSelectServerDialogImplFunc(ip,port,get,set); 64 } 65 66 public void DwSnmpSelectServerDialogImplFunc(String ip,int port,String get,String set) { 67 68 this.setModal(true); 69 returnString=null; 70 flag=false; 71 try{ 72 73 JPanel ipPane=new JPanel(new GridLayout (6,2)); 74 JLabel ipLabel1=new JLabel("IP Address "); 75 JLabel ipLabel2=new JLabel("Port "); 76 JLabel ipLabel3=new JLabel("Get Community "); 77 JLabel ipLabel4=new JLabel("Set Community "); 78 JLabel ipLabel5=new JLabel(" "); 79 JLabel ipLabel6=new JLabel(" "); 80 81 ipText1=new JTextField(ip); 82 ipText2=new JTextField(String.valueOf(port)); 83 ipText3=new JTextField(get); 84 ipText4=new JTextField(set); 85 86 ipPane.add(ipLabel1); 87 ipPane.add(ipText1); 88 ipPane.add(ipLabel2); 89 ipPane.add(ipText2); 90 ipPane.add(ipLabel3); 91 ipPane.add(ipText3); 92 ipPane.add(ipLabel4); 93 ipPane.add(ipText4); 94 ipPane.add(ipLabel5); 95 ipPane.add(ipLabel6); 96 97 ipButtonOK=new JButton("OK"); 98 ipButtonCl=new JButton("Cancel"); 99 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) return null; 117 return returnString; 118 } 119 120 public void actionPerformed(ActionEvent evt) 121 { 122 Object source=evt.getSource(); 123 if(source==ipButtonOK) { 124 returnString=new String [] { ipText1.getText(),ipText2.getText(),ipText3.getText(),ipText4.getText() }; 125 } 126 else returnString=null; 127 this.setVisible(false); 128 } 129 } 130 | Popular Tags |