每日总结-23.11.26

package Interface;
import gongneng.BackGroundPanel;

import javax.imageio.ImageIO;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.IOException;
public class MainTest {
    JFrame jf  = new JFrame("个人资料");
    static final int WIDTH = 800;
    static final int HEIGHT = 650;
    public void init() throws IOException {;
        Toolkit kit = Toolkit.getDefaultToolkit();
        Dimension screenSize = kit.getScreenSize();
        int width = screenSize.width;
        int height = screenSize.height;
        int x = (width - WIDTH) / 2;
        int y = (height - HEIGHT) / 2;
        jf.setBounds(x, y, WIDTH, HEIGHT);
        jf.setResizable(false);
        jf.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        jf.setIconImage(ImageIO.read(new File("images/logo.jpg")));
        BackGroundPanel bgPanel = new BackGroundPanel(ImageIO.read(new File("images/beijing.jpg")));
        Box loginBox = Box.createVerticalBox();
        //账号
        Box nameBox = Box.createHorizontalBox();
        JLabel nameLabel = new JLabel("账   号:");
        nameLabel.setFont(new Font("华文彩云",Font.BOLD,40));
        nameLabel.setForeground(Color.BLACK);
        JTextField nameField = new JTextField("root",20);
        nameField.setFont(new Font("楷体",Font.BOLD,15));
        nameBox.add(nameLabel);
        nameBox.add(Box.createHorizontalStrut(20));
        nameBox.add(nameField);
        //密码
        Box passwordBox = Box.createHorizontalBox();
        JLabel passwordLabel = new JLabel("密   码:");
        passwordLabel.setFont(new Font("华文彩云",Font.BOLD,40));
        passwordLabel.setForeground(Color.BLACK);
        JTextField passwordField = new JTextField(20);
        passwordField.setFont(new Font("楷体",Font.BOLD,15));
        passwordBox.add(passwordLabel);
        passwordBox.add(Box.createHorizontalStrut(20));
        passwordBox.add(passwordField);
        //按钮
        Box signBox = Box.createHorizontalBox();
        JButton loginButton = new JButton("登  录");
        loginButton.setFont(new Font("华文行楷",Font.BOLD,40));
        JButton tuiChuButton = new JButton("退  出");
        tuiChuButton.setFont(new Font("华文行楷",Font.BOLD,40));
        loginButton.addActionListener(e -> {
            String nametext = nameField.getText();
            String passwordtext = passwordField.getText();
            String str = new String(passwordtext);
            boolean x1 = (nametext.equals("root"));
            boolean y1 = (passwordtext.equals("123456"));
            boolean z = (x1 & y1);
            if(z == true){
                JOptionPane.showMessageDialog(jf,"登录成功!");
                jf.dispose();
                try {
                    new Introduction().init();
                } catch (IOException ioException) {
                    ioException.printStackTrace();
                }

            }
            else if(z == false){
                JOptionPane.showMessageDialog(jf,"用户名或密码错误!","错误 ",0);
                nameField.setText("");
                passwordField.setText("");
            }
        });
        tuiChuButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                jf.dispose();
            }
        });
        signBox.add(loginButton);
        signBox.add(Box.createHorizontalStrut(100));
        signBox.add(tuiChuButton);
        loginBox.add(Box.createVerticalStrut(100));
        loginBox.add(nameBox);
        loginBox.add(Box.createVerticalStrut(45));
        loginBox.add(passwordBox);
        loginBox.add(Box.createVerticalStrut(60));
        loginBox.add(signBox);
        bgPanel.add(loginBox);
        jf.add(bgPanel);

        jf.setVisible(true);
    }
    public static void main(String[] args) throws IOException {
        new MainTest().init();
    }
}

 

posted @ 2023-11-26 21:28  lao_bing  阅读(16)  评论(0)    收藏  举报