当前位置: 首页 > news >正文

java:logform

 

/*** encoding: utf-8* 版权所有 2025 ©涂聚文有限公司 ®* 许可信息查看:言語成了邀功盡責的功臣,還需要行爲每日來值班嗎* 描述:* Author    : geovindu,Geovin Du 涂聚文.* IDE       : IntelliJ IDEA 2024.3.6 Java 17* # database  : Oracle21c,MySQL 9.0,SQL Server 2019,PostgreSQL 17.1 Neo4j* # OS        : window10* Datetime  : 2025 - 2025/10/21 - 20:58* User      : geovindu* Product   : IntelliJ IDEA* Project   : swingdemo* File      : LoginWindow.java* explain   : 学习  类**/package com.example.interfaces;import com.example.application.LoginApplicationService;
import com.example.domain.entity.User;import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.util.Optional;public class LoginWindow extends JFrame {private final LoginApplicationService loginService;private JTextField usernameField;private JPasswordField passwordField;public LoginWindow(LoginApplicationService loginService) {this.loginService = loginService;initializeUI();}private void initializeUI() {setTitle("登录");setSize(300, 200);setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);setLocationRelativeTo(null);// 设置全局字体(支持中文)Font labelFont = new Font("SimHei", Font.PLAIN, 14);JPanel panel = new JPanel(new GridLayout(3, 2, 10, 10));panel.setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));JLabel userLabel = new JLabel("用户名:");userLabel.setFont(labelFont); // 用户名标签字体userLabel.setBounds(50, 50, 200, 30); // 设置位置和大小userLabel.setHorizontalAlignment(JLabel.RIGHT);//对齐userLabel.setVerticalAlignment(JLabel.CENTER);panel.add(userLabel);usernameField = new JTextField();usernameField.setFont(labelFont); // 输入框字体panel.add(usernameField);JLabel passLabel = new JLabel("密码:");passLabel.setFont(labelFont); // 密码标签字体passLabel.setBounds(50, 50, 200, 30); // 设置位置和大小passLabel.setHorizontalAlignment(JLabel.RIGHT);passLabel.setVerticalAlignment(JLabel.CENTER);panel.add(passLabel);passwordField = new JPasswordField();passwordField.setFont(labelFont); // 密码框字体panel.add(passwordField);JButton loginButton = new JButton("登录");loginButton.setFont(labelFont); // 按钮字体loginButton.addActionListener(this::handleLogin);panel.add(loginButton);JButton cancelButton = new JButton("取消");cancelButton.setFont(labelFont); // 按钮字体cancelButton.addActionListener(e -> System.exit(0));panel.add(cancelButton);add(panel);setVisible(true);}private void handleLogin(ActionEvent e) {String username = usernameField.getText();String password = new String(passwordField.getPassword());Optional<User> user = loginService.login(username, password);if (user.isPresent()) {JOptionPane.showMessageDialog(this, "登录成功,欢迎回来," + user.get().getFullName() + "!");dispose(); // 关闭登录窗口new MainWindow(user.get()); // 打开主窗口} else {JOptionPane.showMessageDialog(this, "用户名或密码错误", "登录失败", JOptionPane.ERROR_MESSAGE);}}
}

  

