Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

import javafx.application.*; import javafx.event.*; import javafx.scene.*; import javafx.scene.control.*; import javafx.scene.control.Alert.*; import javafx.scene.text.*; import javafx.scene.layout.*; import javafx.stage.*; import javafx.geometry.*; import java.io.*; public class GenericGUI extends Application

image text in transcribedimage text in transcribed

import javafx.application.*; import javafx.event.*; import javafx.scene.*; import javafx.scene.control.*; import javafx.scene.control.Alert.*; import javafx.scene.text.*; import javafx.scene.layout.*; import javafx.stage.*; import javafx.geometry.*; import java.io.*;

public class GenericGUI extends Application { // Window attributes Stage stage; Scene scene; VBox root; // GUI Components private TextArea taOutput = new TextArea();

// Main program public static void main(String[] args) { launch(args); } // Callback to start the GUI public void start(Stage _stage) { // Setup window stage = _stage; stage.setTitle("Threads"); stage.setOnCloseRequest( new EventHandler() { public void handle(WindowEvent evt) { System.exit(0); } } ); root = new VBox(); // Format the text area root.getChildren().add(taOutput); taOutput.setFont(Font.font("Monospaced", 14)); // Visible and do work scene = new Scene(root, 600, 200); stage.setScene(scene); stage.show(); Thread t = new Thread() { public void run() { doWork(); } }; t.start(); } // Do the work of the program public void doWork() { } }

Modify GenericGUI.java from the Day18 Downloads to write the program described below The main program will launch the GUI by calling its constructor The constructor will create the following GUI (window size 600x200) Thread 1 generated 86 Thread 5 generated 20 Thread generated9 Thread 2 generated 25 Thread 3 generated 12 Thread 2 generated 10 Thread 3 generated 95 Thread 4 generated 48 Thread 5 generated 92 Thread 1 generated 86 Thread 5 generated 3 As shown above, it will create 5 threads, numbered 1 through 5. Each thread generates a random number and prints a message to the LextArea in the GUI. Do not use Platform.runLater to output to the IextArea In total, each thread will generate 10 random numbers before exiting its run method In a synchronized manner, each thread will Generate a random number between 1 and 100 Output its assigned thread number (your code must assign a thread number to the thread) and the random number it generated to the LextArea, as shown in the example above Create an object called Entry that includes the number of the thread that generated the random number and the value of that random number Store the Entry object in an Arraylist called list that is shared by all threads . * After a thread generates a random number, it should give up control of the processor using the yield method The Entry class will have two members variables, threadNum and numValue and will have appropriate accessor and mutator functions to get and set these member variables After the threads have each generated 10 random numbers each and have been joined in the doWork method, your doWork method should call a method called gutputResults. The gutputResults method will produce the following output. Practical 1 Retake Thread 1 values produced-54 90 15 20 9 50 57 22 17 33 Thread 1 sum-367 Thread 2 values produced -62 39 3041 53 8 72 34 89 13 Thread 2 sum -441 Thread 3 values produced 100 39 4 37 27 61 5 70 77 63 Thread 3 aum -483 Thread 4 valuea produced 64 41 56 61 76 87 46 76 80 Thread 4 aum -590 Thread 5 valuea produced 9e 51 13 39 80 63 75 82 60 84 Thread 5 aum-645 Leaving dotork) For each thread, the outputResults method prints all the random numbers that were produced by each thread and the sum of those random numbers. The random number produced by each thread must be accessed from the Arraylist that the threads wrote to

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

PC Magazine Guide To Client Server Databases

Authors: Joe Salemi

1st Edition

156276070X, 978-1562760700

More Books

Students also viewed these Databases questions