CreateDirDialog.java
上传用户:aonuowh
上传日期:2021-05-23
资源大小:35390k
文件大小:3k
源码类别:

SNMP编程

开发平台:

C/C++

  1. /* $Id: CreateDirDialog.java,v 1.3 2002/09/09 05:50:39 parasuraman Exp $ */
  2. /*
  3.  * @(#)CreateDirDialog.java
  4.  * Copyright (c) 1996-2002 AdventNet, Inc. All Rights Reserved.
  5.  * Please read the associated COPYRIGHTS file for more details.
  6.  */
  7. import java.applet.*;
  8. import java.awt.*;
  9. import java.awt.event.*;
  10. import java.util.*;
  11. public class CreateDirDialog extends Frame implements ActionListener {
  12.   LabeledTextField ltf =null;
  13.   ButtonPanel ok_close =null;
  14.   public SasClientFunction sframe;
  15.   Font fontb = new Font("Helvetica", Font.BOLD, 16);
  16.   Font font = new Font("Helvetica", Font.PLAIN, 16);
  17.   String advent = new String("AdventNet Create Directory Dialog");
  18.   /* This takes care of the look of CreateDirDialog */
  19.   public CreateDirDialog(String title, boolean modal, String prompt, String defaulttext, int txtlength) { 
  20.     super();
  21.     setTitle(new String(title + " : " + advent));
  22.     setBackground(Color.lightGray);
  23.     setLayout(new BorderLayout());
  24.     ltf = new LabeledTextField(prompt,defaulttext,txtlength);
  25. ltf.addActionListener(this);
  26.     add("Center", ltf);
  27.     String buttons[] = {"OK","Cancel"};
  28.     ok_close = new ButtonPanel(buttons);
  29.     Button[] butts = ok_close.getButtons();
  30. for (int i=0;i<butts.length;i++) butts[i].addActionListener(this);
  31.     add("South", ok_close);
  32.     setFont(fontb, font);
  33.     
  34. addWindowListener( new WindowAdapter() {
  35. public void windowClosing(WindowEvent e) {
  36. setVisible(false);
  37. }
  38. });
  39.     setSize(550,200);
  40.   }
  41.   /* set fonts to the buttons and TextField */
  42.   public void setFont(Font fontb, Font font) {
  43.     if (ltf != null)  ltf.setFont(fontb, font);
  44.     if (ok_close != null)  ok_close.setFont(fontb);
  45.     super.setFont(fontb);
  46.   }
  47.   boolean loading = false;  // to avoid loading MIBs twice
  48.   /* actions for OK and Cancel buttons */
  49.   public void actionPerformed(ActionEvent e) {
  50. if (loading) return;
  51. Component comp = (Component)e.getSource();
  52. if (comp instanceof Button) {
  53.         if (e.getActionCommand().equals("Cancel")) this.setVisible(false);
  54.         else if (e.getActionCommand().equals("OK")) {
  55. loading = true;
  56. setCursor(new Cursor(Cursor.WAIT_CURSOR));
  57. ((SasClientFunction)sframe).createDir(ltf.textfield.getText());
  58. setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
  59. this.setVisible(false);
  60.     }
  61.     }
  62. if (comp instanceof TextField) {
  63. loading = true;
  64. setCursor(new Cursor(Cursor.WAIT_CURSOR));
  65. ((SasClientFunction)sframe).createDir(ltf.textfield.getText());
  66. setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
  67. this.setVisible(false);
  68.     }
  69.   }
  70.   /** Allow another MIB load only if shown again */
  71.   public synchronized void setVisible(boolean flag) {
  72.     loading = false;
  73.     super.setVisible(flag);
  74.   }
  75.   
  76. }