SlideShare a Scribd company logo
1 of 10
Download to read offline
Set up a JavaFX GUI-based program that shows a 10 times 10 grid of labels that forms a
multiplication table, with the labels displaying the multiplication problems, rather than the
answers. Provide a text input field and a button with an event handler that reads an integer value
from the text input and changes the CSS styling in some obvious way for all problems in the
table with the given answer. When a new answer is entered and the button is clicked, change all
the labels back to the original style, then change the labels showing problems for the new answer
to the new style. Use CSS, not setters, for all the styling. The main point of this lab is to learn
JavaFX, so the grading will include a heavy emphasis on the neatness and general appearance of
your GUI.
Solution
Code:
//multiTable.java
// import required packages
import java.util.List;
import javafx.application.Application;
import javafx.event.Event;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Node;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.HBox;
import javafx.stage.Stage;
// class for revrse multiplication table
public class multiTable extends Application
{
// over ride nethod for setup the grid
@Override
public void start(Stage primaryStage)
{
BorderPane pane1 = new BorderPane();
pane1.setTop(getHbox1());
HBox h_box = new HBox(15);
h_box.setPadding(new Insets(15, 15, 15, 15));
h_box.setAlignment(Pos.TOP_CENTER);
h_box.getStyleClass().add("hbox2");
Label labl = new Label("Enter Answer: ");
h_box.getChildren().add(labl);
TextField textfield1 = new TextField();
h_box.getChildren().add(textfield1);
GridPane grid_pane1 = setUpGrid();
gridmaker griddp = new gridmaker(grid_pane1);
Button Answer = new Button("Find problems");
Answer.addEventHandler(MouseEvent.MOUSE_CLICKED, new EventHandler()
{
@Override
public void handle(Event arg0)
{
List fact = factors(textfield1);
for (int[] RCx1 : fact) {
Node node = griddp.get_chldren()[RCx1[0]][RCx1[1]];
node.setStyle("-fx-background-color: green");
}
}
});
h_box.getChildren().add(Answer);
pane1.setCenter(h_box);
pane1.setBottom(grid_pane1);
Scene scene = new Scene(pane1, 550, 650);
scene.getStylesheets().add(getClass().getResource("application.css").toExternalForm());
primaryStage.setTitle("lab 6");
primaryStage.setScene(scene);
primaryStage.show();
}
// method for grid layout
private HBox getHbox1()
{
HBox hbox2 = new HBox(15);
hbox2.setPadding(new Insets(15, 15, 15, 15));
hbox2.setAlignment(Pos.TOP_CENTER);
hbox2.getStyleClass().add("hbox1");
Label labl = new Label("Multiplication Table");
hbox2.getChildren().add(labl);
return hbox2;
}
// method to setup a grid
public GridPane setUpGrid() {
GridPane pane1 = new GridPane();
Label[][] labels2 = new Label[11][11];
for (int nrow = 0; nrow < 11; nrow++) {
for (int ncol = 0; ncol < 11; ncol++) {
Label labl1 = new Label();
setUpLabel(labl1, ncol, nrow);
labels2[nrow][ncol] = labl1;
pane1.add(labl1, ncol, nrow);
}
}
return pane1;
}
// method to setup label
public void setUpLabel(final Label labl1, final int ncol, final int nrow)
{
labl1.setPrefHeight(50);
labl1.setPrefWidth(50);
labl1.setAlignment(Pos.CENTER);
labl1.setStyle("-fx-stroke-border: black; -fx-border-width: 1;");
String na = String.valueOf(nrow);
String nb = String.valueOf(ncol);
if (nrow == 0 || ncol == 0) {
labl1.getStyleClass().add("gridBorders");
if (nrow == 0) {
labl1.setText(nb);
} else if (ncol == 0) {
labl1.setText(na);
}
} else {
labl1.setText(na + " * " + nb);
labl1.getStyleClass().add("gridInside");
}
}
// method to setup display factor
public List factors(TextField pblm)
{
FactorCalc calcul = new FactorCalc();
int numb = Integer.parseInt(pblm.getText());
System.out.println(numb);
List factors = calcul.FactFind(numb, 10);
System.out.println(factors);
return factors;
}
// main method
public static void main(String[] args) {
launch(args);
}
}
//gridmaker.java
// import required packages
import javafx.scene.Node;
import javafx.scene.layout.GridPane;
// class gridmaker
public class gridmaker
{
// pane object
GridPane grid_pane1;
//constructor
public gridmaker(GridPane grid_pane1)
{
this.grid_pane1 = grid_pane1;
}
// grid size
private int getSize()
{
return grid_pane1.getChildren().size();
}
// method to get column size
public int getColSize()
{
int No_rows = grid_pane1.getRowConstraints().size();
for (int coli = 0; coli < grid_pane1.getChildren().size(); coli++)
{
Node chld = grid_pane1.getChildren().get(coli);
if (chld.isManaged())
{
int Col_index = GridPane.getColumnIndex(chld);
int columnEnd = GridPane.getColumnIndex(chld);
No_rows = Math.max(No_rows, (columnEnd != GridPane.REMAINING ?
columnEnd : Col_index) + 1);
}
}
return No_rows;
}
// method to get row size
public int getSizeRow()
{
int No_rows = grid_pane1.getRowConstraints().size();
for (int coli = 0; coli < grid_pane1.getChildren().size(); coli++) {
Node chld = grid_pane1.getChildren().get(coli);
if (chld.isManaged()) {
int Row_index = GridPane.getRowIndex(chld);
int Row_End = GridPane.getRowIndex(chld);
No_rows = Math.max(No_rows, (Row_End != GridPane.REMAINING ? Row_End :
Row_index) + 1);
}
}
return No_rows;
}
// mehtod to ge column childs
public Node[] getChildColoumn(int Col_no) {
if (Col_no < getSizeRow())
{
return get_chldren()[Col_no];
}
return null;
}
// mehtod to get row childs
public Node[] get_child_row(int RCrowNo)
{
Node sz[] = new Node[getSizeRow()];
if (RCrowNo <= getSizeRow())
{
for (int coli = 0; coli < getSizeRow(); coli++)
{
sz[coli] = getChildColoumn(coli)[RCrowNo];
}
return sz;
}
return null;
}
// mehtod to get child row
public Node[] get_child_row_vise()
{
Node sz[] = new Node[getSize()];
int ncol = getColSize();
int Incr = 0;
for (int coli = 0; coli < ncol; coli++)
{
for (Node sz1 : get_child_row(coli))
{
if (sz1 != null)
{
sz[Incr] = sz1;
Incr++;
}
}
}
return sz;
}
// method to get the childs
public Node[][] get_chldren() {
Node[][] RCnodes = new Node[getSizeRow()][getColSize()];
for (Node RCnode : grid_pane1.getChildren()) {
int nrow = grid_pane1.getRowIndex(RCnode);
int RCcolumn = grid_pane1.getColumnIndex(RCnode);
RCnodes[nrow][RCcolumn] = RCnode;
}
return RCnodes;
}
// method to get the position
public Integer RCpostion(Node RCnode, Pos RCpos) {
if (RCnode != null) {
switch (RCpos) {
case RCRow:
return grid_pane1.getRowIndex(RCnode);
case RCColumn:
return grid_pane1.getColumnIndex(RCnode);
}
}
return null;
}
//enumerator
enum Pos
{
RCRow,
RCColumn;
}
}
//FactorCalc.java
// import required packages
import java.util.ArrayList;
import java.util.List;
// class to compute factor
class FactorCalc
{
public List valLst = new ArrayList();
private int valproblem = 0;
// mehtod for finding the facts
public List FactFind(int valproblem, int limit)
{
int incval = 1;
this.valproblem = valproblem;
while (incval <= limit)
{
if (valproblem % incval == 0)
{
valLst.add(incval);
}
incval++;
}
return funcCombi();
}
// method for functional computation
public List funcCombi()
{
List ValArys = new ArrayList<>();
for (int lp = 0; lp < valLst.size(); lp++)
{
for (int j = 0; j < valLst.size(); j++) {
if (valLst.get(lp) * valLst.get(j) == valproblem)
{
int[] inx = new int[2];
inx[0] = valLst.get(lp);
inx[1] = valLst.get(j);
ValArys.add(inx);
}
}
}
return ValArys;
}
}
//application.css
.hbox1 {
-fx-background-color: gray;
}
.hbox2 {
-fx-background-color: white;
}
.gridBorders {
-fx-background-color: red;
-fx-text-fill:#A3FF47;
-fx-border-style: solid;
-fx-border-width: 1;
-fx-stroke-border: black;
}
.gridInside {
-fx-background-color: gray;
-fx-text-fill: white;
-fx-border-style: solid;
-fx-border-width: 1;
-fx-stroke-border: black;
}
.gridAnswer {
-fx-background-color: white;
-fx-text-fill: black;
}

