1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
| private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
long startTime = System.currentTimeMillis();long endTime ;
endTime = 0;
Thread thread = new Thread(new DelayedWriter(jTextField3,jTextField5, jTextField4.getText(),endTime));
thread.start();
// long endTime = System.currentTimeMillis();
jLabel18.setText("temps = "+ (endTime-startTime));
}
class DelayedWriter implements Runnable{
JTextField tf;JTextField tf1;
String s1 = jTextField4.getText(),s0 =jTextField2.getText();
String s,str="",str1="";long endTime;
public DelayedWriter(JTextField tf,JTextField tf1, String s,long endTime)
{
this.tf = tf;
this.tf1 = tf1;
this.s=s;
this.endTime=endTime;
}
public void run(){
for (int i=0; i< s.length(); i++)
{
char prem = s1.charAt(i),prem1=s0.charAt(i);
int x= Character.getNumericValue(prem1) ^ Character.getNumericValue(prem);
str1 = String.valueOf(x);
tf.setText(s.substring(0,i+1));
try {
Thread.sleep(1000);
} catch (InterruptedException ex) {
}
tf1.setText(tf1.getText().concat(str1));
try {
Thread.sleep(1000);
} catch (InterruptedException ex) {
}
}
endTime = System.currentTimeMillis();
}
} |
Partager