简易商品购物系统登陆界面

xiaoxiao2021-02-28  114

//包含密码框,登陆按钮

import java.awt.BorderLayout; public class Land 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 { Land frame = new Land(); frame.setVisible(true); } catch (Exception e) { e.printStackTrace(); } } }); } /** * Create the frame. */ public Land() { setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setBounds(100, 100, 450, 300); contentPane = new JPanel(); contentPane.setBackground(Color.WHITE); contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); setContentPane(contentPane); contentPane.setLayout(null); textField = new JTextField(); textField.setBackground(new Color(70, 130, 180)); textField.setFont(new Font("楷体", Font.PLAIN, 20)); textField.setHorizontalAlignment(SwingConstants.CENTER); textField.setText("\u6B22\u8FCE\u8FDB\u5165\u8D2D\u7269\u7CFB\u7EDF"); textField.setBounds(43, 29, 348, 69); contentPane.add(textField); textField.setColumns(10); JButton btnNewButton = new JButton("\u70B9\u51FB\u8FDB\u5165"); btnNewButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { //设置密码

String str = "123456"; //判断密码是否正确

if(passwordField.getText().equals(str)){ new Supermarket().setVisible(true); }else{ passwordField.setText(""); } } }); btnNewButton.setBounds(137, 172, 153, 41); contentPane.add(btnNewButton); passwordField = new JPasswordField(); passwordField.setToolTipText("\u8BF7\u8F93\u5165\u5BC6\u7801\uFF1A"); passwordField.setHorizontalAlignment(SwingConstants.CENTER); passwordField.setBounds(189, 127, 93, 35); contentPane.add(passwordField); JLabel lblNewLabel = new JLabel("\u5BC6\u7801\uFF1A"); lblNewLabel.setHorizontalAlignment(SwingConstants.CENTER); lblNewLabel.setBounds(117, 127, 93, 35); contentPane.add(lblNewLabel); } }

转载请注明原文地址: https://www.6miu.com/read-80281.html

最新回复(0)