More Related Content

Similar to Set up a JavaFX GUI-based program that shows a 10 times 10 grid of la.pdf

ES6 patterns in the wild
ES6 patterns in the wildES6 patterns in the wild
ES6 patterns in the wildJoe Morgan
 
Fee managment system
Fee managment systemFee managment system
Fee managment systemfairy9912
 
AJUG April 2011 Cascading example
AJUG April 2011 Cascading exampleAJUG April 2011 Cascading example
AJUG April 2011 Cascading exampleChristopher Curtin
 
The Ring programming language version 1.5.1 book - Part 175 of 180
The Ring programming language version 1.5.1 book - Part 175 of 180 The Ring programming language version 1.5.1 book - Part 175 of 180
The Ring programming language version 1.5.1 book - Part 175 of 180 Mahmoud Samir Fayed
 
Create a java project that - Draw a circle with three random init.pdf
Create a java project that - Draw a circle with three random init.pdfCreate a java project that - Draw a circle with three random init.pdf
Create a java project that - Draw a circle with three random init.pdfarihantmobileselepun
 
So I have this code(StackInAllSocks) and I implemented the method but.pdf
So I have this code(StackInAllSocks) and I implemented the method but.pdfSo I have this code(StackInAllSocks) and I implemented the method but.pdf
So I have this code(StackInAllSocks) and I implemented the method but.pdfaksahnan
 
