package xitongshezhi;
|
import javax.swing.*;
|
import java.awt.*;
|
import java.awt.event.*;
|
import java.text.SimpleDateFormat;
|
import java.util.Date;
|
|
public class banbenguanli extends JFrame {
|
private JPanel mainPanel;
|
private JLabel titleLabel;
|
private JButton closeButton;
|
|
// 版本信息组件
|
private JLabel currentVersionLabel;
|
private JLabel versionDateLabel;
|
private JLabel statusIconLabel;
|
private JLabel statusTitleLabel;
|
private JLabel statusMessageLabel;
|
private JPanel latestVersionPanel;
|
private JLabel latestVersionLabel;
|
|
// 按钮组件
|
private JButton checkUpdateButton;
|
private JButton updateButton;
|
|
// 进度条组件
|
private JProgressBar downloadProgressBar;
|
private JLabel progressPercentLabel;
|
|
// 版本数据
|
private String currentVersion = "V2.3.5";
|
private String currentDate = "2023-10-15";
|
private String latestVersion = "V2.4.0";
|
private boolean updateAvailable = false;
|
|
// 颜色定义
|
private final Color BACKGROUND_COLOR = new Color(15, 28, 48);
|
private final Color CARD_COLOR = new Color(26, 43, 68);
|
private final Color PRIMARY_COLOR = new Color(52, 152, 219);
|
private final Color SECONDARY_COLOR = new Color(46, 204, 113);
|
private final Color WARNING_COLOR = new Color(243, 156, 18);
|
private final Color TEXT_COLOR = new Color(224, 224, 224);
|
private final Color TEXT_LIGHT_COLOR = new Color(160, 200, 255);
|
|
public banbenguanli() {
|
initializeUI();
|
setupEventListeners();
|
updateVersionInfo();
|
}
|
|
private void initializeUI() {
|
// 设置窗口属性 - 7寸竖屏 (480x800)
|
setTitle("版本管理 - UWB人员定位卡发卡机管理系统");
|
setSize(480, 800);
|
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
|
setLocationRelativeTo(null);
|
setResizable(false);
|
|
// 设置不透明背景
|
getContentPane().setBackground(BACKGROUND_COLOR);
|
|
// 主面板
|
mainPanel = new JPanel();
|
mainPanel.setLayout(new BorderLayout());
|
mainPanel.setBackground(BACKGROUND_COLOR);
|
mainPanel.setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));
|
|
// 创建版本管理弹窗内容
|
JPanel versionPanel = createVersionPanel();
|
mainPanel.add(versionPanel, BorderLayout.CENTER);
|
|
add(mainPanel);
|
}
|
|
private JPanel createVersionPanel() {
|
JPanel panel = new JPanel();
|
panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
|
panel.setBackground(CARD_COLOR);
|
panel.setBorder(BorderFactory.createCompoundBorder(
|
BorderFactory.createLineBorder(PRIMARY_COLOR, 1),
|
BorderFactory.createEmptyBorder(25, 25, 25, 25)
|
));
|
|
// 顶部渐变条
|
JPanel gradientBar = new JPanel();
|
gradientBar.setBackground(PRIMARY_COLOR);
|
gradientBar.setPreferredSize(new Dimension(400, 5));
|
gradientBar.setMaximumSize(new Dimension(400, 5));
|
gradientBar.setAlignmentX(Component.CENTER_ALIGNMENT);
|
|
// 标题区域
|
JPanel headerPanel = new JPanel();
|
headerPanel.setLayout(new BoxLayout(headerPanel, BoxLayout.Y_AXIS));
|
headerPanel.setBackground(CARD_COLOR);
|
headerPanel.setAlignmentX(Component.CENTER_ALIGNMENT);
|
|
// 图标
|
JLabel iconLabel = new JLabel("📋");
|
iconLabel.setFont(new Font("Segoe UI Emoji", Font.PLAIN, 42));
|
iconLabel.setAlignmentX(Component.CENTER_ALIGNMENT);
|
iconLabel.setBorder(BorderFactory.createEmptyBorder(0, 0, 15, 0));
|
|
// 标题
|
JLabel titleLabel = new JLabel("版本管理");
|
titleLabel.setFont(new Font("Microsoft YaHei", Font.BOLD, 24));
|
titleLabel.setForeground(TEXT_COLOR);
|
titleLabel.setAlignmentX(Component.CENTER_ALIGNMENT);
|
|
// 副标题
|
JLabel subtitleLabel = new JLabel("UWB人员定位卡发卡机管理系统");
|
subtitleLabel.setFont(new Font("Microsoft YaHei", Font.PLAIN, 14));
|
subtitleLabel.setForeground(TEXT_LIGHT_COLOR);
|
subtitleLabel.setAlignmentX(Component.CENTER_ALIGNMENT);
|
subtitleLabel.setBorder(BorderFactory.createEmptyBorder(5, 0, 25, 0));
|
|
headerPanel.add(iconLabel);
|
headerPanel.add(titleLabel);
|
headerPanel.add(subtitleLabel);
|
|
// 当前版本卡片
|
JPanel currentVersionPanel = createCurrentVersionPanel();
|
|
// 更新状态区域
|
JPanel statusPanel = createStatusPanel();
|
|
// 下载进度
|
JPanel progressPanel = createProgressPanel();
|
|
// 按钮区域
|
JPanel buttonPanel = createButtonPanel();
|
|
// 关闭按钮
|
JButton closeBtn = new JButton("关闭");
|
closeBtn.setFont(new Font("Microsoft YaHei", Font.BOLD, 15));
|
closeBtn.setBackground(new Color(255, 255, 255, 20));
|
closeBtn.setForeground(TEXT_COLOR);
|
closeBtn.setBorder(BorderFactory.createCompoundBorder(
|
BorderFactory.createLineBorder(new Color(255, 255, 255, 50), 1),
|
BorderFactory.createEmptyBorder(12, 20, 12, 20)
|
));
|
closeBtn.setFocusPainted(false);
|
closeBtn.setCursor(new Cursor(Cursor.HAND_CURSOR));
|
closeBtn.setAlignmentX(Component.CENTER_ALIGNMENT);
|
closeBtn.setMaximumSize(new Dimension(400, 45));
|
|
closeButton = closeBtn;
|
|
// 组装所有组件
|
panel.add(gradientBar);
|
panel.add(Box.createRigidArea(new Dimension(0, 20)));
|
panel.add(headerPanel);
|
panel.add(currentVersionPanel);
|
panel.add(Box.createRigidArea(new Dimension(0, 20)));
|
panel.add(statusPanel);
|
panel.add(Box.createRigidArea(new Dimension(0, 15)));
|
panel.add(progressPanel);
|
panel.add(Box.createRigidArea(new Dimension(0, 20)));
|
panel.add(buttonPanel);
|
panel.add(Box.createRigidArea(new Dimension(0, 15)));
|
panel.add(closeBtn);
|
|
return panel;
|
}
|
|
private JPanel createCurrentVersionPanel() {
|
JPanel panel = new JPanel();
|
panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
|
panel.setBackground(new Color(15, 28, 48, 150));
|
panel.setBorder(BorderFactory.createCompoundBorder(
|
BorderFactory.createLineBorder(new Color(255, 255, 255, 12), 1),
|
BorderFactory.createEmptyBorder(20, 20, 20, 20)
|
));
|
panel.setAlignmentX(Component.CENTER_ALIGNMENT);
|
panel.setMaximumSize(new Dimension(400, 150));
|
|
// 版本号标签
|
currentVersionLabel = new JLabel(currentVersion);
|
currentVersionLabel.setFont(new Font("Microsoft YaHei", Font.BOLD, 22));
|
currentVersionLabel.setForeground(Color.WHITE);
|
currentVersionLabel.setBackground(PRIMARY_COLOR);
|
currentVersionLabel.setOpaque(true);
|
currentVersionLabel.setBorder(BorderFactory.createEmptyBorder(10, 25, 10, 25));
|
currentVersionLabel.setAlignmentX(Component.CENTER_ALIGNMENT);
|
|
// 版本描述
|
JLabel versionDescLabel = new JLabel("当前版本");
|
versionDescLabel.setFont(new Font("Microsoft YaHei", Font.PLAIN, 14));
|
versionDescLabel.setForeground(TEXT_LIGHT_COLOR);
|
versionDescLabel.setAlignmentX(Component.CENTER_ALIGNMENT);
|
versionDescLabel.setBorder(BorderFactory.createEmptyBorder(10, 0, 5, 0));
|
|
// 更新日期
|
versionDateLabel = new JLabel("最后更新: " + currentDate);
|
versionDateLabel.setFont(new Font("Microsoft YaHei", Font.PLAIN, 13));
|
versionDateLabel.setForeground(TEXT_LIGHT_COLOR);
|
versionDateLabel.setAlignmentX(Component.CENTER_ALIGNMENT);
|
|
panel.add(currentVersionLabel);
|
panel.add(versionDescLabel);
|
panel.add(versionDateLabel);
|
|
return panel;
|
}
|
|
private JPanel createStatusPanel() {
|
JPanel panel = new JPanel();
|
panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
|
panel.setBackground(new Color(15, 28, 48, 150));
|
panel.setBorder(BorderFactory.createCompoundBorder(
|
BorderFactory.createLineBorder(new Color(255, 255, 255, 12), 1),
|
BorderFactory.createEmptyBorder(20, 20, 20, 20)
|
));
|
panel.setAlignmentX(Component.CENTER_ALIGNMENT);
|
panel.setMaximumSize(new Dimension(400, 200));
|
|
JPanel contentPanel = new JPanel();
|
contentPanel.setLayout(new BoxLayout(contentPanel, BoxLayout.Y_AXIS));
|
contentPanel.setBackground(new Color(15, 28, 48, 0));
|
contentPanel.setAlignmentX(Component.CENTER_ALIGNMENT);
|
|
// 状态图标
|
statusIconLabel = new JLabel("✅");
|
statusIconLabel.setFont(new Font("Segoe UI Emoji", Font.PLAIN, 48));
|
statusIconLabel.setAlignmentX(Component.CENTER_ALIGNMENT);
|
statusIconLabel.setBorder(BorderFactory.createEmptyBorder(0, 0, 10, 0));
|
|
// 状态标题
|
statusTitleLabel = new JLabel("系统已是最新版本");
|
statusTitleLabel.setFont(new Font("Microsoft YaHei", Font.BOLD, 18));
|
statusTitleLabel.setForeground(TEXT_COLOR);
|
statusTitleLabel.setAlignmentX(Component.CENTER_ALIGNMENT);
|
|
// 状态消息
|
statusMessageLabel = new JLabel("您的系统运行的是最新稳定版本,所有功能正常运行。");
|
statusMessageLabel.setFont(new Font("Microsoft YaHei", Font.PLAIN, 13));
|
statusMessageLabel.setForeground(TEXT_LIGHT_COLOR);
|
statusMessageLabel.setAlignmentX(Component.CENTER_ALIGNMENT);
|
statusMessageLabel.setBorder(BorderFactory.createEmptyBorder(10, 0, 15, 0));
|
|
// 最新版本信息面板
|
latestVersionPanel = new JPanel();
|
latestVersionPanel.setLayout(new FlowLayout(FlowLayout.CENTER));
|
latestVersionPanel.setBackground(new Color(243, 156, 18, 38));
|
latestVersionPanel.setBorder(BorderFactory.createCompoundBorder(
|
BorderFactory.createLineBorder(new Color(243, 156, 18, 75), 1),
|
BorderFactory.createEmptyBorder(10, 15, 10, 15)
|
));
|
latestVersionPanel.setAlignmentX(Component.CENTER_ALIGNMENT);
|
latestVersionPanel.setMaximumSize(new Dimension(350, 50));
|
|
JLabel arrowLabel = new JLabel("⬆️");
|
arrowLabel.setFont(new Font("Segoe UI Emoji", Font.PLAIN, 14));
|
|
JLabel latestTextLabel = new JLabel("最新版本: ");
|
latestTextLabel.setFont(new Font("Microsoft YaHei", Font.BOLD, 14));
|
latestTextLabel.setForeground(WARNING_COLOR);
|
|
latestVersionLabel = new JLabel(latestVersion);
|
latestVersionLabel.setFont(new Font("Microsoft YaHei", Font.BOLD, 15));
|
latestVersionLabel.setForeground(WARNING_COLOR);
|
|
latestVersionPanel.add(arrowLabel);
|
latestVersionPanel.add(latestTextLabel);
|
latestVersionPanel.add(latestVersionLabel);
|
latestVersionPanel.setVisible(false);
|
|
contentPanel.add(statusIconLabel);
|
contentPanel.add(statusTitleLabel);
|
contentPanel.add(statusMessageLabel);
|
contentPanel.add(latestVersionPanel);
|
|
panel.add(contentPanel);
|
|
return panel;
|
}
|
|
private JPanel createProgressPanel() {
|
JPanel panel = new JPanel();
|
panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
|
panel.setBackground(CARD_COLOR);
|
panel.setAlignmentX(Component.CENTER_ALIGNMENT);
|
panel.setMaximumSize(new Dimension(400, 60));
|
panel.setVisible(false);
|
|
// 进度信息
|
JPanel infoPanel = new JPanel(new BorderLayout());
|
infoPanel.setBackground(CARD_COLOR);
|
infoPanel.setMaximumSize(new Dimension(400, 25));
|
|
JLabel downloadingLabel = new JLabel("下载更新...");
|
downloadingLabel.setFont(new Font("Microsoft YaHei", Font.PLAIN, 13));
|
downloadingLabel.setForeground(TEXT_LIGHT_COLOR);
|
|
progressPercentLabel = new JLabel("0%");
|
progressPercentLabel.setFont(new Font("Microsoft YaHei", Font.BOLD, 13));
|
progressPercentLabel.setForeground(TEXT_LIGHT_COLOR);
|
|
infoPanel.add(downloadingLabel, BorderLayout.WEST);
|
infoPanel.add(progressPercentLabel, BorderLayout.EAST);
|
|
// 进度条
|
downloadProgressBar = new JProgressBar(0, 100);
|
downloadProgressBar.setValue(0);
|
downloadProgressBar.setBackground(new Color(255, 255, 255, 25));
|
downloadProgressBar.setForeground(SECONDARY_COLOR);
|
downloadProgressBar.setBorder(BorderFactory.createEmptyBorder());
|
downloadProgressBar.setMaximumSize(new Dimension(400, 8));
|
|
panel.add(infoPanel);
|
panel.add(Box.createRigidArea(new Dimension(0, 8)));
|
panel.add(downloadProgressBar);
|
|
return panel;
|
}
|
|
private JPanel createButtonPanel() {
|
JPanel panel = new JPanel();
|
panel.setLayout(new GridLayout(1, 2, 15, 0));
|
panel.setBackground(CARD_COLOR);
|
panel.setAlignmentX(Component.CENTER_ALIGNMENT);
|
panel.setMaximumSize(new Dimension(400, 50));
|
|
// 检查更新按钮
|
checkUpdateButton = new JButton("检查更新");
|
checkUpdateButton.setFont(new Font("Microsoft YaHei", Font.BOLD, 14));
|
checkUpdateButton.setBackground(PRIMARY_COLOR);
|
checkUpdateButton.setForeground(Color.WHITE);
|
checkUpdateButton.setBorder(BorderFactory.createEmptyBorder(12, 0, 12, 0));
|
checkUpdateButton.setFocusPainted(false);
|
checkUpdateButton.setCursor(new Cursor(Cursor.HAND_CURSOR));
|
|
// 立即更新按钮
|
updateButton = new JButton("立即更新");
|
updateButton.setFont(new Font("Microsoft YaHei", Font.BOLD, 14));
|
updateButton.setBackground(new Color(128, 128, 128));
|
updateButton.setForeground(Color.WHITE);
|
updateButton.setBorder(BorderFactory.createEmptyBorder(12, 0, 12, 0));
|
updateButton.setFocusPainted(false);
|
updateButton.setCursor(new Cursor(Cursor.HAND_CURSOR));
|
updateButton.setEnabled(false);
|
|
panel.add(checkUpdateButton);
|
panel.add(updateButton);
|
|
return panel;
|
}
|
|
private void setupEventListeners() {
|
// 关闭按钮
|
closeButton.addActionListener(e -> {
|
dispose();
|
});
|
|
// 检查更新按钮
|
checkUpdateButton.addActionListener(e -> {
|
checkForUpdates();
|
});
|
|
// 立即更新按钮
|
updateButton.addActionListener(e -> {
|
startUpdate();
|
});
|
}
|
|
private void updateVersionInfo() {
|
currentVersionLabel.setText(currentVersion);
|
versionDateLabel.setText("最后更新: " + currentDate);
|
latestVersionLabel.setText(latestVersion);
|
|
if (updateAvailable) {
|
showUpdateAvailable();
|
} else {
|
showUpToDate();
|
}
|
}
|
|
private void showUpToDate() {
|
statusIconLabel.setText("✅");
|
statusTitleLabel.setText("系统已是最新版本");
|
statusMessageLabel.setText("您的系统运行的是最新稳定版本,所有功能正常运行。");
|
latestVersionPanel.setVisible(false);
|
updateButton.setEnabled(false);
|
updateButton.setBackground(new Color(128, 128, 128));
|
}
|
|
private void showUpdateAvailable() {
|
statusIconLabel.setText("⚠️");
|
statusTitleLabel.setText("发现新版本");
|
statusMessageLabel.setText("有新版本可用,建议更新以获得更好的体验和功能。");
|
latestVersionPanel.setVisible(true);
|
updateButton.setEnabled(true);
|
updateButton.setBackground(SECONDARY_COLOR);
|
}
|
|
private void checkForUpdates() {
|
// 保存原始按钮状态
|
String originalText = checkUpdateButton.getText();
|
|
// 显示检查中状态
|
checkUpdateButton.setText("检查中...");
|
checkUpdateButton.setEnabled(false);
|
|
// 模拟网络请求延迟
|
Timer timer = new Timer(2000, e -> {
|
// 随机决定是否有更新
|
updateAvailable = Math.random() > 0.5;
|
|
if (updateAvailable) {
|
showUpdateAvailable();
|
} else {
|
showUpToDate();
|
}
|
|
// 恢复按钮状态
|
checkUpdateButton.setText(originalText);
|
checkUpdateButton.setEnabled(true);
|
|
// 显示检查完成提示
|
String originalMessage = statusMessageLabel.getText();
|
statusMessageLabel.setText(updateAvailable ?
|
"✓ 检查完成,发现新版本可用" :
|
"✓ 检查完成,系统已是最新版本");
|
|
// 3秒后恢复原消息
|
Timer restoreTimer = new Timer(3000, e2 -> {
|
if (updateAvailable) {
|
statusMessageLabel.setText("有新版本可用,建议更新以获得更好的体验和功能。");
|
} else {
|
statusMessageLabel.setText("您的系统运行的是最新稳定版本,所有功能正常运行。");
|
}
|
});
|
restoreTimer.setRepeats(false);
|
restoreTimer.start();
|
});
|
timer.setRepeats(false);
|
timer.start();
|
}
|
|
private void startUpdate() {
|
// 禁用按钮
|
checkUpdateButton.setEnabled(false);
|
updateButton.setEnabled(false);
|
updateButton.setText("更新中...");
|
|
// 显示下载进度
|
JPanel progressPanel = (JPanel) mainPanel.getComponent(0).getComponentAt(275, 500);
|
progressPanel.setVisible(true);
|
|
// 模拟下载进度
|
Timer progressTimer = new Timer(100, null);
|
progressTimer.addActionListener(new ActionListener() {
|
int progress = 0;
|
|
@Override
|
public void actionPerformed(ActionEvent e) {
|
progress += (int) (Math.random() * 8);
|
if (progress >= 100) {
|
progress = 100;
|
progressTimer.stop();
|
|
// 更新完成
|
Timer completionTimer = new Timer(500, e2 -> {
|
progressPanel.setVisible(false);
|
updateButton.setText("更新完成");
|
updateButton.setBackground(new Color(149, 165, 166));
|
|
// 更新版本信息
|
currentVersion = latestVersion;
|
currentDate = new SimpleDateFormat("yyyy-MM-dd").format(new Date());
|
updateAvailable = false;
|
updateVersionInfo();
|
|
// 显示成功消息
|
statusIconLabel.setText("✅");
|
statusTitleLabel.setText("更新完成");
|
statusMessageLabel.setText("系统已成功更新到最新版本,所有功能已优化。");
|
});
|
completionTimer.setRepeats(false);
|
completionTimer.start();
|
}
|
|
downloadProgressBar.setValue(progress);
|
progressPercentLabel.setText(progress + "%");
|
}
|
});
|
progressTimer.start();
|
}
|
|
// 主方法测试
|
public static void main(String[] args) {
|
// 设置系统外观
|
try {
|
UIManager.setLookAndFeel(UIManager.getLookAndFeel());
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
|
SwingUtilities.invokeLater(() -> {
|
banbenguanli frame = new banbenguanli();
|
frame.setVisible(true);
|
});
|
}
|
}
|