package Manage;import java.awt.*;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import javax.swing.JOptionPane;//消息窗口import javax.swing.*;public class MainInterface extends JFrame implements ActionListener{/** * 定义组件 */JButton jb1,jb2; JPanel jp1,jp2,jp3; JLabel jl1,jl2,jl3; JTextField jtf1,jpf1; /** * 构造方法 */public MainInterface(){/** * 创建组件 */jp1 = new JPanel();jp2 = new JPanel();jp3 = new JPanel();jb1 = new JButton("确定");jb2 = new JButton("退出");jl1 = new JLabel("用户名");jl2 = new JLabel("密码");jl3 = new JLabel(new ImageIcon("sky.jpg"));jtf1 = new JTextField(15);jpf1 = new JPasswordField(15);/** * 设置布局 */this.setLayout(new GridLayout(3,1));/** * 添加组件 */jp1.add(jl1);jp1.add(jtf1);jp2.add(jl2);jp2.add(jpf1);jp3.add(jb1);jp3.add(jb2);/** * 添加面板 */this.add(jp1);this.add(jp2);this.add(jp3);/** * 注册监听 */jb1.addActionListener(this);jb1.setActionCommand("ensure");jb2.addActionListener(this);jb2.setActionCommand("cancel");/** * 设置窗体 */this.setTitle("学生登陆界面");this.setSize(300,200);this.setLocation(300,300);//设计标题图片this.setIconImage(new ImageIcon("book.png").getImage());//设置面板颜色。jp1.setBackground(Color.cyan);jp2.setBackground(Color.cyan);jp3.setBackground(Color.cyan);this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);this.setResizable(false);this.setVisible(true);}/** * 判断登陆口令是否正确 */public void actionPerformed(ActionEvent e) {String name = jtf1.getText();String psw = String.valueOf(jpf1.getText());if(e.getActionCommand().equals("ensure")){ if(!(name.equals("wukete")) && !(psw.equals("773805950")) ){//弹出一个显示错误信息的消息对话框JOptionPane.showMessageDialog(null,"用户名或者密码错误!," +"","错误",JOptionPane.ERROR_MESSAGE); return;}else{//弹出一个选择窗口JOptionPane.showConfirmDialog(null, "进入系统", "提示", JOptionPane.YES_NO_OPTION);System.out.println("登陆成功!");}}else if(e.getActionCommand().equals("cancel")){/** * 退出程序。 */JOptionPane.showConfirmDialog(null, "退出系统", "提示", JOptionPane.YES_NO_OPTION);}}public static void main(String []args){MainInterface mi = new MainInterface();}}
简单登录界面
最新推荐文章于 2023-04-12 16:18:24 发布