Question

Need help creating a GUI using JavaFX. Also to Convert all console input/output to be used...

Need help creating a GUI using JavaFX. Also to Convert all console input/output to be used in a GUI. Here is my Code

import java.util.ArrayList;

import java.util.Arrays;

      import java.util.Collections;

public class Part1_2 {

                public static void main(String[] args) {

                                ArrayList<String> names = new ArrayList<String>();

                                names.add("Wilson");

                                names.add("David");

                                names.add("John");

                                names.add("Eli");

                                names.add("Riley");

                                for (String name : names) {                         

                                                System.out.println(name);

                                }

                                System.out.println("\n");

                                Collections.sort(names);                              

                                for (String name : names) {                         

                                                System.out.println(name);

                                }

                                System.out.println("\n");

                                Collections.shuffle(names);                        

                                for (String name : names) {                         

                                                System.out.println(name);

                                }

                                System.out.println("David: ["+Collections.binarySearch(names, "David")+"]");     

                                System.out.println("Eli: ["+Collections.binarySearch(names, "Eli")+"]");                  

                               

                                names.toArray();                                                            

                                System.out.println(names);                        

                                Arrays.asList(names);                                    

                                System.out.println(names);                        

                }

0 0
Add a comment Improve this question Transcribed image text
Answer #1

SearchGUI_FXML.fxml

<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.TextArea?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.text.Font?>

<AnchorPane id="AnchorPane" prefHeight="317.0" prefWidth="382.0" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/10.0.1" fx:controller="searchgui.SearchGUI_FXMLController">
<children>
<Label layoutX="121.0" layoutY="14.0" text="Names Operation">
<font>
<Font name="System Bold" size="17.0" />
</font>
</Label>
<TextField fx:id="addNameField" layoutX="45.0" layoutY="79.0" prefHeight="25.0" prefWidth="195.0" />
<Button fx:id="addNameButton" layoutX="265.0" layoutY="79.0" mnemonicParsing="false" onAction="#addNames" text="Add Name" />
<TextArea fx:id="namesAreaField" layoutX="39.0" layoutY="126.0" prefHeight="118.0" prefWidth="195.0" />
<Button fx:id="sortNamesButton" layoutX="262.0" layoutY="149.0" mnemonicParsing="false" onAction="#sortNames" text="Sort Names" />
<Button fx:id="shuffleNamesButton" layoutX="255.0" layoutY="196.0" mnemonicParsing="false" onAction="#shuffleNames" text="Shuffle Names" />
<TextField fx:id="searchNameField" layoutX="41.0" layoutY="267.0" prefHeight="25.0" prefWidth="188.0" />
<Button fx:id="searchNameButton" layoutX="254.0" layoutY="267.0" mnemonicParsing="false" onAction="#searchName" text="Search Name" />
</children>
</AnchorPane>

SearchGUI_FXMLController.java

import java.net.URL;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.ResourceBundle;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Button;
import javafx.scene.control.TextArea;
import javafx.scene.control.TextField;
import javax.swing.JOptionPane;

public class SearchGUI_FXMLController implements Initializable {
  
@FXML private TextField addNameField;
@FXML private TextField searchNameField;
@FXML private TextArea namesAreaField;
@FXML private Button addNameButton;
@FXML private Button sortNamesButton;
@FXML private Button shuffleNamesButton;
@FXML private Button searchNameButton;
private ArrayList<String> namesList = new ArrayList<>();
  
@FXML
public void addNames()
{
boolean found = false;
String name = addNameField.getText().trim();
if(name.equals(""))
JOptionPane.showMessageDialog(null, "Name string is mandatory!", "Field(s) Missing Alert", JOptionPane.ERROR_MESSAGE);
else {
for (String str : namesList)
{
if (str.equals(name))
{
found = true;
break;
}
else
{
found = false;
}
}
if (!found)
{
namesList.add(name);
HashSet<String> hs = new HashSet<>();
hs.addAll(namesList);
namesList.clear();
namesList.addAll(hs);
System.out.println(namesList);
namesAreaField.setText("");
for(String str : namesList)
{
namesAreaField.appendText(str + "\n");
}
}
else
{
JOptionPane.showMessageDialog(null, "Name already present!", "Duplicate Entry", JOptionPane.ERROR_MESSAGE);
}
}
}
  
@FXML
public void sortNames()
{
Collections.sort(namesList);
namesAreaField.setText("");
for(String str : namesList)
{
namesAreaField.appendText(str + "\n");
}
}
  
@FXML
public void shuffleNames()
{
Collections.shuffle(namesList);
namesAreaField.setText("");
for(String str : namesList)
{
namesAreaField.appendText(str + "\n");
}
}
  
@FXML
public void searchName()
{
String nameToSearch = searchNameField.getText().trim();
int index = 0;
if(nameToSearch.equals(""))
JOptionPane.showMessageDialog(null, "Name string is mandatory!", "Field(s) Missing Alert", JOptionPane.ERROR_MESSAGE);
else
{
index = Collections.binarySearch(namesList, nameToSearch);
if(index < 0)
JOptionPane.showMessageDialog(null, nameToSearch + " is not present in the list!", "Search Name: Failure", JOptionPane.ERROR_MESSAGE);
else
JOptionPane.showMessageDialog(null, nameToSearch + " was found at position: " + (index + 1), "Search Name: Success", JOptionPane.INFORMATION_MESSAGE);
}
}
  
@Override
public void initialize(URL url, ResourceBundle rb) {
  
}
}

SearchGUI.java (Main class)

import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;

public class SearchGUI extends Application {
  
@Override
public void start(Stage stage) throws Exception {
Parent root = FXMLLoader.load(getClass().getResource("SearchGUI_FXML.fxml"));
  
Scene scene = new Scene(root);
  
stage.setScene(scene);
stage.show();
}
  
public static void main(String[] args) {
launch(args);
}
}

Add a comment
Know the answer?
Add Answer to:
Need help creating a GUI using JavaFX. Also to Convert all console input/output to be used...
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
  • how would i use test.add because i would like to use add import java.io.File; import java.io.FileNotFoundException;...

