用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);//設置字體顏色
        }
    }
}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM