try { BeautyEyeLNFHelper.frameBorderStyle = BeautyEyeLNFHelper.FrameBorderStyle.osLookAndFeelDecorated; //UIManager.put("RootPane.setupButtonVisible", false); org.jb2011.lnf.beautyeye.BeautyEyeLNFHelper.launchBeautyEyeLNF(); } catch(Exception e) { //TODO exception } // 创建窗体对象 JFrame jFrame =new JFrame(); // 设置窗体大小 jFrame.setSize(800, 500); // 设置窗体全屏展示 //jFrame.setExtendedState(JFrame.MAXIMIZED_BOTH); // 设置窗体显示位置 //jFrame.setLocation(100,200); // 设置窗体显示正中间 jFrame.setLocationRelativeTo(null); // 设置窗体标题 jFrame.setTitle("窗体标题"); // 设置窗体不可全屏显示 //jFrame.setResizable(false); // 设置窗体关闭后退出程序 jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //设置此窗口是否应该始终位于其他窗口上方 jFrame.setAlwaysOnTop(true); // 设置窗体图标 jFrame.setIconImage(new ImageIcon(HelloWorld.class.getResource("/images/book.png")).getImage()); // 创建容器 JPanel jPanel =new JPanel(null); JLabel usernameLabel =new JLabel("用户名:"); usernameLabel.setFont(new Font("微软雅黑",Font.PLAIN,15)); usernameLabel.setHorizontalTextPosition(SwingConstants.LEFT); usernameLabel.setSize(80, 30); usernameLabel.setLocation(100, 50); JTextField usernameTextField =new JTextField(); usernameTextField.setFont(new Font("微软雅黑",Font.PLAIN,15)); usernameTextField.setSize(200, 30); usernameTextField.setLocation(220, 50); JLabel passwordLabel =new JLabel("密码:"); passwordLabel.setFont(new Font("微软雅黑",Font.PLAIN,15)); passwordLabel.setHorizontalTextPosition(SwingConstants.LEFT); passwordLabel.setSize(80, 30); passwordLabel.setLocation(100, 100); JPasswordField passwordTextField =new JPasswordField(); passwordTextField.setFont(new Font("微软雅黑",Font.PLAIN,15)); passwordTextField.setSize(200, 30); passwordTextField.setLocation(220, 100); JButton jButton =new JButton("确定"); jButton.setFont(new Font("微软雅黑",Font.PLAIN,15)); jButton.setSize(200, 30); jButton.setLocation(220, 150); jButton.setCursor(new Cursor(Cursor.HAND_CURSOR)); jButton.setForeground(Color.white); // beautyeye框架设置按钮背景颜色 jButton.setUI(new BEButtonUI().setNormalColor(NormalColor.blue)); jButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { String username=usernameTextField.getText();// 获取文本 String password=new String(passwordTextField.getPassword());//获取密码 System.out.println(username); System.out.println(password); } }); usernameTextField.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { // 输入用户名回车,自动进入到密码框 passwordTextField.requestFocus(); } }); passwordTextField.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { // 输入密码后回车,当按钮自动进入到监听器执行登录 jButton.doClick(); } }); jPanel.add(usernameLabel); jPanel.add(passwordLabel); jPanel.add(usernameTextField); jPanel.add(passwordTextField); jPanel.add(passwordTextField); jPanel.add(jButton); jFrame.setContentPane(jPanel); // 设置窗体可见 jFrame.setVisible(true);
标签:jFrame,Font,passwordTextField,窗体,new,JavaSwing,jButton,JTextField From: https://www.cnblogs.com/liangqingyun/p/18587204