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

📄 loginframe2.java~7~

📁 JAVA教学用代码
💻 JAVA~7~
字号:
package jsjexample;

import java.awt.BorderLayout;

import javax.swing.JFrame;
import javax.swing.JLabel;
import java.awt.*;
import javax.swing.JTextField;
import javax.swing.JButton;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JPasswordField;

public class LoginFrame2 extends JFrame {
    public LoginFrame2() {
        try {
            jbInit();
        } catch (Exception exception) {
            exception.printStackTrace();
        }
    }

    private void jbInit() throws Exception {
        getContentPane().setLayout(null);
        jLabel1.setBackground(Color.pink);
        jLabel1.setOpaque(true);
        jLabel1.setBounds(new Rectangle(44, 27, 167, 33));
        jButton1.addActionListener(new LoginFrame2_jButton1_actionAdapter(this));
        jButton2.addActionListener(new LoginFrame2_jButton2_actionAdapter(this));
        jPasswordField1.setBounds(new Rectangle(86, 115, 126, 22));
        this.getContentPane().add(jLabel1);
        jButton2.setBounds(new Rectangle(143, 168, 98, 34));
        jButton2.setMnemonic('C');
        jButton2.setText("取消(C)");
        jButton1.setBounds(new Rectangle(41, 166, 93, 36));
        jButton1.setMnemonic('A');
        jButton1.setText("确定(A)");
        jLabel3.setText("密码");
        jLabel3.setBounds(new Rectangle(29, 116, 34, 16));
        jTextField1.setBounds(new Rectangle(85, 73, 125, 22));
        this.getContentPane().add(jLabel2);
        this.getContentPane().add(jTextField1);
        this.getContentPane().add(jLabel3);
        this.getContentPane().add(jButton1);
        this.getContentPane().add(jButton2);
        this.getContentPane().add(jPasswordField1);
        jLabel2.setText("姓名");
        jLabel2.setBounds(new Rectangle(28, 74, 34, 16));
    }

    JLabel jLabel1 = new JLabel();
    JLabel jLabel2 = new JLabel();
    JTextField jTextField1 = new JTextField();
    JLabel jLabel3 = new JLabel();
    JButton jButton1 = new JButton();
    JButton jButton2 = new JButton();
    JPasswordField jPasswordField1 = new JPasswordField();
    public static void main(String args[]) {
        LoginFrame2 login = new LoginFrame2();
        login.setSize(400, 300);
        login.setLocation(100, 100);
        login.setVisible(true);

    }

    public void jButton1_actionPerformed(ActionEvent e) {
        String str1 = jTextField1.getText().trim();
       // String str2 = .trim();
//        if (str1.equals("aaa") && str2.equals("123")) {
//            jLabel1.setText("登陆成功!");
//        } else {
//            jLabel1.setText("用户名或密码错误!");
//            jTextField1.setText("");
//        }

    }

    public void jButton2_actionPerformed(ActionEvent e) {
        System.exit(0);
    }
}


class LoginFrame2_jButton2_actionAdapter implements ActionListener {
    private LoginFrame2 adaptee;
    LoginFrame2_jButton2_actionAdapter(LoginFrame2 adaptee) {
        this.adaptee = adaptee;
    }

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


class LoginFrame2_jButton1_actionAdapter implements ActionListener {
    private LoginFrame2 adaptee;
    LoginFrame2_jButton1_actionAdapter(LoginFrame2 adaptee) {
        this.adaptee = adaptee;
    }

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

⌨️ 快捷键说明

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