    how would i use test.add because i would like to use add import java.io.File; import java.io.FileNotFoundException; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.Scanner; public class checkFruit { private List<String> tests; public List<String> getFruit(String fruits) { tests = new ArrayList<String>(Arrays.asList(fruits.split(","))); for (String test : tests) { System.out.println(test); tests.add()//how would i use add here } return tests; } public static void main(String[] args) { Scanner in = new Scanner(System.in); System.out.print("Enter file name: "); File file = new File(in.nextLine()); try { checkFruit...

  • I need help in converting this into pseudo-code Student.java public class Student implements Comparable<Student>{ private String...

    I need help in converting this into pseudo-code Student.java public class Student implements Comparable<Student>{ private String name, major, status; private int rank;    public Student() { this.name = this.major = this.status = ""; this.rank = 0; }    public Student(String name, String major, String status) { this.name = name; this.major = major; this.status = status; } public String getName() { return name; } public String getMajor() { return major; } public String getStatus() { return status; }    public int...

  • Look for some finshing touches java help with this program. I just two more things added...

    Look for some finshing touches java help with this program. I just two more things added to this code. A loop at the end that will ask the user if they want to quit if they do want to quit the program stops if they don't it loads a new number sequence. import java.util.Random; import java.util.ArrayList; import java.util.Scanner; import java.util.Arrays; import java.util.List; import java.util.Collections; public class main { public static void main(String[] args) { List < Sequence > list =...

  • JavaFX! Just need to fill several lanes of code please!!! CSE205 OOP and Data Structure Quiz #15 Last Name (print) First Name (print) Write a JavaFX GUI application program that simulates a timer. T...

    JavaFX! Just need to fill several lanes of code please!!! CSE205 OOP and Data Structure Quiz #15 Last Name (print) First Name (print) Write a JavaFX GUI application program that simulates a timer. The timer should show "count: the beginning and increase the number by 1 in every one second, and so on. o" at .3 A Timer - × A Timer Count: 0 Count: 1 (B) After 1 second, the GUI Window (A) Initial GUI Window According to the...

  • I'm getting a few errors still under RecipeBox. Would you be able to see what's wrong?...

    I'm getting a few errors still under RecipeBox. Would you be able to see what's wrong? Thanks ------------ package recipecollection; import java.util.ArrayList; public class SteppingStone5_RecipeTest { public static void main(String[] args) { ArrayList<String> recipeIngredients = new ArrayList<>(); recipeIngredients.add("Peanut butter"); recipeIngredients.add("Jelly"); recipeIngredients.add("Bread"); SteppingStone5_Recipe recipe1 = new SteppingStone5_Recipe("Peanut butter & jelly sandwich", 2, recipeIngredients, 300, 10.0); System.out.println("RECIPE 1"); recipe1.printRecipe(); System.out.println(); recipe1.setRecipeName("Turkey sandwich"); recipe1.setServings(5); recipe1.setTotalRecipeCalories(500); System.out.println(); System.out.println("RECIPE 1 (Modified)"); recipe1.printRecipe(); System.out.println(); System.out.println("RECIPE 2"); SteppingStone5_Recipe recipe2 = SteppingStone5_Recipe.createNewRecipe(); recipe2.printRecipe(); } } ///////////////// package recipecollection;...

  • A teacher wants to create a list of students in her class. Using the existing Student...

    A teacher wants to create a list of students in her class. Using the existing Student class in this exercise. Create a static ArrayList called classList that adds a student to the classList whenever a new Student is created. In the constructor, you will have to add that Student to the ArrayList. Coding below was given to edit and use public class ClassListTester { public static void main(String[] args) { //You don't need to change anything here, but feel free...

  • A teacher wants to create a list of students in her class. Using the existing Student...

    A teacher wants to create a list of students in her class. Using the existing Student class in this exercise. Create a static ArrayList called classList that adds a student to the classList whenever a new Student is created. In the constructor, you will have to add that Student to the ArrayList. Coding below was given to edit and use public class ClassListTester { public static void main(String[] args) { //You don't need to change anything here, but feel free...

  • Implement a Java program using simple console input & output and logical control structures such that...

    Implement a Java program using simple console input & output and logical control structures such that the program prompts the user to enter 5 integer scores between 0 to 100 as inputs and does the following tasks For each input score, the program determines whether the corresponding score maps to a pass or a fail. If the input score is greater than or equal to 60, then it should print “Pass”, otherwise, it should print “Fail”. After the 5 integer...

  • Can I get help with implementing a quick sort in my program? Starter Code: import java.util.Random;...

    Can I get help with implementing a quick sort in my program? Starter Code: import java.util.Random; import java.util.Scanner; import java.util.Arrays; import java.util.Collections; import java.util.ArrayList; public class RQS { public static int[] prepareData(int[] patients){ /* Data is prepared by inserting random values between 1 and 1000. Data items may be assumed to be unique. Please refer to lab spec for the problem definiton. */ // what is our range? int max = 1000; // create instance of Random class Random randomNum...

  • ******Java Programming Hi guys, I really need you help. I created a code for my java...

    ******Java Programming Hi guys, I really need you help. I created a code for my java course, but it keep giving me error messages. Majority of my code is fine but some keep display error on my console. I was hoping someone could pin points the problem. .There are three classes with the testCenter class being the main class. In the following is the assignment, and the bottom is my code. Please help! Assignment: Concepts: GUI User Design Graphics Deployment...

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