我一直在尝试使用 WindowsBuilder 为 Java 编写睡眠方法,但没有成功。该程序以与我想要的相反方式运行,因此可以说,它休眠然后显示图形。
我如何让程序休眠(延迟,等待)一段时间?
package me.fractional.main;
import java.awt.EventQueue;
import javax.swing.JFrame;
import me.fractional.main.Studio;
import me.fractional.main.GUI;
import javax.swing.JLabel;
import javax.swing.ImageIcon;
import javax.swing.SwingConstants;
import java.awt.Color;
public class main {
public static boolean gamerunning = true;
private JFrame frmFractionalc;
static JLabel logo = new JLabel("");
public static void Sleep(int seconds)
{
try {
Thread.sleep(1000 * seconds);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
main window = new main();
window.frmFractionalc.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
public main() {
initialize();
intro();
}
private void initialize() {
frmFractionalc = new JFrame();
frmFractionalc.getContentPane().setBackground(new Color(0, 139, 139));
frmFractionalc.setBackground(new Color(0, 128, 128));
frmFractionalc.setTitle("Fractional (C) - GameDevStory");
frmFractionalc.setBounds(100, 100, 500, 300);
frmFractionalc.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frmFractionalc.getContentPane().setLayout(null);
logo.setHorizontalAlignment(SwingConstants.CENTER);
logo.setBounds(35, 50, 400, 150);
frmFractionalc.getContentPane().add(logo);
}
public void intro()
{
logo.setIcon(new ImageIcon(main.class.getResource("/me/fractional/main/logo.png")));
Sleep(4);
}
}