javaGUI 登录窗口
2021/12/14 1:17:26
本文主要是介绍javaGUI 登录窗口,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
创建一个登录窗口
import javax.swing.*; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; public class loginFrame extends JFrame { public loginFrame(){ this.setSize(300,200); // this.setLocation(100,100); this.setLocationRelativeTo(null); this.setTitle("登录QQ"); this.setIconImage(new ImageIcon("屏幕截图 2021-12-11 170051.png").getImage()); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.setResizable(false); this.setLayout(new GridLayout(3,1)); JPanel jp = new JPanel(); JPanel jp1 = new JPanel(); JPanel jp2 = new JPanel(); JButton jb = new JButton("确定"); jb.setLocation(100,50); jb.setSize(100,40); JButton jb1 = new JButton("取消"); jb1.setLocation(100,100); jb1.setSize(100,40); JLabel accountLabel = new JLabel("账号",JLabel.CENTER); JTextField accountText = new JTextField(10); JLabel passWord = new JLabel("密码"); JPasswordField passwordField = new JPasswordField(10); jp.add(accountLabel); jp.add(accountText); jp1.add(passWord); jp1.add(passwordField); jp2.add(jb); jp2.add(jb1); this.add(jp); this.add(jp1); this.add(jp2); this.setVisible(true); jb.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { try { String account = accountText.getText(); String password = new String(passwordField.getPassword()); if (account.length() == 0) { JOptionPane.showMessageDialog(null, "账号不能为空", "系统提示", JOptionPane.WARNING_MESSAGE); return; } if (password.length() == 0) { JOptionPane.showMessageDialog(null, "密码不能为空"); return; } } catch (Exception e1) { JOptionPane.showMessageDialog(null, "运行异常"); } } }); jb1.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { accountText.setText(""); passwordField.setText(""); } }); } public static void main(String[] args) { new loginFrame(); } }
这篇关于javaGUI 登录窗口的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-05-15鸿蒙生态设备数量超8亿台
- 2024-05-13TiDB + ES:转转业财系统亿级数据存储优化实践
- 2024-05-09“2024鸿蒙零基础快速实战-仿抖音App开发(ArkTS版)”实战课程已上线
- 2024-05-09聊聊如何通过arthas-tunnel-server来远程管理所有需要arthas监控的应用
- 2024-05-09log4j2这么配就对了
- 2024-05-09nginx修改Content-Type
- 2024-05-09Redis多数据源,看这篇就够了
- 2024-05-09Google Chrome驱动程序 124.0.6367.62(正式版本)去哪下载?
- 2024-05-09有没有大佬知道这种数据应该怎么抓取呀?
- 2024-05-09这种运行结果里的10.100000001,怎么能最快改成10.1?