播放器程序启动提示界面 (java版的高仿酷狗音乐播放器制作笔记 1 )

其实程序启动提示界面的制作,主要是为了达到更好的用户体验(因为程序启动时需要加载一些播放器信息,反应速度慢的话,用户就不知道程序是否在启动),同时启动提示界面在显示同时加载必要的信息。

在这个模块的制作过程中主要要解决的问题是,如何去构造一个不规则窗口。要解决不规则窗口这个问题的办法有很多种(我的程序里采用了我所知道的做法中相对较好的一种,自认为是比较容易理解和实现的)。具体的思想是:若窗口有装饰则去掉装饰(JWindow没,JFrame等就有),接下来就要使得窗口背景变透明,再接下来就是在透明的窗口里画上自己想要的东西了,具体画什么,怎么画就要自己选择了(自己设计绘制或者通过一些控件让系统自己绘制,在这里本人选择的时候者,通过JLabel让系统绘制)。

下面是我的代码:

package windows.OrdinaryWindow;


import handler.SizeUtils;


import java.awt.BorderLayout;
import java.awt.Cursor;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;


import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JWindow;
import javax.swing.Timer;


import source.Resource;


import Library.panel.ImagePanel;
import Library.panel.TextPanel;


import com.sun.awt.AWTUtilities;


public class LoadingMsgWindow extends JWindow {


/**

*/
private static final long serialVersionUID = 1L;


private MainWindow mainWindow;
private JLabel center;
private TextPanel anthor;
private ImagePanel versions;
protected Timer timer;
private int i = 0;


public LoadingMsgWindow(MainWindow mainWindow) {
this.mainWindow = mainWindow;
this.setAlwaysOnTop(true);
AWTUtilities.setWindowOpaque(this, false);
this.toFront();
this.initialize();
this.assignComponent();
}


private void initialize() {
this.setLayout(new BorderLayout());
this.setSize(800, 500);
this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
this.setLocation(
(int) (SizeUtils.getScreenSize().getWidth() - this.getWidth()) / 2,
(int) (SizeUtils.getScreenSize().getHeight() - this.getHeight()) / 2 - 50);
center = new JLabel(new ImageIcon(
"images\\CommonImages\\ MusicSign1.png"));
center.setIcon(new ImageIcon("images\\CommonImages\\MusicSign" + (i++)
+ ".png"));
anthor = new TextPanel(Resource.string.author);
timer = new Timer(1000, new ActionListener() {
public void actionPerformed(ActionEvent e) {
center.setIcon(new ImageIcon("images\\CommonImages\\MusicSign"
+ i + ".png"));


if (mainWindow.isReady()) {
destroy();
mainWindow.start();
} else if (i < 4) {
i++;
timer.restart();
} else
timer.restart();
}
});
timer.setRepeats(false);
timer.start();
}


private void assignComponent() {
center.setLayout(null);
versions = new ImagePanel("images\\versions.png");
versions.setBounds(500, 250, 150, 150);
center.add(versions);
anthor.setBounds(20, 400, 760, 50);
anthor.setStroke(true);
/* 添加显示作者的信息*/
center.add(anthor);
this.add(center);
}


public void start() {
this.setVisible(true);
}


public void destroy() {
this.setVisible(false);
this.dispose();
}
}


效果图:






  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值