java应用软件开发之多物料管理系统--登录界面设…

2018-09-18 06:38:32来源:博客园 阅读 ()

新老客户大回馈,云服务器低至5折

此系列将记录本人从开始到结束做物料管理系统的过程

登录界面的设计

此博客将实现如下界面:

当用户名或密码没输入时将显示相应的提示信息,采用java swing实现

代码:

import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JTextField;
import javax.swing.JPasswordField;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JRadioButton;
import java.awt.Color;

public class login {

    private JFrame frame;
    private JTextField textField;
    private JPasswordField passwordField;

    public static void main(String[] args) {
        EventQueue.invokeLater(new Runnable() {
            public void run() {
                try {
                    login window = new login();
                    window.frame.setLocationRelativeTo(null);
                    window.frame.setVisible(true);
                    
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
    }

    public login() {
        initialize();
    }

    private void initialize() {
        frame = new JFrame();
        frame.setTitle("\u7269\u6599\u7BA1\u7406\u7CFB\u7EDF");
        frame.setBounds(100, 100, 360, 260);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.getContentPane().setLayout(null);
        
        JLabel usernameLabel = new JLabel("\u7528\u6237\u540D\uFF1A");
        usernameLabel.setFont(new Font("宋体", Font.PLAIN, 14));
        usernameLabel.setBounds(90, 66, 72, 28);
        frame.getContentPane().add(usernameLabel);
        
        JLabel passwordLabel = new JLabel("\u5BC6  \u7801\uFF1A");
        passwordLabel.setFont(new Font("宋体", Font.PLAIN, 14));
        passwordLabel.setBounds(90, 104, 72, 33);
        frame.getContentPane().add(passwordLabel);
        
        textField = new JTextField();
        textField.setForeground(Color.BLACK);
        textField.setBounds(147, 70, 110, 21);
        frame.getContentPane().add(textField);
        textField.setColumns(10);
        textField.addActionListener(new action());
        
        passwordField = new JPasswordField();
        passwordField.setBounds(147, 110, 110, 21);
        frame.getContentPane().add(passwordField);
        passwordField.addActionListener(new action());
        
        JButton loginButton = new JButton("\u767B\u5F55");
        loginButton.setBounds(90, 157, 72, 23);
        frame.getContentPane().add(loginButton);
        loginButton.addActionListener(new action());
        
        ButtonGroup group = new ButtonGroup();
        
        JRadioButton button1 = new JRadioButton("\u7BA1\u7406\u54581");
        button1.setBounds(64, 18, 72, 23);
        frame.getContentPane().add(button1);
        group.add(button1);
        
        JRadioButton button2 = new JRadioButton("\u7BA1\u7406\u54582");
        button2.setBounds(138, 18, 72, 23);
        frame.getContentPane().add(button2);
        group.add(button2);
        
        JRadioButton button3 = new JRadioButton("\u7BA1\u7406\u54582");
        button3.setBounds(210, 18, 80, 23);
        frame.getContentPane().add(button3);
        group.add(button3);
        
        JLabel label = new JLabel("");
        label.setBounds(267, 73, 54, 15);
        frame.getContentPane().add(label);
        
        JLabel label_1 = new JLabel("");
        label_1.setBounds(267, 113, 54, 15);
        frame.getContentPane().add(label_1);
    }
    
    class action implements ActionListener{

        @SuppressWarnings("deprecation")
        public void actionPerformed(ActionEvent e) {
            String buttonName = e.getActionCommand();
            if(buttonName.equals("登录")) {
                if(textField.getText().isEmpty()) {
                    JOptionPane.showMessageDialog(null, "账号不能为空");  
                }else if(passwordField.getText().isEmpty()) {
                    JOptionPane.showMessageDialog(null, "密码不能为空");
                }
            }
        }    
    }
}

 

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇:selenium 3+java 配置全

下一篇:Json