Develop a program that implements a prototype user interface

Develop a program that implements a prototype user interface for composing an email message. The application should have text fields for the To, CC, and Bcc address lists and subject line, and one for the message body. Include a button labeled Send. When the Send button is pushed, the program should print the contents of all fields to standard output using print statements.

Solution

import java.awt.*;
import javax.swing.*;
import java.awt.event.*;

public class Email extends JFrame{
  
    //Declaring all elements: labels, text fields, text panes and button
    private JLabel To, Cc, Bcc, Subject;
    private JTextField receiver, C_c, B_c_c, subject;
    private JTextArea textArea;
    private JButton Send;
  
        //constructor
        public Email(){               
        //initialising UI elements declared above
            Send = new JButton(\"Send\");
            To = new JLabel(\"To\");
            receiver = new JTextField(60);
            Cc = new JLabel(\"Cc\");
            C_c= new JTextField(60);
            Bcc = new JLabel(\"Bcc\");
            B_c_c= new JTextField(60);
            Subject = new JLabel(\"Subject\");
            subject = new JTextField(50);
            textArea = new JTextArea();
        }
      
        //adding UI elements to JPanel
        private JPanel createComponentsWithLabel(String label, Component c){
            JPanel JP = new JPanel();
            JP.setLayout(new BorderLayout());
            JP.add(new JLabel(label, JLabel.TOP));
            JP.add(c,BorderLayout.CENTER);
            JP.add(To);
            JP.add(receiver);
            JP.add(Cc);
            JP.add(C_c);
            JP.add(Bcc);
            JP.add(B_c_c);
            JP.add(subject);
            JP.add(textArea);
            JP.add(Send);        
            //Adding action listener to the button
            Send.addActionListener(new CustomActionListener());
            return JP;
    }
       //Action to be performed when Send button is clicked
       class CustomActionListener implements ActionListener{
             public void actionPerformed(ActionEvent e) {
                System.out.println(\"To: \" +receiver.getText());
                System.out.println(\"Cc: \" +C_c.getText());
                System.out.println(\"Bcc: \" +B_c_c.getText());
                System.out.println(\"Subject: \" +subject.getText());
                System.out.println(\"Content: \" +textArea.getText());   }
        }
    
        public static void main(String args[]){
            JFrame JF= new JFrame(\"Compose Message\");
            JF.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            JF.setSize(400,400);
            JF.setVisible(true);
            Email email = new Email();
            JPanel panel = new Email().createComponentsWithLabel(\"Compose Message\",email);
             JF.add(panel);
            JF.setSize(400,400);
        }
              
}    

 Develop a program that implements a prototype user interface for composing an email message. The application should have text fields for the To, CC, and Bcc ad
 Develop a program that implements a prototype user interface for composing an email message. The application should have text fields for the To, CC, and Bcc ad

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site