2019-08-31 Logins extends JFrame

package com.foreknow.view;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.plaf.basic.BasicBorders.RadioButtonBorder;

import com.foreknow.model.User;
import com.foreknow.service.UserService;
import com.foreknow.service.impl.UserServiceImpl;

import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.JPasswordField;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.util.List;
import java.awt.event.ActionEvent;
import javax.swing.JRadioButton;

public class Logins extends JFrame {

    private JPanel contentPane;
    private JTextField textField;
    private JPasswordField passwordField;

    /**
     * Launch the application.
     */
    public static void main(String[] args) {
        EventQueue.invokeLater(new Runnable() {
            public void run() {
                try {
                    Logins frame = new Logins();
                    frame.setVisible(true);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
    }

    /**
     * Create the frame.
     */
    public Logins() {
        setTitle("Logins");
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setBounds(100, 100, 450, 300);
        contentPane = new JPanel();
        contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
        setContentPane(contentPane);
        contentPane.setLayout(null);
        //String email = textField.getName()+"@softedu.com";
        //System.out.println(textField.getName()+"@softedu.com");
        JLabel label = new JLabel("\u7528\u6237\u540D:");
        label.setBounds(56, 55, 54, 15);
        contentPane.add(label);
        
        JLabel label_1 = new JLabel("\u5BC6\u7801\uFF1A");
        label_1.setBounds(56, 126, 54, 15);
        contentPane.add(label_1);
        
        textField = new JTextField();
        textField.setBounds(156, 52, 162, 21);
        contentPane.add(textField);
        textField.setColumns(10);
        
        passwordField = new JPasswordField();
        passwordField.setBounds(156, 123, 162, 21);
        contentPane.add(passwordField);
        
        JButton button = new JButton("\u767B\u5F55");
        button.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                //调用业务层的方法
                UserService service = new UserServiceImpl();
                //获取页面中用户填写的用户名与密码
                String username = textField.getText();
                String password = passwordField.getText();
                List list = service.isValidate(username, password);
                if (list.size()>0) {
                    System.out.println("登陆成功");
                    User user = (User) list.get(0);
                    if (user.getPrower()==0) {
                        MainWindows main = new MainWindows(list);
                    } else if (user.getPrower()==1) {
                        MainWindow main = new MainWindow();
                    }
                    //创建一个新的页面
                    //隐藏当前Login的页面
                    Logins.this.dispose();
                } else {
                    System.out.println("登录失败");
                }
            }
        });
        button.setBounds(56, 216, 93, 23);
        contentPane.add(button);
        
        JButton button_1 = new JButton("\u6CE8\u518C");
        button_1.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                Registes registes = new Registes();
                Logins.this.disable();
                Logins.this.dispose();
            }
        });
        button_1.setBounds(178, 216, 93, 23);
        contentPane.add(button_1);
        
        JButton button_2 = new JButton("\u53D6\u6D88");
        button_2.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                //将文本中的内容取消(清空)
                textField.setText("");
                passwordField.setText("");
            }
        });
        button_2.setBounds(299, 216, 93, 23);
        contentPane.add(button_2);
    }
}

 

                            
                        
                    
                    
                    

你可能感兴趣的:(2019-08-31 Logins extends JFrame)