Question
You are asked to write a JavaFX program that works as below. When the program starts, the user sees an empty text area (at the
You are asked to write a JavaFX program that works as below. When the program starts, the user sees an empty text area (at the top part of the GUI), an empty text field in the middle, and a button with the label Create Word at the bottom.
The idea is that the user will create a document in the text area. Rather than typing every letter of every word, the GUI allows the user to create buttons for words or even longer pieces of text. This idea is explained below. Suppose the user expects to use the word is quite a bit. He/she can then type is in the text field and click the Create Word button. This will create a button with the label is just below the text area and just above the text field.
When the user clicks the is button, the word is is appended to the text already present in the text area. That way, the user ends up typing less. The user can create buttons for longer pieces of text, if he/she so chooses.
The user can create up to 20 buttons for words (or arbitrary sequences of text). The buttons should be arranged in a grid. Put up to four buttons in every row. The buttons should be filled from left to right and then top to bottom. The buttons should be created only if needed. Do not create 20 buttons right at the beginning and store them somewhere.
This is not a huge program. My code for it is 48 lines long, not counting comments and blank lines and Java annotations such as @Override. You need just a single class. You could construct the program using a small number of classes and classes/interfaces.
I used the following: Application, EventHandler, Button, TextArea, TextField, GridPane, VBox, Stage and, of course, Exception and String. I dont think I 1 missed any, but, in any case, treat this list as a helpful suggestion, neither a mandate nor a complete prescription.
Select pictures to see example of assignment
file:///J:/Pictures.pdf
NEED HELP PLEASE!
My CODE SO FAR
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import javax.swing.JTextField;
public class CreateWordGUI extends JFrame {
private JPanel panel1; // create JPanel
private JButton button1; // create Jbutton
private JLabel label1; // create label
private JTextField textField1; // create JTextField
private JTextArea areaField1; // create JTextArea
// create an application that have all the following GUI
public CreateWordGUI() {
setLayout(new FlowLayout());
setTitle("Assignment 2");
areaField1 = new JTextArea(10, 60);
textField1 = new JTextField(60);
button1 = new JButton("CreateWord");
panel1 = new JPanel();
label1 = new JLabel("");
setVisible(true);
setSize(700, 300);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
panel1.add(areaField1);
add(panel1);
add(textField1);
add(button1);
add(label1);
// create event to addctionListener
event e = new event();
button1.addActionListener(e);
}
// create Actionlistener to Jbutton
public class event implements ActionListener {
public void actionPerformed(ActionEvent e) {
// create a text below when word are enter in the areaField
String text = textField1.getText();
if (text == null ? "" == null : text.equals("")) {
label1.setText("");
} else {
label1.setText(text);
}
}
}
// create Main
public static void main(String[] args) {
CreateWordGUI createWord = new CreateWordGUI();
}
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started