title image


Smiley Re: jprogressBar und zweiter Thread
Sorry!

hier der Code:



public class ProgressBarPanel extends JPanel {



private MainFrame mainFrame;

private ProgressBarThread progressbarThread;

public JProgressBar jpbProgressBar = null;

private JLabel jlTitle = null;

/**

* This is the default constructor

*/

public ProgressBarPanel(MainFrame mainFrame) {

super();

this.mainFrame=mainFrame;

initialize();

}



public void startLoginProzess(boolean allowed){



progressbarThread = new ProgressBarThread(jpbProgressBar);

progressbarThread.start();



try {

progressbarThread.join();

} catch (InterruptedException e) {

e.printStackTrace();

}



if(allowed){

mainFrame.showApplicationTab();

}

else{

JOptionPane.showMessageDialog(null, "Login fehlgeschlagen!");

mainFrame.showLoginPanel();

}

}



/**

* This method initializes this

*

* @return void

*/

private void initialize() {

GridBagConstraints gridBagConstraints2 = new GridBagConstraints();

gridBagConstraints2.gridx = 0;

gridBagConstraints2.anchor = java.awt.GridBagConstraints.WEST;

gridBagConstraints2.insets = new java.awt.Insets(3,0,3,3);

gridBagConstraints2.gridy = 0;

jlTitle = new JLabel();

jlTitle.setText("Login Process...");

GridBagConstraints gridBagConstraints = new GridBagConstraints();

gridBagConstraints.gridx = 0;

gridBagConstraints.gridwidth = 1;

gridBagConstraints.gridy = 1;

this.setLayout(new GridBagLayout());

this.setSize(300, 200);

this.add(getJpbProgressBar(), gridBagConstraints);

this.add(jlTitle, gridBagConstraints2);

}



/**

* This method initializes jpbProgressBar

*

* @return javax.swing.JProgressBar

*/

private JProgressBar getJpbProgressBar() {

if (jpbProgressBar == null) {

jpbProgressBar = new JProgressBar();

jpbProgressBar.setPreferredSize(new java.awt.Dimension(200,26));

}



return jpbProgressBar;

}

}



class ProgressBarThread extends Thread {

private JProgressBar progressBar;



public ProgressBarThread(JProgressBar progressBar) {

this.progressBar = progressBar;

}



public void run() {

long sleepTime = 10;

for (int n = 0; n < 1; n++) {



for (int i = 0; i < 100; i++) {

try {

Thread.sleep(sleepTime);

} catch (InterruptedException e) {

e.printStackTrace();

}

progressBar.setValue(i);

}



for (int j = 100; j > 0; j--) {

try {

Thread.sleep(sleepTime);

} catch (InterruptedException e) {

e.printStackTrace();

}

progressBar.setValue(j);

}

}

}



}



geschrieben von

Login

E-Mail:
  

Passwort:
  

Beitrag anfügen

Symbol:
 
 
 
 
 
 
 
 
 
 
 
 
 

Überschrift: