给Swing程序添加一款eclipse启动效果
Swingadmin 发布于:2017-07-20 09:18:10
阅读:loading
既然用swing开发程序,最后使用exe的方式运行,其实再往专业(高大上)的方面去实现,可以添加一个软件启动的界面,主要是启动时做一些检查类、校验类相关的动作,并给出相关动作的进度,这些你值得拥有。比较简单,以至于我就不想说太多了,参考代码如下:
package cn.chendd.ui;
import all;
/**
* 主程序
*/
public classStartupMain extends JFrame {
private static final long serialVersionUID= 1L;
private Image splashImage = newImageIcon(getClass().getResource("/splash.png")).getImage();
public JProgressBar bar = new JProgressBar(0, 100);
public JLabel textLabel = new JLabel();
public StartupMain(){
super.setIconImage(newImageIcon(getClass().getResource("/logo.png")).getImage());
super.setSize(splashImage.getWidth(null) , splashImage.getHeight(null));
super.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
super.setLocationRelativeTo(null);
super.setUndecorated(true);
JPaneltextPanel = newJPanel(){
private static final long serialVersionUID= 1L;
@Override
protected void paintComponent(Graphicsg) {
g.drawImage(splashImage, 0, 0, null);
}
};
textPanel.setLayout(null);
textLabel.setFont(new Font("宋体" , Font.PLAIN , 12));
textLabel.setBounds(5, 230, 500,20);
JPanelsouthPanel = newJPanel();
southPanel.setLayout(new BorderLayout());
//设置文本显示位置
textLabel.setText("载入工作台");
textPanel.add(textLabel);
bar.setBorder(null);
bar.setForeground(new Color(10,36,106));
bar.setBackground(new Color(212,208,200));
southPanel.add(bar);
this.add(textPanel);
this.add(southPanel,BorderLayout.SOUTH);
super.setVisible(true);
}
public void setProressBarValue(int value , String text){
this.bar.setValue(value);
this.textLabel.setText(text);
}
/**
* <pre>
* 进度条结束,关闭进度窗口
* </pre>
*/
public void endProgressBar(String[]args){
//启动应用程序
BeautyEyeLNFHelper.frameBorderStyle= BeautyEyeLNFHelper.FrameBorderStyle.translucencyAppleLike;
try {
BeautyEyeLNFHelper.launchBeautyEyeLNF();
}catch(Exception e) {
e.printStackTrace();
}
SwingTheme.launch(SwingTheme.class, args);
this.setVisible(false);
}
}
/**
* 启动面板
*/
package cn.chendd.ui;
import all;
public classSwingTheme extendsSingleFrameApplication {
public static void main(String[] args) throws Exception {
StartupMainmain = newStartupMain();
for (int i = 1; i <= 10; i++){
main.setProressBarValue(i* 10, "载入工作台..." + i * 10 + "%");
Thread.sleep(200L);
}
main.endProgressBar(args);
}
/**
* 调用父类的启动函数
*/
@Override
protected void startup() {
Viewview = getMainView();
JComponentmainPanel = this.createMainPanel();
view.setComponent(mainPanel);
view.setMenuBar(this.createMenuBar());
JFrameframe = (JFrame) view.getRootPane().getParent();
frame.setSize(new Dimension(550, 350));
frame.setTitle("小渣渣");
frame.setLocationRelativeTo(null);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
/**
* 示例演示的代码,可不要
*/
private JComponentcreateMainPanel() {
JPanelmainPanel = newJPanel();
mainPanel.setLayout(new BorderLayout());
mainPanel.add(new JButton("就"), BorderLayout.NORTH);
mainPanel.add(new JButton("问"), BorderLayout.SOUTH);
mainPanel.add(new JButton("服"), BorderLayout.EAST);
mainPanel.add(new JButton("你"), BorderLayout.WEST);
mainPanel.add(new JButton("不服"), BorderLayout.CENTER);
return mainPanel;
}
/**
* 示例演示的代码,可不要
*/
protected JMenuBarcreateMenuBar() {
JMenuBarmenuBar = newJMenuBar();
JMenufileMenu = newJMenu("文件(F) ");
JMenusettingMenu = newJMenu("设置(S) ");
JMenuhelpMenu = newJMenu("帮助(H) ");
menuBar.add(fileMenu);
menuBar.add(settingMenu);
menuBar.add(helpMenu);
return menuBar;
}
}
点赞