I want to show how merge sort perform visually using JFrame
. What I want to do is to make visible subsequent JLabel
with some time delay. I tried many way but all of them appears at same moment with no intermediate delay.
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
// jLabel1.setVisible(false);
jLabel2.setVisible(false);
jLabel3.setVisible(false);
jLabel4.setVisible(false);
jLabel5.setVisible(false);
jLabel6.setVisible(false);
jLabel7.setVisible(false);
final Timer t=new Timer((4000), null);
final int delay=2000;
final ActionListener taskPerformer = new ActionListener() {
public void actionPerformed(ActionEvent evt) {
jLabel1.setVisible(true);
t.getDelay();
jLabel2.setVisible(true);
t.setDelay(3000);
jLabel3.setVisible(true);
t.setDelay(2000);
jLabel4.setVisible(true);
t.setDelay(2000);
jLabel5.setVisible(true);
t.setDelay(2000);
jLabel6.setVisible(true);
t.setDelay(2000);
}
};
new Timer(delay, taskPerformer).start();
But when I click button all the lables appear at same momenet though I have kept delay.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…