/*** encoding: utf-8* 版权所有 2025 ©涂聚文有限公司 ®* 许可信息查看:言語成了邀功盡責的功臣,還需要行爲每日來值班嗎* 描述:* Author    : geovindu,Geovin Du 涂聚文.* IDE       : IntelliJ IDEA 2024.3.6 Java 17* # database  : Oracle21c,MySQL 9.0,SQL Server 2019,PostgreSQL 17.1 Neo4j* # OS        : window10* Datetime  : 2025 - 2025/10/21 - 20:59* User      : geovindu* Product   : IntelliJ IDEA* Project   : swingdemo* File      : MainWindow.java* explain   : 学习  类**/package com.example.interfaces;import com.example.domain.entity.User;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;public class MainWindow extends JFrame {private final User currentUser;public MainWindow(User currentUser) {this.currentUser = currentUser;initializeUI();}private void initializeUI() {setTitle("主窗口 - 欢迎," + currentUser.getFullName());setSize(800, 600);setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);setLocationRelativeTo(null);// 创建菜单栏(设置中文字体)JMenuBar menuBar = new JMenuBar();// 为菜单和菜单项设置字体(支持中文)Font menuFont = new Font("SimHei", Font.PLAIN, 14); // 黑体,常规,14号字// 文件菜单JMenu fileMenu = new JMenu("文件");fileMenu.setFont(menuFont); // 设置菜单字体JMenuItem exitItem = new JMenuItem("退出");exitItem.setFont(menuFont); // 设置菜单项字体exitItem.addActionListener(e -> System.exit(0));fileMenu.add(exitItem);menuBar.add(fileMenu);// 编辑菜单JMenu editMenu = new JMenu("编辑");editMenu.setFont(menuFont);JMenuItem cutItem = new JMenuItem("剪切");cutItem.setFont(menuFont);JMenuItem copyItem = new JMenuItem("复制");copyItem.setFont(menuFont);JMenuItem pasteItem = new JMenuItem("粘贴");pasteItem.setFont(menuFont);editMenu.add(cutItem);editMenu.add(copyItem);editMenu.add(pasteItem);menuBar.add(editMenu);// 帮助菜单JMenu helpMenu = new JMenu("帮助");helpMenu.setFont(menuFont);JMenuItem aboutItem = new JMenuItem("关于");aboutItem.setFont(menuFont);aboutItem.addActionListener(this::showAboutDialog);helpMenu.add(aboutItem);menuBar.add(helpMenu);setJMenuBar(menuBar);// 主面板(设置欢迎标签的中文字体)JPanel mainPanel = new JPanel();mainPanel.setLayout(new BorderLayout());JLabel welcomeLabel = new JLabel("欢迎使用系统," + currentUser.getFullName() + "!", SwingConstants.CENTER);// 设置支持中文的字体(黑体,加粗,24号字)welcomeLabel.setFont(new Font("SimHei", Font.BOLD, 24));mainPanel.add(welcomeLabel, BorderLayout.CENTER);add(mainPanel);setVisible(true);}private void showAboutDialog(ActionEvent e) {// 为对话框文本设置中文字体JLabel aboutLabel = new JLabel("<html>系统版本: 1.0<br>作者: DDD示例</html>");aboutLabel.setFont(new Font("SimHei", Font.PLAIN, 14));JOptionPane.showMessageDialog(this,aboutLabel,"关于",JOptionPane.INFORMATION_MESSAGE);}
}

  

http://www.hskmm.com/?act=detail&tid=38463

相关文章:

  • 小作业 13(2023 年北京高考圆锥曲线)
  • DeepSeek-OCR 本地部署实践(适合新手、windows环境)
  • 10月24日日记
  • 2025.10.24总结 - A
  • 事务的隔离级别 - Higurashi
  • 2025年AI优化:AI优化公司技术实力哪家好
  • 总账系统核心设计 - 智慧园区
  • 每日反思(2025_10_24)
  • 10月24号
  • 10月阅读笔记(3)
  • python操作pdf的库
  • 使用Python将iOS快照从KTX格式转换为PNG
  • 我有一个好主意,既然我之前写了一个AI Vtuber
  • 第二十天
  • AI优化服务商:AI优化公司技术实力榜单
  • AI优化服务商:推荐AI优化排名TOP头部公司
  • 2025最新平台,快手刷站自助下单_新站如何用快手刷站服务?
  • 免费刷快手粉双击网站,刷粉真的安全吗
  • 北京AI优化:AI优化企业排行榜与深度解析
  • 10.24作业
  • 2025年承压水箱厂家权威推荐榜:专业制造工艺与耐用性能深度解析,工业级承压水箱/定制承压水箱/高效承压水箱优质供应商精选
  • 玩转单片机之智能车小露——七彩LED呼吸灯
  • 上海市计算机学会2025.10月赛丙组T5
  • 2025年微信编辑器年度测评:8款工具横评,谁才是内容创作者的效率神助攻?
  • windows 发现音量按键调值不够顺畅
  • CUDA C++ 入门:矩阵乘法
  • 在C语言中,定义常量的方法有哪几种?
  • docker 艹哥笔记
  • 4090显卡安装DCNv2
  • 在windows 上用GPIO定义几个按键