java制作加载界面_Java如何制作启动界面?
展開全部
大概的思路就是使用線程來計算耗時的32313133353236313431303231363533e58685e5aeb931333337613133操作,在前段顯示啟動的窗口,示例如下:java?代碼/*
*?To?change?this?template,?choose?Tools?|?Templates
*?and?open?the?template?in?the?editor.
*/
package?test;
import?java.awt.AlphaComposite;
import?java.awt.Color;
import?java.awt.Dimension;
import?java.awt.Font;
import?java.awt.Graphics2D;
import?java.awt.SplashScreen;
import?java.util.logging.Level;
import?java.util.logging.Logger;
import?javax.swing.JButton;
import?javax.swing.JFrame;
/**
*
*?@author?root
*/
public?class?SplashTest?{
public?static?void?main(String[]?args)?{
new?Thread()?{
public?void?run()?{
try?{
SplashScreen?splash?=?SplashScreen.getSplashScreen();
Graphics2D?g?=?splash.createGraphics();
g.setColor(Color.RED);
g.drawString("測試文字",?10,?30);
splash.update();
Thread.sleep(1000);
g.setComposite(AlphaComposite.Clear);
g.fillRect(0,?0,?(int)?splash.getSize().getWidth(),?(int)?splash.getSize().getHeight());
splash.setImageURL(SplashTest.class.getResource("/test/SplashScreen.png"));
int?x?=?100,?y?=?100;
String?author?=?"1?2?3?4?5";
g.setFont(new?Font("TimesRoman",?Font.PLAIN,?30));
g.setPaintMode();
for?(int?i?=?0;?i?
g.setColor(new?Color(50,?50,?0));
g.drawString(author,?x?+?i,?y?+?i?-?1);
g.setColor(new?Color(10,?10,?0));
g.drawString(author,?x?+?i?-?1,?y?+?i);
}
g.setColor(Color.red);
g.drawString(author,?x?+?5,?y?+?5);
splash.update();
Thread.sleep(1000);
}?catch?(Exception?ex)?{
Logger.getLogger(SplashTest.class.getName()).log(Level.SEVERE,?null,?ex);
}
}
}.start();
try?{
Thread.sleep(3000);
}?catch?(Exception?e)?{
e.printStackTrace();
}
JFrame?jf?=?new?JFrame("test");
JButton?jb?=?new?JButton("click");
jf.add(jb);
jf.setPreferredSize(new?Dimension(320,?240));
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jf.pack();
jf.setVisible(true);
}
}
總結
以上是生活随笔為你收集整理的java制作加载界面_Java如何制作启动界面?的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: android string参数最大长度
- 下一篇: 鸿蒙系统有那些上市,鸿蒙上市整套系统究竟