1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
sertanlavr [38]
3 years ago
5

How would you write this using Java: Use a TextField's setText method to set value 0 or 1 as a string?

Computers and Technology
1 answer:
katrin [286]3 years ago
3 0

Answer:

Explanation:

The following Java code uses JavaFX to create a canvas in order to fit the 10x10 matrix and then automatically and randomly populates it with 0's and 1's using the setText method to set the values as a String

import javafx.application.Application;

import javafx.scene.Scene;

import javafx.scene.control.TextField;

import javafx.scene.layout.GridPane;

import javafx.stage.Stage;

public class Main extends Application {

   private static final int canvasHEIGHT = 300;

   private static final int canvasWIDTH = 300;

   public void start(Stage primaryStage) {

       GridPane pane = new GridPane();

       for (int i = 0; i < 10; i++) {

           for (int j = 0; j < 10; j++) {

               TextField text = new TextField();

               text.setText(Integer.toString((int)(Math.random() * 2)));

               text.setMinWidth(canvasWIDTH / 10.0);

               text.setMaxWidth(canvasWIDTH / 10.0);

               text.setMinHeight(canvasHEIGHT / 10.0);

               text.setMaxHeight(canvasHEIGHT / 10.0);

               pane.add(text, j, i);

           }

       }

       Scene scene = new Scene(pane, canvasWIDTH, canvasHEIGHT);

       primaryStage.setScene(scene);

       primaryStage.setMinWidth(canvasWIDTH);

       primaryStage.setMinHeight(canvasHEIGHT);

       primaryStage.setTitle("10 by 10 matrix");

       primaryStage.show();

   }

   public static void main(String[] args) {

       Application.launch(args);

   }

}

You might be interested in
After pushing the power switch of the PC to the ʺonʺ position, Bob, the PC repair person, realizes that the power-on lights foun
Nana76 [90]

Answer:

<em>2. Logic</em>

<em></em>

Explanation:

We all know that for the PC to come on, there must be a power input, this means that if the PC does not power on, then there is probably no power input into the PC. <em>It is only logical for Bob to check if the PC is properly connected first when the power-on lights did not come on</em>. People with no technical training should be able to apply this simple logic too.

3 0
3 years ago
You are reviewing the style sheet code written by a colleague and notice several rules that are enclosed between the /* and */ c
Flauer [41]

Answer:

Nothing will happen.

Explanation:

The rules written between /* and */ will be ignored because /* and */ are the standard way of writing comment in a style sheet code. So, whatever fall in between them will be ignored during rendering of the page.

7 0
4 years ago
To be fluent in computer language you must learn 8000 __________? (9 letter word)
zheka24 [161]

Answer:

I believe its Algorithm

Explanation:

4 0
3 years ago
how can you turn on a light switch and it not work, without turning off the power to the whole house?
vitfil [10]

Answer:

Go to the beaker box and turn off the power to that one room. Duh

Explanation:

6 0
3 years ago
PLZ HELP!!! I'm a beginner in coding!
Lina20 [59]

import random

rock,paper,scissors = 1,2,3

choice = int(input("Please choose 1 2 or 3: "))

computer = random.randint(1,3)

player_won = False

draw = False

if choice == computer:

   draw = True

elif choice == 1 and computer == 3:

   player_won = True

elif choice == 2 and computer == 1:

   player_won = True

elif choice == 3 and computer == 2:

   player_won = True

if player_won:

   print("You won!")

elif not player_won and not draw:

   print("The computer won!")

else:

   print("It's a draw!")

First, I recommend importing at the beginning of your program. Also, you can combine all your same datatype variables in one line. You also need to cast your user choice to an integer so you can compare it with the computer's choice. I wrote the if, elif, and else statements using a boolean variable. I simply wrote all the possibilities that would result in the player winning and this would result in the player_won variable being true. If this is the case, we print to the console, "You won!"

4 0
3 years ago
Other questions:
  • How do you fix this windows 7 screen​
    8·1 answer
  • Powerpoint provides only three picture effects. true or false.
    5·1 answer
  • When the hyper-v role is added to a windows server 2012 r2 server, what is loaded first during boot?
    6·1 answer
  • Which statement best expresses the use of Internet sources in a research project versus other types of sources?
    14·1 answer
  • With respect to the five components of social media information systems (SMIS), which of the following statements is true of SM
    11·1 answer
  • What is cutting-edge technology
    6·1 answer
  • Describe a situation in which you have experienced harm as a consequence of a failure of computer security. Was the failure mali
    6·1 answer
  • Why is the technology so effective in tracking contacts
    7·1 answer
  • Why do some people have random numbers as their usernames?
    9·2 answers
  • Definition of Computer forensics?
    12·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!