⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 passworddialog.java

📁 Java灵感编程1-101之41-60
💻 JAVA
字号:
package passworddialog;import java.awt.*;import javax.swing.*;import com.borland.jbcl.layout.*;import java.awt.event.*;/** * <p>Title: Password Dialog Demo</p> * <p>Description: This is a Password Dialog demo</p> * <p>Copyright: Copyright (c) 2002</p> * <p>Company: d6-125</p> * @author Liujun * @version 1.0 */public class PasswordDialog extends JDialog {  JPanel panel1 = new JPanel();  XYLayout xYLayout1 = new XYLayout();  JLabel jLabel1 = new JLabel();  JLabel jLabel2 = new JLabel();  JTextField jTextField1 = new JTextField();  JButton jButton1 = new JButton();  JButton jButton2 = new JButton();  JPasswordField jPasswordField1 = new JPasswordField(); //定义私有变量OK   private boolean ok;  public PasswordDialog(Frame frame, String title, boolean modal) {    super(frame, title, modal);    try {      jbInit();      pack();    }    catch(Exception ex) {      ex.printStackTrace();    }  }  public PasswordDialog(JFrame parent)   {    this(parent, "连接数据库", true);   }  public PasswordDialog() {    this(null, "连接数据库", false);  }  void jbInit() throws Exception {    panel1.setLayout(xYLayout1);    jLabel1.setText("用户名:");    jLabel2.setText("密  码:");    jTextField1.setText("");    jButton1.setText("确认");    jButton1.addActionListener(new java.awt.event.ActionListener() {      public void actionPerformed(ActionEvent e) {        jButton1_actionPerformed(e);      }    });    jButton2.setToolTipText("");    jButton2.setText("取消");    jButton2.addActionListener(new java.awt.event.ActionListener() {      public void actionPerformed(ActionEvent e) {        jButton2_actionPerformed(e);      }    });    jPasswordField1.setText("");    panel1.add(jLabel2,  new XYConstraints(15, 72, -1, -1));    panel1.add(jLabel1, new XYConstraints(15, 32, -1, -1));    panel1.add(jTextField1, new XYConstraints(88, 32, 147, -1));    panel1.add(jButton1, new XYConstraints(39, 121, -1, -1));    panel1.add(jButton2, new XYConstraints(142, 119, -1, -1));    panel1.add(jPasswordField1,      new XYConstraints(88, 72, 147, -1));    this.getContentPane().add(panel1, BorderLayout.CENTER);  }   public boolean showDialog(ConnectInfo transfer)   {  jTextField1.setText(transfer.username);//设置用户名初值      jPasswordField1.setText(transfer.password);//设置密码初值      ok = false;//设置OK的初始值      show();//显示对话框并得到结果      if (ok)//满足条件则传递参数      {  transfer.username = jTextField1.getText();         transfer.password = new String(jPasswordField1.getPassword());      }      return ok;//返回传递参数与否   }  void jButton1_actionPerformed(ActionEvent e) {         ok = true;//传递参数         setVisible(false);  }  void jButton2_actionPerformed(ActionEvent e) {         setVisible(false);  }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -