📄 snmpsample.java
字号:
tab.addTab("基本信息",pane0);
tab.addTab("流量信息",pane1);
tab.setPreferredSize(new Dimension(400,400));
this.add(tab);
this.setEnabled(true);
}
}
public static void main(String args[]) {
new SNMPSample();
}
class JPopupMenu1 extends JPanel{
JPopupMenu Popup = null;//声明一个全局(Global)并设置初始值为null的JPopupMenu组件.
DefaultMutableTreeNode root = new DefaultMutableTreeNode("监测数据");
JTree tree = new JTree(root);
private int i = 0;
private int childnum = 0;
public JPopupMenu1(){
int num=Num;
int i=0;
String s1=s0;
String c1=c0;
String[][] strbase=new String[1024][1024];
try
{
String itemID = "1.3.6.1.2.1.1.3.0";
InetAddress hostAddress = InetAddress.getByName(s1);
temp =itemIDtime(itemID,hostAddress, c1) ;
int version = 1; // SNMPv1
String[] baseIDs = { "1.3.6.1.2.1.2.2.1.1","1.3.6.1.2.1.2.2.1.4","1.3.6.1.2.1.2.2.1.5",
"1.3.6.1.2.1.2.2.1.10","1.3.6.1.2.1.2.2.1.11","1.3.6.1.2.1.2.2.1.12",
"1.3.6.1.2.1.2.2.1.13","1.3.6.1.2.1.2.2.1.14","1.3.6.1.2.1.2.2.1.15",
"1.3.6.1.2.1.2.2.1.16","1.3.6.1.2.1.2.2.1.17","1.3.6.1.2.1.2.2.1.18",
"1.3.6.1.2.1.2.2.1.19","1.3.6.1.2.1.2.2.1.20","1.3.6.1.2.1.2.2.1.21","1.3.6.1.2.1.2.2.1.2"};
treenodes=baseIDdone( baseIDs, hostAddress, c1) ;
for(num=0;num<treenodes;num++)
{
root.add(resulttree(datas,num,temp));
tree.getSelectionModel().setSelectionMode(TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION);
tree.setPreferredSize(new Dimension(300,10000));
tree.setRowHeight(20);
tree.setEnabled(true);
}
TreePath parentPath=tree.getSelectionPath();
this.add(new JScrollPane(tree),BorderLayout.CENTER);
PopupPanel pp = new PopupPanel();//new一个PopupPanel组件来放置JPopupMenu.
this.add(pp,BorderLayout.SOUTH);
}
catch(Exception ee)
{
System.out.println("Exception during SNMP operation: " + ee + "\n");
}
class ToolBarAction extends AbstractAction{
public ToolBarAction(String name,Icon icon){
super(name,icon);
}
public void actionPerformed(ActionEvent e){
try{
}catch(Exception ex){}
}
}//end of inner class ToolBarAction
/*本方法建立inner class PopupPanel.这个类继承JPanel并实作MouseListener,PopupMenuListener,ActionListener和
*ActionListener等3个Listener.MouseListener为处理鼠标事件的Listener,PopupMenuListener为Popup菜单事件的Listener,
*ActionListener则是大家最熟悉用来处理JMenuItem事件的Listener.
*/
//end of inner class PopupPanel
//将PopupPanel组件放置到窗口中.
}
public DefaultMutableTreeNode resulttree(BigInteger datas[][],int num,BigInteger temp){
BigInteger basetime=new BigInteger("10000");
String sss;
String[][] strbase=new String[1024][1024];
BigInteger term=new BigInteger("0");
String[] s=new String[10];
tempt[0]=datas[num][3].multiply(basetime);
tempt[1]=datas[num][9].multiply(basetime);
tempt[2]=datas[num][5].multiply(basetime);
tempt[3]=datas[num][11].multiply(basetime);
tempt[4]=datas[num][4].multiply(basetime);
tempt[5]=datas[num][10].multiply(basetime);
tempt[6]=datas[num][6].multiply(basetime);
tempt[7]=datas[num][12].multiply(basetime);
tempt[8]=datas[num][7].multiply(basetime);
tempt[9]=datas[num][13].multiply(basetime);
for(i=0;i<10;i++)
{
result[i] = tempt[i].divide(temp);
s[i]=result[i].toString();
sgetresult[num][i]=result[i].toString();
}
String ss=null;
String time=null;
ss=datas[num][2].toString();
String a=String.valueOf(5000);
time=temp.divide(new BigInteger("100")).toString();
temp=temp.divide(new BigInteger("100"));
if(i==0)
{
term=temp;
i++;
}
sss=temp.subtract(term).toString();
String[] str0= {" 接 收 字 节 速 率 : "," 发 送 字 节 速 率 : "," 接收广播/多点发送包速率: "," 发送广播/多点发送包速率: "," 接收单播/单点发送包速率: "," 发送单播/单点发送包速率: "," 接收丢包率 :"," 发送丢包率 :"," 接收错误率 :"," 发送错误率 :"," 连接时间 :","监测到端口的数量:","检测端口号" };
String[] Sdanwei={" 字节/秒 ", " 字节/秒 "," 包/秒 "," 包/秒 "," 包/秒 "," 包/秒 "," 包/秒 "," 包/秒 "," 包/秒 "," 包/秒 "};
String[] str1=new String[10];
for(int n=0;n<10;n++)
str1[n]=str0[n].concat(s[n]);
for(int n=0;n<10;n++)
strbase[num][n]=str1[n].concat(Sdanwei[n]);
DefaultMutableTreeNode root0= nodeInsert(strbase,num);
return root0;
}
public DefaultMutableTreeNode nodeInsert(String strbase[][],int num){
DefaultMutableTreeNode root1 = new DefaultMutableTreeNode("编号"+num+"--"+ifDescr[num]);
DefaultMutableTreeNode node0=new DefaultMutableTreeNode(strbase[num][0]);
DefaultMutableTreeNode node1=new DefaultMutableTreeNode(strbase[num][1]);
DefaultMutableTreeNode node2=new DefaultMutableTreeNode(strbase[num][2]);
DefaultMutableTreeNode node3=new DefaultMutableTreeNode(strbase[num][3]);
DefaultMutableTreeNode node4=new DefaultMutableTreeNode(strbase[num][4]);
DefaultMutableTreeNode node5=new DefaultMutableTreeNode(strbase[num][5]);
DefaultMutableTreeNode node6=new DefaultMutableTreeNode(strbase[num][6]);
DefaultMutableTreeNode node7=new DefaultMutableTreeNode(strbase[num][7]);
DefaultMutableTreeNode node8=new DefaultMutableTreeNode(strbase[num][8]);
DefaultMutableTreeNode node9=new DefaultMutableTreeNode(strbase[num][9]);
root1.add(node0);
root1.add(node1);
root1.add(node2);
root1.add(node3);
root1.add(node4);
root1.add(node5);
root1.add(node6);
root1.add(node7);
root1.add(node8);
root1.add(node9);
return root1;
} //end of JPopupMenu1()
class ToolBarAction extends AbstractAction{
public ToolBarAction(String name,Icon icon){
super(name,icon);
}
public void actionPerformed(ActionEvent e){
try{
}catch(Exception ex){}
}
}//end of inner class ToolBarAction
class PopupPanel extends JPanel implements MouseListener,PopupMenuListener,ActionListener{
JMenuItem theItem;
public PopupPanel(){
Popup = new JPopupMenu();//new 一个新的JPopupMenu.
Popup.add(theItem = new JMenuItem("设置阈值"));//建立JMenuItem组件.
theItem.addActionListener(this);//将JMenuItem组件加入事件处理模式.
Popup.add(theItem = new JMenuItem("察看阈值",new ImageIcon("icons/copy24.gif")));
theItem.addActionListener(this);
Popup.add(theItem = new JMenuItem("报警信息",new ImageIcon("icons/paste24.gif")));
theItem.addActionListener(this);
Popup.addSeparator();//在JPopupMenu中加入分隔线,我们在前面有提到JPopupMenu和Menu大致上的性质是一样的,所以
//在JPopupMenu中一样是以JMenuItem来当作选项的组件.
// Popup.add(theItem = new JMenuItem("Page Setup..."));
theItem.addActionListener(this);
Popup.setBorder(new BevelBorder(BevelBorder.RAISED));
Popup.addPopupMenuListener(this); //将JPopupMenu组件加入PopupMenu事件处理模式中.
addMouseListener(this);//将PopupPanel类加入Mouse事件处理模式中.
tree.addMouseListener(this);//后面有说明
}//end of PopupPanel()
public void mouseClicked(MouseEvent me){ checkPopup(me);}
public void mousePressed(MouseEvent me){ checkPopup(me);}
public void mouseReleased(MouseEvent me){ checkPopup(me);}
public void mouseEntered(MouseEvent me){}
public void mouseExited(MouseEvent me){}
private void checkPopup(MouseEvent me){
if(me.isPopupTrigger()){
Popup.show(me.getComponent(), me.getX(), me.getY());
}
}//end of checkPopup()
public void popupMenuWillBecomeVisible(PopupMenuEvent pme){
}
public void popupMenuWillBecomeInvisible(PopupMenuEvent pme){
}
public void popupMenuCanceled(PopupMenuEvent pme){
}
public void actionPerformed(ActionEvent ae){
String cmd=ae.getActionCommand();
if(cmd.equals("设置阈值"))
{
new SetLookDoor();
}
else if(cmd.equals("察看阈值")){
new GetSetDoor();
}
else if(cmd.equals("报警信息")){
int on=1;
getresultnow(on);
new Fireshow();
}
}
}
class SetLookDoor implements ActionListener{
JDialog dialog;
public void actionPerformed(ActionEvent e){
}
SetLookDoor(){
dialog = new JDialog();
Container dialogPane = dialog.getContentPane();
JLabel SetNum=new JLabel("请输入要设置得端口编号:");
JLabel SetNum1=new JLabel("");
getNum.setText("");
JButton button=new JButton("确定");
JButton buttonno=new JButton("取消");
dialogPane.add(SetNum);
dialogPane.add(getNum);
dialogPane.add(button);
dialogPane.add(buttonno);
dialogPane.add(SetNum1);
JLabel Setdoor1=new JLabel("接 收 字 节 速 率 :");
JLabel Setdoor2=new JLabel("发 送 字 节 速 率 : ");
JLabel Setdoor3=new JLabel("接收广播/多点发送包速率: ");
JLabel Setdoor4=new JLabel("发送广播/多点发送包速率: ");
JLabel Setdoor5=new JLabel("接收单播/单点发送包速率: ");
JLabel Setdoor6=new JLabel("发送单播/单点发送包速率: ");
JLabel Setdoor7=new JLabel(" 接收丢包率 :");
JLabel Setdoor8=new JLabel("发送丢包率 :");
JLabel Setdoor9=new JLabel("接收错误率 :");
JLabel Setdoor10=new JLabel("发送错误率 :");
JLabel Setdoor11=new JLabel("");
getset1.setText("");
getset2.setText("");
getset3.setText("");
getset4.setText("");
getset5.setText("");
getset6.setText("");
getset7.setText("");
getset8.setText("");
getset9.setText("");
getset10.setText("");
String danw1=" 字节/秒 ";
String danw2=" 包/秒 ";
SetNum.setBounds(70,20,160,25);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -