import java.awt.BorderLayout; import java.awt.Container; import java.awt.Dimension; import java.awt.Toolkit; import javax.swing.JFrame; import javax.swing.JLabel; public class test extends JFrame { JLabel jlb; public static void main(String args[]) { try { test frame = new test(); frame.setVisible(true); } catch (Exception e) { e.printStackTrace(); } } /** * Create the frame */ public test() { super(); setBounds(100, 100, 296, 127); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); du dd = new du(); // 加载窗口 Thread t = new Thread(dd); t.start(); // 启动线程 try { Thread.sleep(3000); // 你运行的内容 } catch (InterruptedException e) { e.printStackTrace(); } t.stop(); // 当运行完已经关闭线程 dd.dispose(); // 关闭窗口 } class du extends JFrame implements Runnable { String sy = "."; public du() { Container container = getContentPane(); container.setLayout(new BorderLayout()); jlb = new JLabel(); container.add(jlb, BorderLayout.CENTER); this.setSize(200, 50); Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); Dimension frameSize = this.getSize(); if (frameSize.height > screenSize.height) { frameSize.height = screenSize.height; } if (frameSize.width > screenSize.width) { frameSize.width = screenSize.width; } this.setLocation((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2); this.setVisible(true); } public void run() { while (true) { for (int i = 0; i < 8; i++) { try { jlb.setText("读取当中" + sy); Thread.sleep(500); sy += "."; } catch (InterruptedException e) { e.printStackTrace(); } } sy = "."; } } } }