title image


Smiley Re: Zeig mal bitte wie
Hier ein Beispiel mit invokeLater:



import javax.swing.*;

import java.awt.event.*;

import java.awt.*;



public class TestGui extends JFrame // implements ActionListener

{

public static void main(String args[]) {

JFrame frame = new TestGui();

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

frame.show();

}



public TestGui() {

setTitle("testPleaseWait");

setSize(300, 400);



Container contentPane = getContentPane();

JButton jb = new JButton("Button");

jb.addActionListener(new ActionListener()

{

JDialog jd = null;

public void actionPerformed(ActionEvent e)

{

jd = new JDialog();

jd.setTitle("Please wait ...");

jd.setModal(true);

jd.setBounds(getX()+(getWidth()/2), getY()+(getHeight()/2), 100, 100);



// Code geht sofort weiter!

SwingUtilities.invokeLater(new Runnable()

{

public void run()

{

callPleaseWait();

jd.dispose();

}

});

jd.setVisible(true);

}

});



contentPane.add(jb, "Center");

}// constructor





private void callPleaseWait()

{

try

{

int nCount = 0;

for (int n = 0; n < 2000; n++)

{

nCount++;

System.out.print("" + nCount);

Thread.sleep(1);

}

}

catch(Exception ex) { ex.printStackTrace(); }

}



}


Gruss,
Christian


geschrieben von

Login

E-Mail:
  

Passwort:
  

Beitrag anfügen

Symbol:
 
 
 
 
 
 
 
 
 
 
 
 
 

Überschrift: