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

📄 mainframe.java~79~

📁 一款高校科研管理系统
💻 JAVA~79~
字号:
package scince;

import java.awt.Dimension;
import javax.swing.JOptionPane;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JButton;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JLabel;
import java.awt.Font;
import javax.swing.JTextField;
import javax.swing.JPasswordField;
import java.sql.DriverManager;
import java.sql.Statement;
import java.sql.ResultSet;
import java.sql.Connection;
import java.sql.SQLException;
import java.awt.*;
import java.io.*;
import java.awt.event.*;
import javax.swing.JPasswordField;
import javax.swing.UIManager;

public class mainframe extends JFrame {
    JPanel contentPane;
    JButton jButton1 = new JButton();
    JLabel jLabel1 = new JLabel();
    JLabel jLabel2 = new JLabel();
    JLabel jLabel3 = new JLabel();
    JTextField jTextField1 = new JTextField();
    JButton jButton2 = new JButton();
    JLabel jLabel4 = new JLabel();
    JPasswordField jPasswordField1 = new JPasswordField();
    public mainframe() {
        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(400, 400));
        setTitle("welcome");
        jButton1.setBackground(Color.white);
        jButton1.setBounds(new Rectangle(77, 258, 98, 37));
        jButton1.setFont(new java.awt.Font("新宋体", Font.PLAIN, 12));
        jButton1.setForeground(Color.cyan);
        jButton1.setText("登陆");
        jButton1.addActionListener(new mainframe_jButton1_actionAdapter(this));
        jLabel1.setFont(new java.awt.Font("方正姚体", Font.PLAIN, 36));
        jLabel1.setForeground(Color.cyan);
        jLabel1.setText("欢迎光临本系统");
        jLabel1.setBounds(new Rectangle(54, 20, 289, 60));
        jLabel2.setForeground(Color.cyan);
        jLabel2.setText("阿满制作");
        jLabel2.setBounds(new Rectangle(243, 74, 113, 45));
        jLabel3.setForeground(Color.cyan);
        jLabel3.setText("用户名");
        jLabel3.setBounds(new Rectangle(75, 141, 73, 24));
        jTextField1.setForeground(Color.cyan);
        jTextField1.setCaretColor(Color.magenta);
        jTextField1.setBounds(new Rectangle(153, 140, 115, 27));
        jButton2.setBounds(new Rectangle(208, 260, 93, 38));
        jButton2.setFont(new java.awt.Font("新宋体", Font.PLAIN, 12));
        jButton2.setForeground(Color.cyan);
        jButton2.setText("重置");
        jButton2.addActionListener(new mainframe_jButton2_actionAdapter(this));
        jLabel4.setForeground(Color.cyan);
        jLabel4.setText("密码");
        jLabel4.setBounds(new Rectangle(74, 182, 63, 26));
        jPasswordField1.setForeground(Color.cyan);
        jPasswordField1.setCaretColor(Color.magenta);
        jPasswordField1.setDisabledTextColor(Color.white);
        jPasswordField1.setBounds(new Rectangle(153, 181, 117, 29));
        contentPane.setBackground(new Color(0, 0, 161));
        jButton3.setBounds(new Rectangle(74, 324, 99, 38));
        jButton3.setForeground(Color.cyan);
        jButton3.setText("注册");
        jButton3.addActionListener(new mainframe_jButton3_actionAdapter(this));
        jButton4.setBounds(new Rectangle(210, 325, 96, 33));
        jButton4.setForeground(Color.cyan);
        jButton4.setText("退出");
        jButton4.addActionListener(new mainframe_jButton4_actionAdapter(this));
        contentPane.add(jLabel1);
        contentPane.add(jTextField1);
        contentPane.add(jButton1);
        contentPane.add(jButton2);
        contentPane.add(jLabel3);
        contentPane.add(jLabel4);
        contentPane.add(jPasswordField1);
        contentPane.add(jButton3);
        contentPane.add(jButton4);
        contentPane.add(jLabel2);
    }

    int count = 3; //allow user try password three times;

    JButton jButton3 = new JButton();
    JButton jButton4 = new JButton();
    public void jButton1_actionPerformed(ActionEvent e) {
        Connection con;
        Statement sql;
        ResultSet rs;
        String queryString;
        String user;
        String password;

        user = jTextField1.getText().trim();
        password = jPasswordField1.getText();
        if (count <0) {
            JOptionPane.showMessageDialog(null, "你没有机会了", "密码提示框",
                                          JOptionPane.INFORMATION_MESSAGE);
            this.dispose();
        } //试密码超过三次就关闭窗口
        queryString = "select * from 用户 where 用户名='" + user + "'and 密码='" +
                      password + "'";

        if (jTextField1.getText().equals("") && count > 0) {
            JOptionPane.showMessageDialog(null, "请输入内容,还有"+ ( count )+"次机会,请确认后认真填写", "密码提示框",
                                          JOptionPane.INFORMATION_MESSAGE);
            --count;
        }
        try {
            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
        } catch (java.lang.ClassNotFoundException ee) {
            System.err.print("class not find!");
            System.err.println(ee.getMessage());
        }

        try {
            con = DriverManager.getConnection("jdbc:odbc:scince", "", "");
            sql = con.createStatement();
            rs = sql.executeQuery(queryString);

            if (rs.next()) {
                Frame1 frame = new Frame1();
                frame.setSize(400, 400);
                frame.setLocation(380, 250);
                frame.setTitle("table wizard");
                frame.setVisible(true);
                this.dispose();
            } else {

                if (count >=0&&!jTextField1.getText().equals("")) {
                    JOptionPane.showMessageDialog(null,
                                                  "请输入内容,还有"+( count )+"次机会,请确认后认真填写",
                                                  "密码提示框",
                                                  JOptionPane.
                                                  INFORMATION_MESSAGE);
                    --count;
                }
            }
            con.close();
        } catch (SQLException ex) {}
        ;


    }

    public void jButton2_actionPerformed(ActionEvent e) {
        jTextField1.setText("");
        jPasswordField1.setText("");
    }

    public void jButton4_actionPerformed(ActionEvent e) {
            this.dispose();
    }

    public void jButton3_actionPerformed(ActionEvent e) {
         Enroll Enroll=new Enroll();
         Enroll.setLocation(440, 300);
         Enroll.setSize(400, 400);
         Enroll.setTitle("注册对话框");
         Enroll.setVisible(true);
    }
}


class mainframe_jButton3_actionAdapter implements ActionListener {
    private mainframe adaptee;
    mainframe_jButton3_actionAdapter(mainframe adaptee) {
        this.adaptee = adaptee;
    }

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


class mainframe_jButton4_actionAdapter implements ActionListener {
    private mainframe adaptee;
    mainframe_jButton4_actionAdapter(mainframe adaptee) {
        this.adaptee = adaptee;
    }

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


class mainframe_jButton2_actionAdapter implements ActionListener {
    private mainframe adaptee;
    mainframe_jButton2_actionAdapter(mainframe adaptee) {
        this.adaptee = adaptee;
    }

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


class mainframe_jButton1_actionAdapter implements ActionListener {
    private mainframe adaptee;
    mainframe_jButton1_actionAdapter(mainframe adaptee) {
        this.adaptee = adaptee;
    }

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

⌨️ 快捷键说明

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