Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/349.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java启动屏幕_Java_Swing_Splash Screen_Japplet - Fatal编程技术网

Java启动屏幕

Java启动屏幕,java,swing,splash-screen,japplet,Java,Swing,Splash Screen,Japplet,我试图在加载小程序之前显示一些文本,因此我制作了一个简单的SSCCE(.org): 如果您运行它,按钮1将在3秒后出现,而在这之前它应该会出现。。。我做错了什么?我认为init()方法必须在项目呈现之前返回。我认为init()方法必须在项目呈现之前返回。JustinKSU讨论了问题的技术部分 更好的策略是使用图像参数在小程序出现之前显示“飞溅”。有关更多详细信息,请参阅 我想要一个固定时间的。。。不仅仅是装载 在这种情况下,在小程序中放置一个CardLayout。将“splash”添加到第一张卡

我试图在加载小程序之前显示一些文本,因此我制作了一个简单的SSCCE(.org):


如果您运行它,按钮1将在3秒后出现,而在这之前它应该会出现。。。我做错了什么?

我认为
init()
方法必须在项目呈现之前返回。

我认为
init()
方法必须在项目呈现之前返回。

JustinKSU讨论了问题的技术部分

更好的策略是使用
图像
参数
在小程序出现之前显示“飞溅”。有关更多详细信息,请参阅

我想要一个固定时间的。。。不仅仅是装载

在这种情况下,在小程序中放置一个
CardLayout
。将“splash”添加到第一张卡,将GUI的其余部分添加到另一张卡。在
init()
的末尾,创建一个不重复的Swing
计时器
,该计时器将使用主GUI翻转到卡上

例如

//
导入java.awt.*;
导入java.awt.event.*;
导入javax.swing.*;
公共类SplashApplet扩展了JApplet{
公共void init(){
最终CardLayout CardLayout=新的CardLayout();
最终JPanel gui=新JPanel(cardLayout);
JPanel splash=新的JPanel();
飞溅。挫折地面(颜色。红色);
添加(splash,“splash”);
JPanel mainGui=新的JPanel();
mainGui.setBackground(颜色:绿色);
添加(mainGui,“main”);
ActionListener=新建ActionListener(){
已执行的公共无效行动(行动事件ae){
显示(gui,“主”);
}
};
定时器=新定时器(3000,侦听器);
//只需要做一次
timer.setRepeats(假);
setContentPane(gui);
验证();
timer.start();
}
}

JustinKSU涵盖了问题的技术部分

更好的策略是使用
图像
参数
在小程序出现之前显示“飞溅”。有关更多详细信息,请参阅

我想要一个固定时间的。。。不仅仅是装载

在这种情况下,在小程序中放置一个
CardLayout
。将“splash”添加到第一张卡,将GUI的其余部分添加到另一张卡。在
init()
的末尾,创建一个不重复的Swing
计时器
,该计时器将使用主GUI翻转到卡上

例如

//
导入java.awt.*;
导入java.awt.event.*;
导入javax.swing.*;
公共类SplashApplet扩展了JApplet{
公共void init(){
最终CardLayout CardLayout=新的CardLayout();
最终JPanel gui=新JPanel(cardLayout);
JPanel splash=新的JPanel();
飞溅。挫折地面(颜色。红色);
添加(splash,“splash”);
JPanel mainGui=新的JPanel();
mainGui.setBackground(颜色:绿色);
添加(mainGui,“main”);
ActionListener=新建ActionListener(){
已执行的公共无效行动(行动事件ae){
显示(gui,“主”);
}
};
定时器=新定时器(3000,侦听器);
//只需要做一次
timer.setRepeats(假);
setContentPane(gui);
验证();
timer.start();
}
}

是的,但我想要一个固定时间的。。。不仅仅是加载。@Jakhr:代码中有一个小错误,就是忽略了关闭计时器。请参阅“使用单行注释编辑”。是的,但我希望在固定时间内使用单行注释。。。不仅仅是加载。@Jakhr:代码中有一个小错误,就是忽略了关闭计时器。请参见“使用单行注释编辑”。
import java.awt.*;
import javax.swing.*;

    public class test extends JApplet {
      public void init() {

                this.add(new JLabel("Button 1"));
                System.out.println("Hello world...");


                try {
                Thread.sleep(3000);
                }catch(Exception hapa) { hapa.printStackTrace(); }


      }
    }
// <applet code='SplashApplet' width='400' height='400'></applet>
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class SplashApplet extends JApplet {

    public void init() {
        final CardLayout cardLayout = new CardLayout();
        final JPanel gui = new JPanel(cardLayout);

        JPanel splash = new JPanel();
        splash.setBackground(Color.RED);
        gui.add(splash, "splash");

        JPanel mainGui = new JPanel();
        mainGui.setBackground(Color.GREEN);
        gui.add(mainGui, "main");

        ActionListener listener = new ActionListener() {
            public void actionPerformed(ActionEvent ae) {
                cardLayout.show(gui, "main");
            }
        };

        Timer timer = new Timer(3000, listener);
        // only needs to be done once
        timer.setRepeats(false);
        setContentPane(gui);
        validate();
        timer.start();
    }
}