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

📄 frame1.java

📁 JAVA编写的登陆窗体
💻 JAVA
字号:
package loginexample;

import java.awt.BorderLayout;
import java.awt.Dimension;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JLabel;
import java.awt.Rectangle;
import javax.swing.JTextField;
import javax.swing.JButton;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JPasswordField;
import javax.swing.JOptionPane;

/**
 * <p>Title: </p>
 *
 * <p>Description: </p>
 *
 * <p>Copyright: Copyright (c) 2007</p>
 *
 * <p>Company: </p>
 *
 * @author not attributable
 * @version 1.0
 */
public class Frame1 extends JFrame {
    JPanel contentPane;
    JLabel jLabel1 = new JLabel();
    JLabel jLabel2 = new JLabel();
    JTextField jTextField1 = new JTextField();
    JButton jButton1 = new JButton();
    JButton jButton2 = new JButton();
    JPasswordField jPasswordField1 = new JPasswordField();
    //
    DBCON db = new DBCON();
    JButton jButton3 = new JButton();
    JButton jButton4 = new JButton();
    //
    public Frame1() {
        try {
            setDefaultCloseOperation(EXIT_ON_CLOSE);
            jbInit();
        } catch (Exception exception) {
            exception.printStackTrace();
        }
    }

    /**
     * Component initialization.
     *
     * @throws java.lang.Exception
     */
    private void jbInit() throws Exception {
        contentPane = (JPanel) getContentPane();
        contentPane.setLayout(null);
        setSize(new Dimension(358, 221));
        setTitle("Frame Title");
        jLabel1.setText("用户名:");
        jLabel1.setBounds(new Rectangle(42, 41, 88, 27));
        jLabel2.setText("密  码:");
        jLabel2.setBounds(new Rectangle(41, 73, 93, 20));
        jTextField1.setBounds(new Rectangle(142, 38, 171, 21));
        jButton1.setBounds(new Rectangle(21, 140, 113, 25));
        jButton1.setMnemonic('A');
        jButton1.setText("确定(A)");
        jButton1.addActionListener(new Frame1_jButton1_actionAdapter(this));
        jButton2.setBounds(new Rectangle(134, 140, 116, 25));
        jButton2.setMnemonic('C');
        jButton2.setText("取消(C)");
        jPasswordField1.setBounds(new Rectangle(141, 77, 175, 21));
        jButton3.setBounds(new Rectangle(17, 169, 125, 26));
        jButton3.setText("修改密码");
        jButton3.addActionListener(new Frame1_jButton3_actionAdapter(this));
        jButton4.setBounds(new Rectangle(253, 140, 101, 25));
        jButton4.setText("注册");
        jButton4.addActionListener(new Frame1_jButton4_actionAdapter(this));
        contentPane.add(jLabel1);
        contentPane.add(jLabel2);
        contentPane.add(jTextField1);
        contentPane.add(jPasswordField1);
        contentPane.add(jButton1);
        contentPane.add(jButton2);
        contentPane.add(jButton3);
        contentPane.add(jButton4);
    }

    public void jButton1_actionPerformed(ActionEvent e) {
        String str = jTextField1.getText().trim();
        //     String strpass=jPasswordField1.getText().trim();
        char ch[] = jPasswordField1.getPassword();
        String strpass = new String(ch);
        if (str.length() == 0 | strpass.length() == 0) {
            JOptionPane.showMessageDialog(this, "请输入完整数据!");
        } else {
            boolean b = db.selectuser(str, strpass);
            //将str,strpass作为参数传递给DBCON类的对象db的selectuset
            //这个方法的参数

            if (b == true) {
                JOptionPane.showMessageDialog(this, "登陆成功!");
            } else {
                JOptionPane.showMessageDialog(this, "用户名或密码错误!");

            }
            //           if(str.equals("abc")&&strpass.equals("123"))
            //           {
            //
            //           }

        }
    }

    public void jButton3_actionPerformed(ActionEvent e) {
        this.dispose();//关闭当前窗体
        userpasswordfrm frm=new userpasswordfrm();
        frm.setSize(400,600);
        frm.setLocation(100,100);
        frm.setVisible(true);


    }

    public void jButton4_actionPerformed(ActionEvent e) {
        //System.exit(0);//整个程序关闭
        this.dispose();
        zcfrm frm=new zcfrm();
        frm.setSize(400,500);
        frm.setLocation(100,100);

        frm.setVisible(true);
    }
}


class Frame1_jButton4_actionAdapter implements ActionListener {
    private Frame1 adaptee;
    Frame1_jButton4_actionAdapter(Frame1 adaptee) {
        this.adaptee = adaptee;
    }

    public void actionPerformed(ActionEvent e) {
        adaptee.jButton4_actionPerformed(e);
    }
}


class Frame1_jButton3_actionAdapter implements ActionListener {
    private Frame1 adaptee;
    Frame1_jButton3_actionAdapter(Frame1 adaptee) {
        this.adaptee = adaptee;
    }

    public void actionPerformed(ActionEvent e) {
        adaptee.jButton3_actionPerformed(e);
    }
}


class Frame1_jButton1_actionAdapter implements ActionListener {
    private Frame1 adaptee;
    Frame1_jButton1_actionAdapter(Frame1 adaptee) {
        this.adaptee = adaptee;
    }

    public void actionPerformed(ActionEvent e) {
        adaptee.jButton1_actionPerformed(e);
    }
}

⌨️ 快捷键说明

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