用java在电脑上简单弹出个提示框
Posted 张学涛
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了用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);//设置字体颜色 } } }
以上是关于用java在电脑上简单弹出个提示框的主要内容,如果未能解决你的问题,请参考以下文章