日期:2014-05-20 浏览次数:20735 次
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
import javax.swing.SwingWorker;
import javax.swing.UIManager;
/**
*
* @date 13/11/2012
*/
public class LoadingPage extends JPanel {
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
}
catch(Exception e) {
}
JFrame f = new JFrame("Test Loading");
f.getContentPane().add(new LoadingPage(), BorderLayout.CENTER);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.pack();
f.setLocationRelativeTo(null);
f.setVisible(true);
}
});
}
private JButton buttonLoad;
private JLabel labelLoading;
private ImageLoadingWorker worker;
LoadingPage() {
super(new FlowLayout(FlowLayout.CENTER, 50, 50));
buttonLoad = new JButton("Load Image");
labelLoading = new JLabel("Loading ..."); // 这里替换成你的图片 new JLabel(Icon);
worker = new ImageLoadingWorker();
setBorder(BorderFactory.createEmptyBorder(50, 50, 50, 50));
buttonLoad.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
showComponent(labelLoading);
worker.execute();
}