I know how to display text from thread in console, but how can I put it in TextArea? Also since my text is chars and numbers, how can I convert them to string since TextArea takes only String if I am right?
I need to append PrintNum, LetterSmall and LetterBig in TextArea. Does someone know the way? Any help would be appreciated!
public class pracice extends Application {
@Override
public void start(Stage primaryStage) {
TextArea ta = new TextArea();
Button btn = new Button();
btn.setText("Show");
btn.setOnAction(new EventHandler<ActionEvent>() {
Runnable run = new PrintNum(25);
Thread th1 = new Thread(run);
char lett;
char lettUp;
Runnable let = new LetterSmall(lett);
Thread th2 = new Thread(let);
Runnable lUp = new LetterBig(lettUp);
Thread th3 = new Thread(lUp);
@Override
public void handle(ActionEvent event) {
System.out.append("\nBegin\n");
th1.start();
try{
th1.join(2000);
} catch (InterruptedException e){
e.printStackTrace();
}
th2.start();
try{
th2.join();
} catch (InterruptedException e){
e.printStackTrace();
}
th3.start();
}
});
BorderPane root = new BorderPane();
root.setTop(btn);
root.setCenter(ta);
Scene scene = new Scene(root, 300, 250);
primaryStage.setTitle("Practice");
primaryStage.setScene(scene);
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
class PrintNum implements Runnable {
private int lastNum;
Random r = new Random();
public PrintNum(int n){
lastNum = n;
}
public void run(){
System.out.append("\n");
for(int i = 1; i <= lastNum; i++){
int rN = r.nextInt(25) + 1;
System.out.append((lastNum - rN) + " ");
}
}
}
class LetterSmall implements Runnable {
Random r = new Random();
private char lett;
public LetterSmall(char s){
lett = s;
}
public void run(){
System.out.append("\n");
for(int i = 1; i <= 25; i++){
char c = (char) (r.nextInt(26) + 'a');
lett = c;
System.out.append(lett + " ");
}
}
}
class LetterBig implements Runnable {
Random r = new Random();
private char lettUp;
public LetterBig(char up){
lettUp = up;
}
public void run(){
System.out.append("\n");
for(int i = 1; i <= 25; i++){
char c = (char) (r.nextInt(26) + 'A');
lettUp = c;
System.out.append(lettUp + " ");
}
}
}