用java在电脑上简单弹出个提示框
package test; import javax.swing.*; import java.awt.*; /** * @Author: 张学涛 * @Date: 2020-05-25 11:08 * @Version 1.0 */ public class SimpTest { public static void main(String[] args) { SimpleFrame frame = new SimpleFrame("人脸验证警告:"); frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); //显示 frame.setVisible(true); } static class SimpleFrame extends JFrame { private static final int DEFAULT_WIDTH = 240; private static final int DEFAULT_HEIGHT =100; public SimpleFrame(String title){ setSize(DEFAULT_WIDTH,DEFAULT_HEIGHT); setTitle(title); setBackground(Color.red); //设置框体显示在中央 int windowWidth = this.getWidth(); //获得窗口宽 int windowHeight = this.getHeight(); //获得窗口高 Toolkit kit = Toolkit.getDefaultToolkit(); //定义工具包 Dimension screenSize = kit.getScreenSize(); //获取屏幕的尺寸 int screenWidth = screenSize.width; //获取屏幕的宽 int screenHeight = screenSize.height; //获取屏幕的高 this.setLocation(screenWidth/2-windowWidth/2, screenHeight/2-windowHeight/2);//设置窗口居中显示 this.setUndecorated(true); // this.getRootPane().setWindowDecorationStyle(JRootPane.WARNING_DIALOG);//采用指定的窗口装饰风格 this.getRootPane().setWindowDecorationStyle(JRootPane.ERROR_DIALOG);//采用指定的窗口装饰风格 this.setAlwaysOnTop(true); WordPanel wordPanel= new WordPanel(); getContentPane().add(wordPanel); } } static class WordPanel extends JPanel { private static final int POS_X =30; private static final int POS_Y = 40; @Override public void paintComponent(Graphics g) { super.paintComponent(g); setBackground(Color.WHITE); g.drawString("非本人登录",POS_X,POS_Y); setFont(new Font("黑体",1,18)); setForeground(Color.red);//设置字体颜色 } } }
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通