Using JavaFX: Write a GUI application for the WebBuy Company that allows a user
ID: 3874494 • Letter: U
Question
Using JavaFX:
Write a GUI application for the WebBuy Company that allows a user to compose the three parts of a complete email message: the “To:”, “Subject:” and “Message:” text. The “To:”, and “Subject:” Text areas should provide a single line for data entry. The “Message:” area should allow multiple lines of input and be able to scroll if necessary to accommodate a long message. The user clicks a button to send the email message.
When the application starts, the text area will display a message listing the options which can be selected. As the user selects and deselects options, the proper additions to that message will be made. Provide a simple error checking to prevent sending and empty message mail. Compile, run, and check the results.
Explanation / Answer
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class JEMail extends JFrame implements ActionListener
{
private JLabel toLabel = new JLabel("To:");
private JTextField toField = new JTextField(24);
private JLabel subjectLabel = new JLabel("Subject:");
private JTextField subjectField = new JTextField(24);
private JLabel messageLabel = new JLabel("Message");
private JButton sendButton = new JButton("Send");
private JTextArea message = new JTextArea(4, 22);
public JEMail()
{
super("WebBuy Company E-Mail");
setSize(370, 270);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Container pane = getContentPane();
FlowLayout flow = new FlowLayout(FlowLayout.RIGHT);
pane.setLayout(flow);
JPanel panel1 = new JPanel();
panel1.add(toLabel);
pane.add(toField);
pane.add(panel1);
JPanel panel2 = new JPanel();
panel2.add(subjectLabel);
panel2.add(subjectField);
pane.add(panel2);
JPanel panel3 = new JPanel();
panel3.add(messageLabel);
message.setLineWrap(true);
message.setWrapStyleWord(true);
JScrollPane scroll = new JScrollPane(message,
JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
panel3.add(scroll);
pane.add(panel3);
JPanel panel4 = new JPanel();
panel4.add(sendButton);
pane.add(panel4);
sendButton.addActionListener(this);
setContentPane(pane);
}
public static void main(String[] arguments)
{
JEMail email = new JEMail();
email.setVisible(true);
}
public void actionPerformed(ActionEvent event)
{
Object source = event.getSource();
if (source == sendButton)
message.append(" Mail has been sent!");
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.