【赤石科技】电脑温度

2024-J-W010 2025-08-26 11:44:42

运行条件:Java JDK 21,且存放程序的文件名为 EmergencyCooler.java

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class EmergencyCooler {
    private static final int temperature = 95;

    public static void main(String[] args) {
        SwingUtilities.invokeLater(EmergencyCooler::createEmergencyWindow);
    }

    private static void createEmergencyWindow() {
        JFrame frame = new JFrame("!!! 系统温度紧急警报 !!!");
        frame.setSize(600, 400);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setResizable(false);
        frame.setLocationRelativeTo(null);
        frame.setLayout(new BorderLayout());
        frame.getContentPane().setBackground(Color.RED);

        JLabel title = new JLabel("CRITICAL TEMPERATURE ALERT", JLabel.CENTER);
        title.setFont(new Font("Consolas", Font.BOLD, 20));
        title.setForeground(Color.WHITE);
        frame.add(title, BorderLayout.NORTH);

        JLabel tempLabel = new JLabel("CPU 温度: " + temperature, JLabel.CENTER);
        tempLabel.setFont(new Font("宋体", Font.BOLD, 24));
        tempLabel.setForeground(Color.YELLOW);
        frame.add(tempLabel, BorderLayout.CENTER);

        JLabel warning = new JLabel("<html><center>警告!系统温度过高!<br>继续使用可能导致硬件损坏!</center></html>", JLabel.CENTER);
        warning.setFont(new Font("Arial", Font.PLAIN, 16));
        warning.setForeground(Color.WHITE);
        frame.add(warning, BorderLayout.SOUTH);

        frame.setVisible(true);

        Timer timer = new Timer(4000, e -> {
            frame.setVisible(false);
            showCoolingSolution();
        });

        timer.setRepeats(false);
        timer.start();
    }

    private static void showCoolingSolution() {
        JFrame frame = new JFrame("紧急降温方案");
        frame.setSize(500, 300);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setResizable(false);
        frame.setLocationRelativeTo(null);
        frame.setLayout(new BorderLayout());

        JLabel title = new JLabel("请立即执行以下降温操作:", JLabel.CENTER);
        title.setFont(new Font("宋体", Font.BOLD, 18));
        frame.add(title, BorderLayout.NORTH);

        JTextArea solution = new JTextArea();
        solution.setText("""
                降温步骤:

                1. 对着电脑麦克风吹气(冷风)
                2. 用嘴给散热口扇风
                3. 在屏幕上放几块冰块
                4. 把电脑放进冰箱冷冻5分钟

                完成以上操作后点击确认继续。""");

        solution.setFont(new Font("宋体", Font.PLAIN, 16));
        solution.setEditable(false);
        solution.setLineWrap(true);
        solution.setWrapStyleWord(true);
        frame.add(new JScrollPane(solution), BorderLayout.CENTER);

        JButton confirm = new JButton("我已完成物理降温");
        confirm.setFont(new Font("宋体", Font.BOLD, 16));
        confirm.addActionListener(e -> {
            frame.setVisible(false);
            showCoolingProgress();
        });

        JPanel buttonPanel = new JPanel();
        buttonPanel.add(confirm);
        frame.add(buttonPanel, BorderLayout.SOUTH);

        frame.setVisible(true);
    }

    private static void showCoolingProgress() {
        JFrame frame = new JFrame("降温进度");
        frame.setSize(400, 200);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setResizable(false);
        frame.setLocationRelativeTo(null);
        frame.setLayout(new BorderLayout());

        JLabel title = new JLabel("正在验证降温效果...", JLabel.CENTER);
        title.setFont(new Font("宋体", Font.BOLD, 16));
        frame.add(title, BorderLayout.NORTH);

        JProgressBar progressBar = new JProgressBar(0, 100);
        progressBar.setStringPainted(true);
        frame.add(progressBar, BorderLayout.CENTER);

        frame.setVisible(true);

        Timer timer = new Timer(100, new ActionListener() {
            int progress = 0;
            @Override
            public void actionPerformed(ActionEvent e) {
                progress++;
                progressBar.setValue(progress);

                if (progress == 100) {
                    ((Timer)e.getSource()).stop();
                    frame.setVisible(false);
                    showResult();
                }
            }
        });

        timer.start();
    }

    private static void showResult() {
        JFrame frame = new JFrame("降温结果");
        frame.setSize(400, 300);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setResizable(false);
        frame.setLocationRelativeTo(null);
        frame.setLayout(new BorderLayout());

        JLabel result = new JLabel("<html><center>降温成功!<br><br>" +
                "当前温度: 25°C<br><br>" +
                "您的物理降温技巧非常专业!<br>" +
                "建议每2小时重复此操作一次。</center></html>", JLabel.CENTER);

        result.setFont(new Font("宋体", Font.PLAIN, 16));
        frame.add(result, BorderLayout.CENTER);

        JButton close = new JButton("关闭程序");
        close.setFont(new Font("宋体", Font.BOLD, 14));
        close.addActionListener(e -> System.exit(0));

        JPanel buttonPanel = new JPanel();
        buttonPanel.add(close);
        frame.add(buttonPanel, BorderLayout.SOUTH);

        frame.setVisible(true);
    }
}

共 2 条回复

SHY

%%%%%%

wangjunyi2013

%%%