CS506 Web Design and Development Assignment 4 Solution Fall 2012

Question:
You have to develop a GUI based application to demonstrate the working of threads in such a way that it displays each loop execution for thread in separate text area as given in the figure below.


Hints:
First understand the threads example given in handouts lecture for console based application.

Note: Your code must be justified enough for 20 marks.

Public class assignment implements ActionListener{
JTextArea[] textarea = new JTextArea[2];
JTextField f1;
JTextField f2;
Thread th1;
Thread th2;
Worker myworker;
//constructor of main class
public assignment(){

 

}
public static void main(String[] args){

 

}

 

//actionperformed function
public void actionPerformed(ActionEvent ae){
 th1 = new Thread(myworker(f1.getText(),0); //0 is jtext area number 1 in jtextarea array
th2 = new Thread (myworker(f2.getText(),1); 1 is jtext area number 2 in jtextarea array
th1.start();
th2.start();
}

 

//This is the worker class that will implements Running interface
   public class Worker implements Runnable{
    int s;
    int speed;
     //The constructor will take two arguments one for speed that will retrived from    textfields and the other will be the JTextArea number because we will not add the static name of the text area.
public Worker(int speed, int s){
}
 public void run(){
 textarea[s].append(.....)
Thread.sleep(speed);
}
    }

Download Complete Solution HERE Assignment4

DOWNLOAD SOLUTION HERE
loading...