L
lbrtchx
Hi *,
I need to set a member variable in an object, by running a thread.
I think something like that should be doable, because this is how
GUI work right? There is something however I am not getting right here.
With this simple code example I just try to set the Dates of a number
of days from now using a DateFormatter and a given Local.
What is it I am not getting right here?
// __ CODE EXAMPLE
import java.util.*;
import java.text.*;
// __
class Runnbl00 implements Runnable{
private String[] aTimedDays;
private int iDays;
// __
private DateFormat frmttr;
// __
public Runnbl00(int iDays, String aPattern, Locale Lcl){
this.iDays = 1;
if((iDays > 0) && (iDays < 366)){ this.iDays = iDays; }
// __
frmttr = DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.FULL, Lcl);
}
// __
public void run(){
this.aTimedDays = new String[this.iDays];
long lTm = System.currentTimeMillis();
// __
for(int i = 0; (i < this.iDays); ++i){
this.aTimedDays = frmttr.format(new Date(lTm));
System.err.println("// __ in run(): " + aTimedDays);
lTm += 24*60*60*1000;
}// [0, this.iDays)
}
// __
public String[] getTimedDays(){ return(aTimedDays); }
// __
public int getDays(){ return(iDays); }
}
// __
public class TestRunnbl00{
// __
public static void main(String[] aArgs){
int iDays = 7;
String aPattern = "yyyyMMddHHmmss";
Locale Lcl = Locale.FRANCE;
Lcl = new Locale("en","US");
// __
Runnbl00 R = new Runnbl00(iDays, aPattern, Lcl);
(new Thread(R)).start();
String[] aTimedDays = R.getTimedDays();
// __
if((aTimedDays != null) && (aTimedDays.length > 0)){
for(int i = 0; (i < aTimedDays.length); ++i){
System.err.println("// __ in calling object: " + aTimedDays);
}// i [0, aTimedDays.length)
}
else{ System.err.println("// __ in calling object: " + aTimedDays); }
// __
System.err.println("// __ R.getDays(): " + R.getDays());
}
}
Albretch Mueller (lbrtchx)
I need to set a member variable in an object, by running a thread.
I think something like that should be doable, because this is how
GUI work right? There is something however I am not getting right here.
With this simple code example I just try to set the Dates of a number
of days from now using a DateFormatter and a given Local.
What is it I am not getting right here?
// __ CODE EXAMPLE
import java.util.*;
import java.text.*;
// __
class Runnbl00 implements Runnable{
private String[] aTimedDays;
private int iDays;
// __
private DateFormat frmttr;
// __
public Runnbl00(int iDays, String aPattern, Locale Lcl){
this.iDays = 1;
if((iDays > 0) && (iDays < 366)){ this.iDays = iDays; }
// __
frmttr = DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.FULL, Lcl);
}
// __
public void run(){
this.aTimedDays = new String[this.iDays];
long lTm = System.currentTimeMillis();
// __
for(int i = 0; (i < this.iDays); ++i){
this.aTimedDays = frmttr.format(new Date(lTm));
System.err.println("// __ in run(): " + aTimedDays);
lTm += 24*60*60*1000;
}// [0, this.iDays)
}
// __
public String[] getTimedDays(){ return(aTimedDays); }
// __
public int getDays(){ return(iDays); }
}
// __
public class TestRunnbl00{
// __
public static void main(String[] aArgs){
int iDays = 7;
String aPattern = "yyyyMMddHHmmss";
Locale Lcl = Locale.FRANCE;
Lcl = new Locale("en","US");
// __
Runnbl00 R = new Runnbl00(iDays, aPattern, Lcl);
(new Thread(R)).start();
String[] aTimedDays = R.getTimedDays();
// __
if((aTimedDays != null) && (aTimedDays.length > 0)){
for(int i = 0; (i < aTimedDays.length); ++i){
System.err.println("// __ in calling object: " + aTimedDays);
}// i [0, aTimedDays.length)
}
else{ System.err.println("// __ in calling object: " + aTimedDays); }
// __
System.err.println("// __ R.getDays(): " + R.getDays());
}
}
Albretch Mueller (lbrtchx)