• 作业


    import javax.swing.*;
    import javax.swing.event.AncestorEvent;
    import javax.swing.event.AncestorListener;

    import java.awt.*; //导入必要的包
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.awt.event.KeyEvent;
    import java.nio.file.DirectoryStream.Filter;

    public class load extends JFrame {
    JTextField jTextField;// 定义文本框组件
    JPasswordField jPasswordField;// 定义密码框组件
    JLabel jLabel1, jLabel2;
    JPanel jp1, jp2, jp3;
    JButton jb1, jb2;// 创建按钮

    public load() {
    jTextField = new JTextField(12);
    jPasswordField = new JPasswordField(12);
    jLabel1 = new JLabel("用户名");
    jLabel2 = new JLabel("密 码 ");
    jb1 = new JButton("确认");
    jb1.addActionListener(new ActionListener() {

    @Override
    public void actionPerformed(ActionEvent e) {
    // TODO Auto-generated method stub
    JOptionPane.showMessageDialog(null, "正确", "提示", JOptionPane.INFORMATION_MESSAGE);

    }
    });

    jb2 = new JButton("取消");
    jp1 = new JPanel();
    jp2 = new JPanel();
    jp3 = new JPanel();

    // 设置布局
    this.setLayout(new GridLayout(3, 1));

    jp1.add(jLabel1);
    jp1.add(jTextField);// 第一块面板添加用户名和文本框

    jp2.add(jLabel2);
    jp2.add(jPasswordField);// 第二块面板添加密码和密码输入框

    jp3.add(jb1);
    jp3.add(jb2); // 第三块面板添加确认和取消

    // jp3.setLayout(new FlowLayout());
    // //因为JPanel默认布局方式为FlowLayout,所以可以注销这段代码.
    this.add(jp1);
    this.add(jp2);
    this.add(jp3); // 将三块面板添加到登陆框上面
    // 设置显示
    this.setSize(300, 230);
    Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
    this.setLocation(d.width / 2 - this.getWidth() / 2, d.height / 2 - this.getHeight() / 2);
    // this.pack();
    this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    this.setVisible(true);
    this.setTitle("登陆");

    JMenuBar menubar = new JMenuBar();
    this.setJMenuBar(menubar);

    JMenu menu;
    JMenuItem item;

    // create the File menu
    menu = new JMenu("File");
    menubar.add(menu);

    item = new JMenuItem("Open...");
    menu.add(item);

    item = new JMenuItem("Close");
    menu.add(item);
    menu.addSeparator();

    item = new JMenuItem("Save As...");

    menu.add(item);
    menu.addSeparator();

    item = new JMenuItem("Quit");
    menu.add(item);

    // create the Filter menu
    menu = new JMenu("Filter");
    menubar.add(menu);
    menu.add(item);

    // create the Help menu
    menu = new JMenu("Help");
    menubar.add(menu);

    item = new JMenuItem("About ImageViewer...");

    menu.add(item);
    }

    public static void main(String[] args) {
    new load();
    }
    }

  • 相关阅读:
    数据库之ORACLE常见基础操作
    数据库基础之Oracle函数
    Snuketoon [ABC217H]
    Cards [CF1278F]
    Squirrel Migration [ARC087F]
    Xor Query [ABC223H]
    Three Permutations [ABC214G]
    雨林跳跃[APIO2021]
    Redis5.0 主从模式和高可用 搭建和测试报告
    Redis5 压力测试结果反馈报告
  • 原文地址:https://www.cnblogs.com/87v5/p/5293356.html
Copyright © 2020-2023  润新知