home *** CD-ROM | disk | FTP | other *** search
/ BUG 15 / BUGCD1998_06.ISO / aplic / jbuilder / jruntime.z / PasswordDialog.java < prev    next >
Text File  |  1997-08-25  |  3KB  |  129 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.   XYLayout xYLayout1 = new XYLayout();
  23.   BevelPanel bevelPanel1 = new BevelPanel();
  24.   Button button1 = new Button();
  25.   Button button2 = new Button();
  26.   Label label1 = new Label();
  27.   TextField textField1 = new TextField();
  28.  
  29.   public PasswordDialog(Frame frame, String title, boolean modal) {
  30.     super(frame, title, modal);
  31.     try {
  32.       jbInit();
  33.     }
  34.     catch (Exception e) {
  35.       e.printStackTrace();
  36.     }
  37.     add(panel1);
  38.     pack();
  39.   }
  40.  
  41.   public PasswordDialog(Frame frame, String title) {
  42.     this(frame, title, false);
  43.   }
  44.  
  45.   public PasswordDialog(Frame frame) {
  46.     this(frame, "", false);
  47.   }
  48.  
  49.   public void jbInit() throws Exception {
  50.     xYLayout1.setWidth(318);
  51.     xYLayout1.setHeight(118);
  52.     button1.setLabel("OK");
  53.     button1.addActionListener(new PasswordDialog_button1_actionAdapter(this));
  54.     button2.setLabel("Cancel");
  55.     label1.setText("Enter Password");
  56.     textField1.setEchoChar('@');
  57.     button2.addActionListener(new PasswordDialog_button2_actionAdapter(this));
  58.     this.addWindowListener(new PasswordDialog_this_windowAdapter(this));
  59.     panel1.setLayout(xYLayout1);
  60.     panel1.add(bevelPanel1, new XYConstraints(9, 10, 298, 65));
  61.     bevelPanel1.add(label1, new XYConstraints(7, 2, 144, 24));
  62.     bevelPanel1.add(textField1, new XYConstraints(5, 24, 265, 25));
  63.     panel1.add(button1, new XYConstraints(61, 81, 74, 25));
  64.     panel1.add(button2, new XYConstraints(164, 81, 77, 25));
  65.   }
  66. //<Exclude>
  67.   // Test case
  68.   public static void main(String[] argv) {
  69.     DecoratedFrame frame = new DecoratedFrame();
  70.     frame.show();
  71.     PasswordDialog pd = new PasswordDialog(frame, "Test", true);
  72.     pd.show();
  73.     //Get any results here
  74.     System.out.println(pd.textField1.getText());
  75.     System.exit(0);
  76.   }
  77. //</Exclude>
  78.  
  79.   //OK
  80.   void button1_actionPerformed(ActionEvent e) {
  81.     dispose();
  82.   }
  83.  
  84.   //Cancel
  85.   void button2_actionPerformed(ActionEvent e) {
  86.     dispose();
  87.   }
  88.   
  89.   void this_windowClosing(WindowEvent e) {
  90.     dispose();
  91.   }
  92. }
  93.  
  94. class PasswordDialog_button1_actionAdapter implements ActionListener {
  95.   PasswordDialog adaptee;
  96.  
  97.   PasswordDialog_button1_actionAdapter(PasswordDialog adaptee) {
  98.     this.adaptee = adaptee;
  99.   }
  100.  
  101.   public void actionPerformed(ActionEvent e) {
  102.     adaptee.button1_actionPerformed(e);
  103.   }
  104. }
  105.  
  106. class PasswordDialog_button2_actionAdapter implements ActionListener {
  107.   PasswordDialog adaptee;
  108.  
  109.   PasswordDialog_button2_actionAdapter(PasswordDialog adaptee) {
  110.     this.adaptee = adaptee;
  111.   }
  112.  
  113.   public void actionPerformed(ActionEvent e) {
  114.     adaptee.button2_actionPerformed(e);
  115.   }
  116. }
  117.  
  118. class PasswordDialog_this_windowAdapter extends WindowAdapter {
  119.   PasswordDialog adaptee;
  120.  
  121.   PasswordDialog_this_windowAdapter(PasswordDialog adaptee) {
  122.     this.adaptee = adaptee;
  123.   }
  124.  
  125.   public void windowClosing(WindowEvent e) {
  126.     adaptee.this_windowClosing(e);
  127.   }
  128. }
  129.