Question
Write a WidgetView GUI that has the following widgets:

a button labeled "go up/down"
a label initialized to 0 (we'll call this the left label)
a label initialized to 0 (we'll call this the right label)
a button labeled "go down/up"
a label initialized to “Last Random #s: “ (we’ll call this the numbers label)

When the "go up/down" button is pushed, a random number between 1 and 10 (inclusive) is generated and added to the left label, and another random number between 1 and 10 (inclusive) is generated and subtracted from the right label. The two random numbers are displayed in the numbers label.


When the "go down/up" button is pushed, a random number between 1 and 10 (inclusive) is generated and subtracted from the left label, and another random number between 1 and 10 (inclusive) is generated and added to the right label. The two random numbers are displayed in the numbers label.
The picture below is the output.

3:51 PM ooooo T-Mobile LTE 74% dist-edwaketech.edu Unit 13 Lab Grade Sheet Key For full credit, the program must be implemented as per instru instructions may result in partial to full loss of points. Item Up Down (30 pts) Output Run your application and make screenshots at the points indicated below. Your results may vary because of the random numbers. Initial s go downtup Last random Rs: After clicking left button go updown 6 go downup Last random es: 6,6 After clicking eft button go up down 8-10 go down up Last random Rs 2.4 After clicking right button go updown 14-15 go down up Last random s: 5,6 After clicking right button go up down 20-18 go down up Last random s: 3,6
0 0
Add a comment Improve this question Transcribed image text
Answer #1

package HomeworkLib.swingandfx;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;

import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Alert;
import javafx.scene.control.Alert.AlertType;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TextArea;
import javafx.scene.control.TextField;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.scene.text.Font;
import javafx.scene.text.FontWeight;
import javafx.scene.text.Text;
import javafx.stage.Stage;

public class LeftAnfRightRandomNumber extends Application {

   GridPane grid = null;
   Text scenetitle = null;

   Label leftLabel = null;
   Label rightLabel = null;
   Label lastRamdonNumLabel = null;
   Button goUpAndDownBtn = null;
   Button goDownAndUpBtn = null;
   HBox leftAndRightHBox = null;

   Stage primaryStage = null;

   @Override
   public void start(Stage primaryStage) {

       this.primaryStage = primaryStage;
       grid = new GridPane();

       grid.setAlignment(Pos.CENTER);
       grid.setHgap(5);
       grid.setVgap(5);
       grid.setPadding(new Insets(20, 5, 20, 5));
       grid.setStyle("-fx-background-color: cyan; -fx-grid-lines-visible: false");

       scenetitle = new Text("Number System");
       scenetitle.setFont(Font.font("Tahoma", FontWeight.NORMAL, 20));
       grid.add(scenetitle, 0, 0, 1, 1);

       leftAndRightHBox = new HBox(6);
       goUpAndDownBtn = new Button("go up/down");
       leftAndRightHBox.getChildren().add(goUpAndDownBtn);
       leftLabel = new Label("0");
       leftAndRightHBox.getChildren().add(leftLabel);
       rightLabel = new Label("0");
       leftAndRightHBox.getChildren().add(rightLabel);
       goDownAndUpBtn = new Button("go Down/up");
       leftAndRightHBox.getChildren().add(goDownAndUpBtn);
       lastRamdonNumLabel = new Label("Last Random $s:");
       leftAndRightHBox.setAlignment(Pos.TOP_LEFT);
       leftAndRightHBox.getChildren().add(lastRamdonNumLabel);
       grid.add(leftAndRightHBox, 0, 1, 1, 1);
       leftAndRightHBox.setDisable(false);

       goUpAndDownBtn.setOnAction(new EventHandler<ActionEvent>() {
           @Override
           public void handle(ActionEvent e) {
               handleGoUpAndDownButtonAction(e);
           }
       });

       goDownAndUpBtn.setOnAction(new EventHandler<ActionEvent>() {

           @Override
           public void handle(ActionEvent e) {
               handleGoDownAndUpBtnButtonAction(e);
           }
       });

       Scene scene = new Scene(grid, 575, 425);
       primaryStage.setTitle("File System");
       primaryStage.setScene(scene);
       primaryStage.show();
   }

   public void handleGoUpAndDownButtonAction(ActionEvent event) {
       Random rand = new Random();
       int leftNum = rand.nextInt(10);
       int rightNum = rand.nextInt(10);

       int leftLabelNum = Integer.parseInt(leftLabel.getText());
       int rightLabelNum = Integer.parseInt(rightLabel.getText());

       leftLabel.setText("" + (leftLabelNum + leftNum));
       rightLabel.setText("" + (rightLabelNum - rightNum));
       lastRamdonNumLabel
               .setText("Last Random $s:" + leftNum + "," + rightNum);
   }

   public void handleGoDownAndUpBtnButtonAction(ActionEvent event) {
       Random rand = new Random();
       int leftNum = rand.nextInt(10);
       int rightNum = rand.nextInt(10);

       int leftLabelNum = Integer.parseInt(leftLabel.getText());
       int rightLabelNum = Integer.parseInt(rightLabel.getText());

       leftLabel.setText("" + (leftLabelNum - leftNum));
       rightLabel.setText("" + (rightLabelNum + rightNum));
       lastRamdonNumLabel
               .setText("Last Random $s:" + leftNum + "," + rightNum);
   }

   /**
   * @param args
   * the command line arguments
   */
   public static void main(String[] args) {
       launch(args);
   }
}

Output :

---------------

Add a comment
Know the answer?
Add Answer to:
Write a WidgetView GUI that has the following widgets: a button labeled "go up/down" a label...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a C# Windows Forms App code in Visual studio with a "start", "stop", "up", "down",...

    Write a C# Windows Forms App code in Visual studio with a "start", "stop", "up", "down", "left" and "right" buttons and a textbox. The textbox should start printing numbers from 1 to 100 on the press of the "start" button and stop printing process immediately on the press of "stop" button. Also create a thread after stop button is pressed to allow manual input from  "up", "down", "left" and "right" buttons and print up, down, left or right in the same...

  • Python 3+ (using TKinter): 1.) Develop new TKinter GUI widget class Ed that can be used to teach first-graders addition and subtraction. The GUI should contain two Entry widgets and a Button widget la...

    Python 3+ (using TKinter): 1.) Develop new TKinter GUI widget class Ed that can be used to teach first-graders addition and subtraction. The GUI should contain two Entry widgets and a Button widget labeled "Enter". At start-up, your program should generate (1) two single-digit pseudorandom numbers a and b and (2) an operation op, which could be addition or subtraction—with equal likelihood—using the randrange() function in the random module. The expression a op b will then be displayed in the...

  • This is python3. Please help me out. Develop the following GUI interface to allow the user...

    This is python3. Please help me out. Develop the following GUI interface to allow the user to specify the number of rows and number of columns of cards to be shown to the user. Show default values 2 and 2 for number of rows and number of columns. The buttons "New Game" and "Turn Over" span two column-cells each. Fig 1. The GUI when the program first starts. When the user clicks the "New Game" button, the program will read...

  • C Programming. Write a prograrm that generates a "random walk" across a 10 × 10 array....

    C Programming. Write a prograrm that generates a "random walk" across a 10 × 10 array. The array will con- tain characters (all ' . ' initially). The program must randomly "walk" from element to ele- ment, always going up, down, left, or right by one element. The elements visited by the program will be labeled with the letters A through Z, in the order visited. Here's an example of the desired output: 9. BCD.. F E. H G KR...

  • In Java, please write the program for the following program. Please TEST YOUR PROGRAM. You MUST...

    In Java, please write the program for the following program. Please TEST YOUR PROGRAM. You MUST use GUI, that means all user input must be through the windows. The "first window" is the window on the top left of the following picture. Add 5 more items to be purchased. Search is accessed from second window, top right. Thw third window is the bottom left, and the fourth window is the bottom right. The program MUST CONTAIN EVERYTHING IN THE PICTURES....

  • Write a program that performs the following operations on a one dimensional array with 50 unsigned...

    Write a program that performs the following operations on a one dimensional array with 50 unsigned integers. The main program will initialize the array, print the array values to the screen and then call a function that will determine and print the maximum and minimum values. •Declare the array and any other variables. •Use a loop to initialize the array with 50 random integer values between 0 and 99 using the rand() function. (number = rand() % 100;) •Using cout...

  • Write a C++ program that does the following : 1. Accepts array size from the keyboard....

    Write a C++ program that does the following : 1. Accepts array size from the keyboard. The size must be positive integer that is >= 5 and <= 15 inclusive . 2. Use the size from step 1 in order to create an integer array. Populate the created array with random integer values between 10 and 200. 3. Display the generated array. 4. Write a recursive function that displays the array in reverse order . 5. Write a recursive function...

  • 2. Let's now use Excel to simulate rolling two 6-sided dice and finding the minimum of...

    2. Let's now use Excel to simulate rolling two 6-sided dice and finding the minimum of both dice. • Create a new Excel sheet in your document. Click on cell Al, then click on the function icon f. and select Math&Trig, then select RANDBETWEEN. In the dialog box, enter 1 for bottom and enter 6 for top. • After getting the random number in the first cell, click and hold down the mouse button to drag the lower right corner...

  • Specification Write a program that allows the user to play number guessing games. Playing a Guessing...

    Specification Write a program that allows the user to play number guessing games. Playing a Guessing Game Use rand() function from the Standard C Library to generate a random number between 1 and 100 (inclusive). Prompt the user to enter a guess. Loop until the user guesses the random number or enters a sentinel value (-1) to give up. Print an error message if the user enters a number that is not between 1 and 100. Print an error message...

  • pay no attention to the numbers that it is labeled just do down the list from...

    pay no attention to the numbers that it is labeled just do down the list from top to bottom Alternate Energy Molecules 27) Where do fatty acids enter the aerobic respiration cycle? 28) Where do proteins enter the aerobic respiration cycle? 29) Why can proteins enter the respiration pathway in several places? 30) What extra waste is produced from protein breakdown? Anaerobic Respiration 31) Who does anaerobic respiration? 32) Define obligate anaerobe: 33) How much ATP does anaerobic respiration produce?...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT