Related questions with answers
-
Search the Java Web site for information on how to use a JTextArea. Write an
application for the WebBuy Company that allows a user to compose the three
parts of a complete e-mail 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
e-mail message. When the message is complete and the Send button is clicked,
the application should display “Mail has been sent!” on a new line in the message
area. Save the file as JEMail.java.
-
Modify the JEMail application to include a Clear button that the user can
click at any time to clear the “To:”, “Subject:”, and “Message:” fields. Save the file
as JEMail2.java.
Search the Java Web site for information on how to use a JTextArea. Write an application for the WebBuy Company that allows a user to compose the three parts of a complete e-mail 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 e-mail message. When the message is complete and the Send button is clicked, the application should display “Mail has been sent!” on a new line in the message area. Save the file as JEMail.java.
Modify the JEMail application to include a Clear button that the user can click at any time to clear the “To:”, “Subject:”, and “Message:” fields. Save the file as JEMail2.java.
Solution
Verifiedimport javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
public class JEmail extends JFrame implements ActionListener, KeyListener {
final int WIDTH = 250;
final int HEIGHT = 400;
JTextArea to = new JTextArea("To: ");
JTextArea subject = new JTextArea("Subject: ");
JTextArea message = new JTextArea("Message: ");
//Add thc scroll bar to the Message
JScrollPane scroll = new JScrollPane(message);
JButton send = new JButton("Send");
Container con = getContentPane();
public JEmail() {
setSize(WIDTH, HEIGHT);
con.setLayout(new GridLayout(4,1));
con.add(to);
//Make sure the text does not
// go out of text area bounds
to.setLineWrap(true);
con.add(subject);
subject.setLineWrap(true);
con.add(scroll);
message.setLineWrap(true);
con.add(send);
to.addKeyListener(this);
subject.addKeyListener(this);
send.addActionListener(this);
}
Create an account to view solutions
Create an account to view solutions
More related questions
1/4
1/7