每次打开和关闭我的应用程序时,我都希望出现一个小窗口,等待几秒钟。当我启动程序时,一切正常。但是在应用程序运行时创建框架的新实例后,我得到的只是一个白屏。我怎样才能解决这个问题? 请不要介意标签的德语内容。谢谢!
public class WaitingFrame extends JFrame
{
public WaitingFrame(boolean closing)
{
// Window setup. Set title unnecessary 'cause of setUndecorated(true)
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
setLocation((int) screenSize.getWidth() /3, (int) screenSize.getHeight() / 4);
setSize(350,200);
setLayout(new BorderLayout());
GridBagConstraints c = new GridBagConstraints();
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setResizable(false);
setUndecorated(true);
this.getContentPane().setBackground(Color.WHITE);
// Creating Java Swing Components
JPanel bottom = new JPanel(new GridBagLayout());
bottom.setBackground(Color.WHITE);
ImageIcon icon = new ImageIcon("db.png");
JLabel first = new JLabel();
JLabel second = new JLabel("%");
JLabel third = new JLabel();
int waitingTime;
if(!closing)
{
first.setText("Programm startet in ");
third.setText(" Sekunden!");
waitingTime=60;
}
else
{
first.setText("Programm wird in ");
third.setText(" Sekunden beendet!");
waitingTime=30;
}
bottom.add(first,c);
c.gridx = 1;
bottom.add(second,c);
c.gridx = 2;
bottom.add(third,c);
JButton cancel = new JButton("in den Hintergrund");
cancel.addActionListener(new ActionListener()
{
@Override
public void actionPerformed(ActionEvent e)
{
minimize();
}
});
c.gridwidth=3;
c.gridx=0;
c.gridy=1;
bottom.add(cancel,c);
this.getContentPane().add(bottom,BorderLayout.SOUTH);
this.getContentPane().add(new JLabel(icon),BorderLayout.CENTER);
setVisible(true);
for(int i=5;i>0;i--)
{
second.setText(String.valueOf(i));
try {
TimeUnit.SECONDS.sleep(1);
}
catch(InterruptedException sl) {}
}
this.dispose();
if(closing)
System.exit(0);
}
private void minimize()
{
this.setState(Frame.ICONIFIED);
}
}
我知道直到现在可能不会使用某些变量
这是关闭应用程序时得到的一切。 WaitingFrame