Powering code reuse with context and render props
Powering code reuse with context and render propsPowering code reuse with context and render props
Powering code reuse with context and render propsForbes Lindesay
 
Initial UI Mockup - Part 3 - Transcript.pdf
Initial UI Mockup - Part 3 - Transcript.pdfInitial UI Mockup - Part 3 - Transcript.pdf
Initial UI Mockup - Part 3 - Transcript.pdfShaiAlmog1
 
Data structures cs301 power point slides lecture 03
Data structures   cs301 power point slides lecture 03Data structures   cs301 power point slides lecture 03
Data structures cs301 power point slides lecture 03Nasir Mehmood
 
Stay with React.js in 2020
Stay with React.js in 2020Stay with React.js in 2020
Stay with React.js in 2020Jerry Liao
 
The Future of JVM Languages
The Future of JVM Languages The Future of JVM Languages
The Future of JVM Languages VictorSzoltysek
 
Creating a Facebook Clone - Part XXIX - Transcript.pdf
Creating a Facebook Clone - Part XXIX - Transcript.pdfCreating a Facebook Clone - Part XXIX - Transcript.pdf
Creating a Facebook Clone - Part XXIX - Transcript.pdfShaiAlmog1
 
package singlylinkedlist; public class Node { public String valu.pdf
package singlylinkedlist; public class Node { public String valu.pdfpackage singlylinkedlist; public class Node { public String valu.pdf
package singlylinkedlist; public class Node { public String valu.pdfamazing2001
 

Similar to Set up a JavaFX GUI-based program that shows a 10 times 10 grid of la.pdf (20)

ES6 patterns in the wild
ES6 patterns in the wildES6 patterns in the wild
ES6 patterns in the wild
 
Fee managment system
Fee managment systemFee managment system
Fee managment system
 
AJUG April 2011 Cascading example
AJUG April 2011 Cascading exampleAJUG April 2011 Cascading example
AJUG April 2011 Cascading example
 
The Ring programming language version 1.5.1 book - Part 175 of 180
The Ring programming language version 1.5.1 book - Part 175 of 180 The Ring programming language version 1.5.1 book - Part 175 of 180
The Ring programming language version 1.5.1 book - Part 175 of 180
 
Scala on Your Phone
Scala on Your PhoneScala on Your Phone
Scala on Your Phone
 
Create a java project that - Draw a circle with three random init.pdf
Create a java project that - Draw a circle with three random init.pdfCreate a java project that - Draw a circle with three random init.pdf
Create a java project that - Draw a circle with three random init.pdf
 
CSharp v1.0.2
CSharp v1.0.2CSharp v1.0.2
CSharp v1.0.2
 
So I have this code(StackInAllSocks) and I implemented the method but.pdf
So I have this code(StackInAllSocks) and I implemented the method but.pdfSo I have this code(StackInAllSocks) and I implemented the method but.pdf
So I have this code(StackInAllSocks) and I implemented the method but.pdf
 
Powering code reuse with context and render props
Powering code reuse with context and render propsPowering code reuse with context and render props
Powering code reuse with context and render props
 
Initial UI Mockup - Part 3 - Transcript.pdf
Initial UI Mockup - Part 3 - Transcript.pdfInitial UI Mockup - Part 3 - Transcript.pdf
Initial UI Mockup - Part 3 - Transcript.pdf
 
H base programming
H base programmingH base programming
H base programming
 
To-Do App With Flutter: Step By Step Guide
To-Do App With Flutter: Step By Step GuideTo-Do App With Flutter: Step By Step Guide
To-Do App With Flutter: Step By Step Guide
 
Data structures cs301 power point slides lecture 03
Data structures   cs301 power point slides lecture 03Data structures   cs301 power point slides lecture 03
Data structures cs301 power point slides lecture 03
 
Redux vs Alt
Redux vs AltRedux vs Alt
Redux vs Alt
 
Stay with React.js in 2020
Stay with React.js in 2020Stay with React.js in 2020
Stay with React.js in 2020
 
The Future of JVM Languages
The Future of JVM Languages The Future of JVM Languages
The Future of JVM Languages
 
Creating a Facebook Clone - Part XXIX - Transcript.pdf
Creating a Facebook Clone - Part XXIX - Transcript.pdfCreating a Facebook Clone - Part XXIX - Transcript.pdf
Creating a Facebook Clone - Part XXIX - Transcript.pdf
 
C++ practical
C++ practicalC++ practical
C++ practical
 
package singlylinkedlist; public class Node { public String valu.pdf
package singlylinkedlist; public class Node { public String valu.pdfpackage singlylinkedlist; public class Node { public String valu.pdf
package singlylinkedlist; public class Node { public String valu.pdf
 
C# labprograms
C# labprogramsC# labprograms
C# labprograms
 

More from xlynettalampleyxc

According to the IRS, 1.1 of tax returns will be audited in 2011. A.pdf
According to the IRS, 1.1 of tax returns will be audited in 2011. A.pdfAccording to the IRS, 1.1 of tax returns will be audited in 2011. A.pdf
According to the IRS, 1.1 of tax returns will be audited in 2011. A.pdfxlynettalampleyxc
 
Write a SELECT statement that returns a single value that represents.pdf
Write a SELECT statement that returns a single value that represents.pdfWrite a SELECT statement that returns a single value that represents.pdf
Write a SELECT statement that returns a single value that represents.pdfxlynettalampleyxc
 
which represents the ground state for the N- ion i. w.ia ere sm.pdf
which represents the ground state for the N- ion  i. w.ia ere sm.pdfwhich represents the ground state for the N- ion  i. w.ia ere sm.pdf
which represents the ground state for the N- ion i. w.ia ere sm.pdfxlynettalampleyxc
 
what is the prediction equation for the median income and incarcerat.pdf
what is the prediction equation for the median income and incarcerat.pdfwhat is the prediction equation for the median income and incarcerat.pdf
what is the prediction equation for the median income and incarcerat.pdfxlynettalampleyxc
 
What is the ecological and environmental importance of salinityoxyg.pdf
What is the ecological and environmental importance of salinityoxyg.pdfWhat is the ecological and environmental importance of salinityoxyg.pdf
What is the ecological and environmental importance of salinityoxyg.pdfxlynettalampleyxc
 
WEP has vulnerabilities. Which of the following is not a reason why .pdf
WEP has vulnerabilities. Which of the following is not a reason why .pdfWEP has vulnerabilities. Which of the following is not a reason why .pdf
WEP has vulnerabilities. Which of the following is not a reason why .pdfxlynettalampleyxc
 
Two astronauts are 2.40 m apart in their spaceship. One speaks to the.pdf
Two astronauts are 2.40 m apart in their spaceship. One speaks to the.pdfTwo astronauts are 2.40 m apart in their spaceship. One speaks to the.pdf
Two astronauts are 2.40 m apart in their spaceship. One speaks to the.pdfxlynettalampleyxc
 
The ratio of the probability of disease in an exposed group to the p.pdf
The ratio of the probability of disease in an exposed group to the p.pdfThe ratio of the probability of disease in an exposed group to the p.pdf
The ratio of the probability of disease in an exposed group to the p.pdfxlynettalampleyxc
 
The output should now look like this Row 1 sum 30 Row 2 sum.pdf
The output should now look like this Row 1 sum 30 Row 2 sum.pdfThe output should now look like this Row 1 sum 30 Row 2 sum.pdf
The output should now look like this Row 1 sum 30 Row 2 sum.pdfxlynettalampleyxc
 
The end problem in eukaryotic DNA replicationa. is solved by t.pdf
The end problem in eukaryotic DNA replicationa. is solved by t.pdfThe end problem in eukaryotic DNA replicationa. is solved by t.pdf
The end problem in eukaryotic DNA replicationa. is solved by t.pdfxlynettalampleyxc
 
Suppose that one obtained the following DNA sequence data for the fou.pdf
Suppose that one obtained the following DNA sequence data for the fou.pdfSuppose that one obtained the following DNA sequence data for the fou.pdf
Suppose that one obtained the following DNA sequence data for the fou.pdfxlynettalampleyxc
 
Sample of DNA isolated from bacterium X contains 17.5 of adenine.pdf
Sample of DNA isolated from bacterium X contains 17.5 of adenine.pdfSample of DNA isolated from bacterium X contains 17.5 of adenine.pdf
Sample of DNA isolated from bacterium X contains 17.5 of adenine.pdfxlynettalampleyxc
 
Practice using layouts Anderson, Franceschi import javax..pdf
Practice using layouts Anderson, Franceschi import javax..pdfPractice using layouts Anderson, Franceschi import javax..pdf
Practice using layouts Anderson, Franceschi import javax..pdfxlynettalampleyxc
 
Please, I need a correct answer and clear explanation. open image an.pdf
Please, I need a correct answer and clear explanation. open image an.pdfPlease, I need a correct answer and clear explanation. open image an.pdf
Please, I need a correct answer and clear explanation. open image an.pdfxlynettalampleyxc
 
Patient 2 Patient #2 Jan Johnson Next, Dr. Gupta sees Jan Johnson. .pdf
Patient 2 Patient #2 Jan Johnson Next, Dr. Gupta sees Jan Johnson. .pdfPatient 2 Patient #2 Jan Johnson Next, Dr. Gupta sees Jan Johnson. .pdf
Patient 2 Patient #2 Jan Johnson Next, Dr. Gupta sees Jan Johnson. .pdfxlynettalampleyxc
 
Non-math and physics question, but engineering orientated.Identify.pdf
Non-math and physics question, but engineering orientated.Identify.pdfNon-math and physics question, but engineering orientated.Identify.pdf
Non-math and physics question, but engineering orientated.Identify.pdfxlynettalampleyxc
 
Name three properties of the waveform that can be changed with the m.pdf
Name three properties of the waveform that can be changed with the m.pdfName three properties of the waveform that can be changed with the m.pdf
Name three properties of the waveform that can be changed with the m.pdfxlynettalampleyxc
 
Inventory Valuation FIFO, LIFO, and Average The company reported the.pdf
Inventory Valuation FIFO, LIFO, and Average The company reported the.pdfInventory Valuation FIFO, LIFO, and Average The company reported the.pdf
Inventory Valuation FIFO, LIFO, and Average The company reported the.pdfxlynettalampleyxc
 
In December 2009, a 45-year-old female presented to the emergency dep.pdf
In December 2009, a 45-year-old female presented to the emergency dep.pdfIn December 2009, a 45-year-old female presented to the emergency dep.pdf
In December 2009, a 45-year-old female presented to the emergency dep.pdfxlynettalampleyxc
 
In a longitudinal study of attitude toward statistics, a doctoral st.pdf
In a longitudinal study of attitude toward statistics, a doctoral st.pdfIn a longitudinal study of attitude toward statistics, a doctoral st.pdf
In a longitudinal study of attitude toward statistics, a doctoral st.pdfxlynettalampleyxc
 

More from xlynettalampleyxc (20)

According to the IRS, 1.1 of tax returns will be audited in 2011. A.pdf
According to the IRS, 1.1 of tax returns will be audited in 2011. A.pdfAccording to the IRS, 1.1 of tax returns will be audited in 2011. A.pdf
According to the IRS, 1.1 of tax returns will be audited in 2011. A.pdf
 
Write a SELECT statement that returns a single value that represents.pdf
Write a SELECT statement that returns a single value that represents.pdfWrite a SELECT statement that returns a single value that represents.pdf
Write a SELECT statement that returns a single value that represents.pdf
 
which represents the ground state for the N- ion i. w.ia ere sm.pdf
which represents the ground state for the N- ion  i. w.ia ere sm.pdfwhich represents the ground state for the N- ion  i. w.ia ere sm.pdf
which represents the ground state for the N- ion i. w.ia ere sm.pdf
 
what is the prediction equation for the median income and incarcerat.pdf
what is the prediction equation for the median income and incarcerat.pdfwhat is the prediction equation for the median income and incarcerat.pdf
what is the prediction equation for the median income and incarcerat.pdf
 
What is the ecological and environmental importance of salinityoxyg.pdf
What is the ecological and environmental importance of salinityoxyg.pdfWhat is the ecological and environmental importance of salinityoxyg.pdf
What is the ecological and environmental importance of salinityoxyg.pdf
 
WEP has vulnerabilities. Which of the following is not a reason why .pdf
WEP has vulnerabilities. Which of the following is not a reason why .pdfWEP has vulnerabilities. Which of the following is not a reason why .pdf
WEP has vulnerabilities. Which of the following is not a reason why .pdf
 
Two astronauts are 2.40 m apart in their spaceship. One speaks to the.pdf
Two astronauts are 2.40 m apart in their spaceship. One speaks to the.pdfTwo astronauts are 2.40 m apart in their spaceship. One speaks to the.pdf
Two astronauts are 2.40 m apart in their spaceship. One speaks to the.pdf
 
The ratio of the probability of disease in an exposed group to the p.pdf
The ratio of the probability of disease in an exposed group to the p.pdfThe ratio of the probability of disease in an exposed group to the p.pdf
The ratio of the probability of disease in an exposed group to the p.pdf
 
The output should now look like this Row 1 sum 30 Row 2 sum.pdf
The output should now look like this Row 1 sum 30 Row 2 sum.pdfThe output should now look like this Row 1 sum 30 Row 2 sum.pdf
The output should now look like this Row 1 sum 30 Row 2 sum.pdf
 
The end problem in eukaryotic DNA replicationa. is solved by t.pdf
The end problem in eukaryotic DNA replicationa. is solved by t.pdfThe end problem in eukaryotic DNA replicationa. is solved by t.pdf
The end problem in eukaryotic DNA replicationa. is solved by t.pdf
 
Suppose that one obtained the following DNA sequence data for the fou.pdf
Suppose that one obtained the following DNA sequence data for the fou.pdfSuppose that one obtained the following DNA sequence data for the fou.pdf
Suppose that one obtained the following DNA sequence data for the fou.pdf
 
Sample of DNA isolated from bacterium X contains 17.5 of adenine.pdf
Sample of DNA isolated from bacterium X contains 17.5 of adenine.pdfSample of DNA isolated from bacterium X contains 17.5 of adenine.pdf
Sample of DNA isolated from bacterium X contains 17.5 of adenine.pdf
 
Practice using layouts Anderson, Franceschi import javax..pdf
Practice using layouts Anderson, Franceschi import javax..pdfPractice using layouts Anderson, Franceschi import javax..pdf
Practice using layouts Anderson, Franceschi import javax..pdf
 
Please, I need a correct answer and clear explanation. open image an.pdf
Please, I need a correct answer and clear explanation. open image an.pdfPlease, I need a correct answer and clear explanation. open image an.pdf
Please, I need a correct answer and clear explanation. open image an.pdf
 
Patient 2 Patient #2 Jan Johnson Next, Dr. Gupta sees Jan Johnson. .pdf
Patient 2 Patient #2 Jan Johnson Next, Dr. Gupta sees Jan Johnson. .pdfPatient 2 Patient #2 Jan Johnson Next, Dr. Gupta sees Jan Johnson. .pdf
Patient 2 Patient #2 Jan Johnson Next, Dr. Gupta sees Jan Johnson. .pdf
 
Non-math and physics question, but engineering orientated.Identify.pdf
Non-math and physics question, but engineering orientated.Identify.pdfNon-math and physics question, but engineering orientated.Identify.pdf
Non-math and physics question, but engineering orientated.Identify.pdf
 
Name three properties of the waveform that can be changed with the m.pdf
Name three properties of the waveform that can be changed with the m.pdfName three properties of the waveform that can be changed with the m.pdf
Name three properties of the waveform that can be changed with the m.pdf
 
Inventory Valuation FIFO, LIFO, and Average The company reported the.pdf
Inventory Valuation FIFO, LIFO, and Average The company reported the.pdfInventory Valuation FIFO, LIFO, and Average The company reported the.pdf
Inventory Valuation FIFO, LIFO, and Average The company reported the.pdf
 
In December 2009, a 45-year-old female presented to the emergency dep.pdf
In December 2009, a 45-year-old female presented to the emergency dep.pdfIn December 2009, a 45-year-old female presented to the emergency dep.pdf
In December 2009, a 45-year-old female presented to the emergency dep.pdf
 
In a longitudinal study of attitude toward statistics, a doctoral st.pdf
In a longitudinal study of attitude toward statistics, a doctoral st.pdfIn a longitudinal study of attitude toward statistics, a doctoral st.pdf
In a longitudinal study of attitude toward statistics, a doctoral st.pdf
 

Recently uploaded

microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfSumit Tiwari
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsKarinaGenton
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxRoyAbrique
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 

Recently uploaded (20)

microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its Characteristics
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 

Set up a JavaFX GUI-based program that shows a 10 times 10 grid of la.pdf

  • 1. Set up a JavaFX GUI-based program that shows a 10 times 10 grid of labels that forms a multiplication table, with the labels displaying the multiplication problems, rather than the answers. Provide a text input field and a button with an event handler that reads an integer value from the text input and changes the CSS styling in some obvious way for all problems in the table with the given answer. When a new answer is entered and the button is clicked, change all the labels back to the original style, then change the labels showing problems for the new answer to the new style. Use CSS, not setters, for all the styling. The main point of this lab is to learn JavaFX, so the grading will include a heavy emphasis on the neatness and general appearance of your GUI. Solution Code: //multiTable.java // import required packages import java.util.List; import javafx.application.Application; import javafx.event.Event; import javafx.event.EventHandler; import javafx.geometry.Insets; import javafx.geometry.Pos; import javafx.scene.Node; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.control.Label; import javafx.scene.control.TextField; import javafx.scene.input.MouseEvent; import javafx.scene.layout.BorderPane; import javafx.scene.layout.GridPane; import javafx.scene.layout.HBox; import javafx.stage.Stage; // class for revrse multiplication table public class multiTable extends Application { // over ride nethod for setup the grid @Override
  • 2. public void start(Stage primaryStage) { BorderPane pane1 = new BorderPane(); pane1.setTop(getHbox1()); HBox h_box = new HBox(15); h_box.setPadding(new Insets(15, 15, 15, 15)); h_box.setAlignment(Pos.TOP_CENTER); h_box.getStyleClass().add("hbox2"); Label labl = new Label("Enter Answer: "); h_box.getChildren().add(labl); TextField textfield1 = new TextField(); h_box.getChildren().add(textfield1); GridPane grid_pane1 = setUpGrid(); gridmaker griddp = new gridmaker(grid_pane1); Button Answer = new Button("Find problems"); Answer.addEventHandler(MouseEvent.MOUSE_CLICKED, new EventHandler() { @Override public void handle(Event arg0) { List fact = factors(textfield1); for (int[] RCx1 : fact) { Node node = griddp.get_chldren()[RCx1[0]][RCx1[1]]; node.setStyle("-fx-background-color: green"); } } }); h_box.getChildren().add(Answer); pane1.setCenter(h_box); pane1.setBottom(grid_pane1); Scene scene = new Scene(pane1, 550, 650); scene.getStylesheets().add(getClass().getResource("application.css").toExternalForm()); primaryStage.setTitle("lab 6"); primaryStage.setScene(scene); primaryStage.show();
  • 3. } // method for grid layout private HBox getHbox1() { HBox hbox2 = new HBox(15); hbox2.setPadding(new Insets(15, 15, 15, 15)); hbox2.setAlignment(Pos.TOP_CENTER); hbox2.getStyleClass().add("hbox1"); Label labl = new Label("Multiplication Table"); hbox2.getChildren().add(labl); return hbox2; } // method to setup a grid public GridPane setUpGrid() { GridPane pane1 = new GridPane(); Label[][] labels2 = new Label[11][11]; for (int nrow = 0; nrow < 11; nrow++) { for (int ncol = 0; ncol < 11; ncol++) { Label labl1 = new Label(); setUpLabel(labl1, ncol, nrow); labels2[nrow][ncol] = labl1; pane1.add(labl1, ncol, nrow); } } return pane1; } // method to setup label public void setUpLabel(final Label labl1, final int ncol, final int nrow) { labl1.setPrefHeight(50); labl1.setPrefWidth(50); labl1.setAlignment(Pos.CENTER); labl1.setStyle("-fx-stroke-border: black; -fx-border-width: 1;"); String na = String.valueOf(nrow); String nb = String.valueOf(ncol); if (nrow == 0 || ncol == 0) {
  • 4. labl1.getStyleClass().add("gridBorders"); if (nrow == 0) { labl1.setText(nb); } else if (ncol == 0) { labl1.setText(na); } } else { labl1.setText(na + " * " + nb); labl1.getStyleClass().add("gridInside"); } } // method to setup display factor public List factors(TextField pblm) { FactorCalc calcul = new FactorCalc(); int numb = Integer.parseInt(pblm.getText()); System.out.println(numb); List factors = calcul.FactFind(numb, 10); System.out.println(factors); return factors; } // main method public static void main(String[] args) { launch(args); } } //gridmaker.java // import required packages import javafx.scene.Node; import javafx.scene.layout.GridPane; // class gridmaker public class gridmaker { // pane object GridPane grid_pane1;
  • 5. //constructor public gridmaker(GridPane grid_pane1) { this.grid_pane1 = grid_pane1; } // grid size private int getSize() { return grid_pane1.getChildren().size(); } // method to get column size public int getColSize() { int No_rows = grid_pane1.getRowConstraints().size(); for (int coli = 0; coli < grid_pane1.getChildren().size(); coli++) { Node chld = grid_pane1.getChildren().get(coli); if (chld.isManaged()) { int Col_index = GridPane.getColumnIndex(chld); int columnEnd = GridPane.getColumnIndex(chld); No_rows = Math.max(No_rows, (columnEnd != GridPane.REMAINING ? columnEnd : Col_index) + 1); } } return No_rows; } // method to get row size public int getSizeRow() { int No_rows = grid_pane1.getRowConstraints().size(); for (int coli = 0; coli < grid_pane1.getChildren().size(); coli++) { Node chld = grid_pane1.getChildren().get(coli); if (chld.isManaged()) { int Row_index = GridPane.getRowIndex(chld); int Row_End = GridPane.getRowIndex(chld);
  • 6. No_rows = Math.max(No_rows, (Row_End != GridPane.REMAINING ? Row_End : Row_index) + 1); } } return No_rows; } // mehtod to ge column childs public Node[] getChildColoumn(int Col_no) { if (Col_no < getSizeRow()) { return get_chldren()[Col_no]; } return null; } // mehtod to get row childs public Node[] get_child_row(int RCrowNo) { Node sz[] = new Node[getSizeRow()]; if (RCrowNo <= getSizeRow()) { for (int coli = 0; coli < getSizeRow(); coli++) { sz[coli] = getChildColoumn(coli)[RCrowNo]; } return sz; } return null; } // mehtod to get child row public Node[] get_child_row_vise() { Node sz[] = new Node[getSize()]; int ncol = getColSize(); int Incr = 0; for (int coli = 0; coli < ncol; coli++) {
  • 7. for (Node sz1 : get_child_row(coli)) { if (sz1 != null) { sz[Incr] = sz1; Incr++; } } } return sz; } // method to get the childs public Node[][] get_chldren() { Node[][] RCnodes = new Node[getSizeRow()][getColSize()]; for (Node RCnode : grid_pane1.getChildren()) { int nrow = grid_pane1.getRowIndex(RCnode); int RCcolumn = grid_pane1.getColumnIndex(RCnode); RCnodes[nrow][RCcolumn] = RCnode; } return RCnodes; } // method to get the position public Integer RCpostion(Node RCnode, Pos RCpos) { if (RCnode != null) { switch (RCpos) { case RCRow: return grid_pane1.getRowIndex(RCnode); case RCColumn: return grid_pane1.getColumnIndex(RCnode); } } return null; } //enumerator enum Pos {
  • 8. RCRow, RCColumn; } } //FactorCalc.java // import required packages import java.util.ArrayList; import java.util.List; // class to compute factor class FactorCalc { public List valLst = new ArrayList(); private int valproblem = 0; // mehtod for finding the facts public List FactFind(int valproblem, int limit) { int incval = 1; this.valproblem = valproblem; while (incval <= limit) { if (valproblem % incval == 0) { valLst.add(incval); } incval++; } return funcCombi(); } // method for functional computation public List funcCombi() { List ValArys = new ArrayList<>(); for (int lp = 0; lp < valLst.size(); lp++) { for (int j = 0; j < valLst.size(); j++) {
  • 9. if (valLst.get(lp) * valLst.get(j) == valproblem) { int[] inx = new int[2]; inx[0] = valLst.get(lp); inx[1] = valLst.get(j); ValArys.add(inx); } } } return ValArys; } } //application.css .hbox1 { -fx-background-color: gray; } .hbox2 { -fx-background-color: white; } .gridBorders { -fx-background-color: red; -fx-text-fill:#A3FF47; -fx-border-style: solid; -fx-border-width: 1; -fx-stroke-border: black; } .gridInside { -fx-background-color: gray; -fx-text-fill: white; -fx-border-style: solid; -fx-border-width: 1; -fx-stroke-border: black; } .gridAnswer { -fx-background-color: white;