📄 propertydialog.java
字号:
interval = intervalText.getText(); if (standardSocketChoice.isSelected()) { socketType = SnmpContextBasisFace.STANDARD_SOCKET; } else if (tcpSocketChoice.isSelected()) { socketType = SnmpContextBasisFace.TCP_SOCKET; } else { socketType = SnmpContextBasisFace.NETSCAPE_SOCKET; } fireActionPerformed(e.getID(), e.getActionCommand(), e.getModifiers());}void applyButton_actionPerformed(ActionEvent e){ host = hostText.getText(); bindAddr = bindText.getText(); if (bindAddr.length() == 0) { bindAddr = null; } port = portText.getText(); community = communityText.getText(); interval = intervalText.getText(); if (standardSocketChoice.isSelected()) { socketType = SnmpContextBasisFace.STANDARD_SOCKET; } else if (tcpSocketChoice.isSelected()) { socketType = SnmpContextBasisFace.TCP_SOCKET; } else { socketType = SnmpContextBasisFace.NETSCAPE_SOCKET; } fireActionPerformed(e.getID(), e.getActionCommand(), e.getModifiers());}/** * Implements the ActionListener */public void actionPerformed(ActionEvent e){ Object src = e.getSource(); if (src == tryButton) { tryButton_actionPerformed(e); } else if (src == okButton) { okButton_actionPerformed(e); } else if (src == applyButton) { applyButton_actionPerformed(e); } else if (src == cancelButton) { cancelButton_actionPerformed(e); }}/** * Implements the PropertyChangeListener */public void propertyChange(PropertyChangeEvent e){ Object src = e.getSource(); if (src == reachableBean) { reachableBean_propertyChange(e); }}private void jbInit() { gridBagLayout1 = new GridBagLayout(); hostLabel = new JLabel(" Server: "); portLabel = new JLabel(" Port: "); commLabel = new JLabel(" Community Name: "); intLabel = new JLabel(" Update Interval: "); bindLabel = new JLabel(" Bind Address: "); host = "localhost"; port = "" + SnmpContextBasisFace.DEFAULT_PORT; community = "public"; interval = "5000"; bindAddr = null; socketType = SnmpContextBasisFace.STANDARD_SOCKET; hostText = new JTextField(host); bindText = new JTextField(bindAddr); portText = new JTextField(port); communityText = new JTextField(community); intervalText = new JTextField(interval); standardSocketChoice.setText(SnmpContextv3Face.STANDARD_SOCKET); netscapeSocketChoice.setText(SnmpContextv3Face.NETSCAPE_SOCKET); tcpSocketChoice.setText(SnmpContextv3Face.TCP_SOCKET); messageLabel = new JLabel(" "); reachableBean = new IsHostReachableBean(); tryButton = new JButton("Try connection"); okButton = new JButton("OK"); applyButton = new JButton("Apply"); cancelButton = new JButton("Cancel"); hostText.setBackground(Color.white); bindText.setBackground(Color.white); portText.setBackground(Color.white); communityText.setBackground(Color.white); intervalText.setBackground(Color.white); messageLabel.setBackground(Color.white); messageLabel.setOpaque(true); tryButton.addActionListener(this); okButton.addActionListener(this); applyButton.addActionListener(this); cancelButton.addActionListener(this); reachableBean.addPropertyChangeListener(this); this.getContentPane().setLayout(gridBagLayout1); this.setBackground(Color.lightGray); Container cont = this.getContentPane(); cont.add(hostLabel, getGridBagConstraints2(0, 0, 1, 1, 0.0, 0.0 ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 0, 0)); cont.add(hostText, getGridBagConstraints2(1, 0, 2, 1, 1.0, 0.0 ,GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 0, 0)); cont.add(portLabel, getGridBagConstraints2(0, 1, 1, 1, 0.0, 0.0 ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 0, 0)); cont.add(portText, getGridBagConstraints2(1, 1, 2, 1, 1.0, 0.0 ,GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 0, 0)); cont.add(commLabel, getGridBagConstraints2(0, 2, 1, 1, 0.0, 0.0 ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 0, 0)); cont.add(communityText, getGridBagConstraints2(1, 2, 2, 1, 1.0, 0.0 ,GridBagConstraints.EAST, GridBagConstraints.BOTH, new Insets(5, 5, 5, 5), 0, 0)); cont.add(bindLabel, getGridBagConstraints2(0, 3, 1, 1, 0.0, 0.0 ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 0, 0)); cont.add(bindText, getGridBagConstraints2(1, 3, 2, 1, 1.0, 0.0 ,GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 0, 0)); cont.add(intLabel, getGridBagConstraints2(0, 4, 1, 1, 0.0, 0.0 ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 0, 0)); cont.add(intervalText, getGridBagConstraints2(1, 4, 2, 1, 1.0, 0.0 ,GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 0, 0)); cont.add(socketPanel, getGridBagConstraints2(0, 5, 3, 1, 1.0, 0.0 ,GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(10, 10, 10, 10), 0, 0)); cont.add(tryButton, getGridBagConstraints2(0, 6, 3, 1, 1.0, 0.0 ,GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(10, 10, 10, 10), 0, 0)); cont.add(messageLabel, getGridBagConstraints2(0, 7, 3, 1, 1.0, 1.0 ,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(10, 10, 10, 10), 0, 0)); cont.add(okButton, getGridBagConstraints2(0, 8, 1, 1, 1.0, 0.0 ,GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(10, 2, 10, 2), 0, 0)); cont.add(applyButton, getGridBagConstraints2(1, 8, 1, 1, 0.5, 0.0 ,GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(10, 2, 10, 2), 0, 0)); cont.add(cancelButton, getGridBagConstraints2(2, 8, 1, 1, 0.5, 0.0 ,GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(10, 2, 10, 2), 0, 0)); socketPanel.add(standardSocketChoice, null); socketPanel.add(tcpSocketChoice, null); socketPanel.add(netscapeSocketChoice, null); this.addWindowListener(this);}GridBagConstraints getGridBagConstraints2( int x, int y, int w, int h, double wx, double wy, int anchor, int fill, Insets ins, int ix, int iy){ GridBagConstraints gc = new GridBagConstraints(); gc.gridx = x; gc.gridy = y; gc.gridwidth = w; gc.gridheight = h; gc.weightx = wx; gc.weighty = wy; gc.anchor = anchor; gc.fill = fill; gc.insets = ins; gc.ipadx = ix; gc.ipady = iy; return gc;} /** * Adds an action listener to be notified when the "Apply" or "OK" button * is pressed. * @see #removeActionListener */public synchronized void addActionListener(ActionListener l){ actionPerformedListener.addElement(l);}/** * Removes an action listener. * @see #addActionListener */public synchronized void removeActionListener(ActionListener l){ actionPerformedListener.removeElement(l);} /** * Fires a action event when the "Apply" or "OK" * button is pressed. * * @see #removeActionListener * @see #addActionListener * @see ActionEvent * @see ActionListener */protected void fireActionPerformed(int id, String comm, int modif){ Vector listeners; synchronized(this) { listeners = (Vector) actionPerformedListener.clone(); } ActionEvent event = new ActionEvent(this, id, comm, modif); int sz = listeners.size(); for (int i=0; i<sz; i++) { ActionListener l = (ActionListener) listeners.elementAt(i); l.actionPerformed(event); }}public void windowActivated(WindowEvent evt){}public void windowDeactivated(WindowEvent evt){}public void windowClosing(WindowEvent evt){ ActionEvent evt2 = new ActionEvent( cancelButton, // source ActionEvent.ACTION_PERFORMED, // id cancelButton.getText() // command ); cancelButton_actionPerformed(evt2);}public void windowClosed(WindowEvent evt){}public void windowIconified(WindowEvent evt){}public void windowDeiconified(WindowEvent evt){}public void windowOpened(WindowEvent evt){} }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -