home *** CD-ROM | disk | FTP | other *** search
/ PC World 1998 October / PCWorld_1998-10_cd.bin / software / prehled / inprise / JRUNTIME.Z / PasswordDialog.java < prev    next >
Text File  |  1998-05-08  |  4KB  |  133 lines

  1. // This snippet creates a new dialog box
  2. // that prompts for a password
  3. // <File=PasswordDialog.java>
  4.  
  5. //Title:
  6. //Version:
  7. //Copyright:
  8. //Author:
  9. //Company:
  10. //Description:
  11. //
  12.  
  13. //<PACKAGE>
  14.  
  15. import java.awt.*;
  16. import java.awt.event.*;
  17. import borland.jbcl.layout.*;
  18. import borland.jbcl.control.*;
  19.  
  20. public class PasswordDialog extends Dialog {
  21.   Panel panel1 = new Panel();
  22.   Panel panel2 = new Panel();
  23.   Panel dialogPanel = new Panel();
  24.   BevelPanel bevelPanel1 = new BevelPanel();
  25.   Button button1 = new Button();
  26.   Button button2 = new Button();
  27.   Label label1 = new Label();
  28.   TextField textField1 = new TextField(24);
  29.   BorderLayout borderLayout1 = new BorderLayout();
  30.   BorderLayout borderLayout2 = new BorderLayout();
  31.   GridLayout gridLayout1 = new GridLayout();
  32.   FlowLayout flowLayout1 = new FlowLayout();
  33.  
  34.   public PasswordDialog(Frame frame, String title, boolean modal) {
  35.     super(frame, title, modal);
  36.     try {
  37.       jbInit();
  38.     }
  39.     catch (Exception e) {
  40.       e.printStackTrace();
  41.     }
  42.     add(dialogPanel,BorderLayout.CENTER);
  43.     //pack();
  44.   }
  45.  
  46.   public PasswordDialog(Frame frame, String title) {
  47.     this(frame, title, false);
  48.   }
  49.  
  50.   public PasswordDialog(Frame frame) {
  51.     this(frame, "", false);
  52.   }
  53.  
  54.   private void jbInit() throws Exception {
  55.     dialogPanel.setLayout(borderLayout2);
  56.     bevelPanel1.setLayout(borderLayout1);
  57.     button1.setLabel("OK");
  58.     button1.addActionListener(new PasswordDialog_button1_actionAdapter(this));
  59.     button2.setLabel("Cancel");
  60.     label1.setText("Enter Password");
  61.     textField1.setEchoChar('@');
  62.     gridLayout1.setVgap(4);
  63.     gridLayout1.setHgap(6);
  64.     button2.addActionListener(new PasswordDialog_button2_actionAdapter(this));
  65.     this.addWindowListener(new PasswordDialog_this_windowAdapter(this));
  66.     panel1.add(panel2);
  67.     bevelPanel1.setMargins(new Insets(4, 4, 4, 4));
  68.     panel2.setLayout(gridLayout1);
  69.     panel1.setLayout(flowLayout1);
  70.     dialogPanel.setSize(new Dimension(400, 100));
  71.     bevelPanel1.setBevelInner(BevelPanel.RAISED);
  72.     bevelPanel1.setBevelOuter(BevelPanel.LOWERED);
  73.     bevelPanel1.add(label1,BorderLayout.NORTH);
  74.     bevelPanel1.add(textField1,BorderLayout.SOUTH);
  75.     dialogPanel.add(panel1, BorderLayout.SOUTH);
  76.     panel2.add(button1);
  77.     panel2.add(button2);
  78.     dialogPanel.add(bevelPanel1,BorderLayout.CENTER);
  79.     pack();
  80.     textField1.requestFocus();
  81.   }
  82.  
  83.   //OK
  84.   void button1_actionPerformed(ActionEvent e) {
  85.     dispose();
  86.   }
  87.  
  88.   //Cancel
  89.   void button2_actionPerformed(ActionEvent e) {
  90.     dispose();
  91.   }
  92.  
  93.   void this_windowClosing(WindowEvent e) {
  94.     dispose();
  95.   }
  96. }
  97.  
  98. class PasswordDialog_button1_actionAdapter implements ActionListener {
  99.   PasswordDialog adaptee;
  100.  
  101.   PasswordDialog_button1_actionAdapter(PasswordDialog adaptee) {
  102.     this.adaptee = adaptee;
  103.   }
  104.  
  105.   public void actionPerformed(ActionEvent e) {
  106.     adaptee.button1_actionPerformed(e);
  107.   }
  108. }
  109.  
  110. class PasswordDialog_button2_actionAdapter implements ActionListener {
  111.   PasswordDialog adaptee;
  112.  
  113.   PasswordDialog_button2_actionAdapter(PasswordDialog adaptee) {
  114.     this.adaptee = adaptee;
  115.   }
  116.  
  117.   public void actionPerformed(ActionEvent e) {
  118.     adaptee.button2_actionPerformed(e);
  119.   }
  120. }
  121.  
  122. class PasswordDialog_this_windowAdapter extends WindowAdapter {
  123.   PasswordDialog adaptee;
  124.  
  125.   PasswordDialog_this_windowAdapter(PasswordDialog adaptee) {
  126.     this.adaptee = adaptee;
  127.   }
  128.  
  129.   public void windowClosing(WindowEvent e) {
  130.     adaptee.this_windowClosing(e);
  131.   }
  132. }
  133.