简体   繁体   English

如何获得启动画面以显示消息?

[英]how to obtain a splash screen to display a message?

How can i obtain a flash message ( a black screen that splashes for few seconds ) on screen for the time limit that i suggest ? 在我建议的时间限制内,如何在屏幕上获取Flash消息黑屏,飞溅几秒钟 )?

The whole screen of the computer should go black and there should be a message at the center. 计算机的整个屏幕应该变黑,并且中间应该有一条消息。

For example in the following picture the length and width will be the length and width of the screen of the monitor: 例如,在下面的图片中,长度和宽度将是监视器屏幕的长度和宽度:

图片

Message covering the whole screen 消息覆盖整个屏幕

I want this to be fired if a button is click or on it's own when some event is fired. 如果要触发某个事件,则单击按钮或由其自己触发时,我希望触发此事件。

I'm not sure what you mean. 我不确定你是什么意思。 Try this link . 试试这个链接 Here is also an example provided by Oracle for splash screens. 也是Oracle为启动屏幕提供的示例。

Next time, be sure to provide more information. 下次,请确保提供更多信息。

Here are my suggestions, Since you want this every time you click a button, the splash screen is not a viable solution.I think you have to make a window with your message,but keep in mind that going full screen isn't as simple as making a large panel, you need to look into the underlying OS graphics. 这是我的建议,由于每次单击按钮都需要这样做,因此初始屏幕不是可行的解决方案。我认为您必须使用消息创建一个窗口,但请记住,全屏并不是那么简单作为一个大面板,您需要查看基础的OS图形。 Here is a solution to create a full-screen (non-windowed) application in Java which might be helpful to you. 这是一种使用Java创建全屏(非窗口式)应用程序的解决方案,可能会对您有所帮助。

Also I suggest you to have a look at the Java's Full-Screen mode API . 另外,我建议您看看Java的Full-Screen模式API

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

public class displayFullScreen extends JFrame { 
        private JLabel alarmMessage = new JLabel("Alarm !");
        private JPanel panel = new JPanel();
        public displayFullScreen() {
            setUndecorated(true);
            panel.setLayout(new FlowLayout(FlowLayout.CENTER));
            alarmMessage.setText("Alarm !");
            alarmMessage.setFont(new Font("Cambria",Font.BOLD,100));
            alarmMessage.setForeground(Color.CYAN);
            panel.add(alarmMessage);
            Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
            setBounds(0,0,screenSize.width,screenSize.height);
            panel.setBackground(Color.black);
            add(panel);

            addKeyListener(new KeyAdapter() {
               public void keyPressed(KeyEvent ke) {
                   escapeHandler(ke);
               } 
            });
        }

        public void escapeHandler(KeyEvent ke) {
            if(ke.getKeyCode() == ke.VK_ESCAPE) {
                displayFullScreen.this.dispose();
            } 
        }

} }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM