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

📄 passworddialogframe.java

📁 Java灵感编程1-101之41-60
💻 JAVA
字号:
package passworddialog;import java.awt.*;import java.awt.event.*;import javax.swing.*;import com.borland.jbcl.layout.*;/** * <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 PasswordDialogFrame extends JFrame {  JPanel contentPane;  JButton jButton1 = new JButton();  XYLayout xYLayout1 = new XYLayout();  JLabel jLabel1 = new JLabel();  JLabel jLabel2 = new JLabel();  //定义一个密码对话框的私有变量  private PasswordDialog dialog = null;  //Construct the frame  public PasswordDialogFrame() {    enableEvents(AWTEvent.WINDOW_EVENT_MASK);    try {      jbInit();    }    catch(Exception e) {      e.printStackTrace();    }  }  //Component initialization  private void jbInit() throws Exception  {    //setIconImage(Toolkit.getDefaultToolkit().createImage(PasswordDialogFrame.class.getResource("[Your Icon]")));    contentPane = (JPanel) this.getContentPane();    jButton1.setText("连接数据库");    jButton1.addActionListener(new java.awt.event.ActionListener() {      public void actionPerformed(ActionEvent e) {        jButton1_actionPerformed(e);      }    });    contentPane.setLayout(xYLayout1);    this.setSize(new Dimension(400, 129));    this.setTitle("Password Dialog Frame Demo");    jLabel1.setText("用户名 ==");    jLabel2.setText("密码==");    contentPane.add(jLabel1,      new XYConstraints(49, 51, 305, 16));    contentPane.add(jLabel2,  new XYConstraints(49, 76, 305, 16));    contentPane.add(jButton1, new XYConstraints(0, 0, 400, -1));  }  //Overridden so we can exit when window is closed  protected void processWindowEvent(WindowEvent e) {    super.processWindowEvent(e);    if (e.getID() == WindowEvent.WINDOW_CLOSING) {      System.exit(0);    }  }  void jButton1_actionPerformed(ActionEvent e) {         ConnectInfo transfer            = new ConnectInfo("yourname", "password");//创建一个传递参数类         if (dialog == null)            dialog = new PasswordDialog(this);//创建对话框         if (dialog.showDialog(transfer))//调用连接窗对话框口,并传递参数         {  String uname = transfer.username;//交换用户名数据            String pwd = transfer.password;//交换密码数据            jLabel1.setText("用户名 =="+uname);//显示用户名            jLabel2.setText("密  码 =="+pwd);//显示密码内容            validate();//刷新屏幕         }  }}class ConnectInfo//用于传递参数{  public String username;   public String password;   public ConnectInfo(String u, String p)      { username = u; password = p; }}

⌨️ 快捷键说明

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