Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Part 1 Modify your Java application so that it is an easy-to-use GUI application

ID: 3920730 • Letter: P

Question

Part 1 Modify your Java application so that it is an easy-to-use GUI application where all of the interaction is performed on one screen. You will now take the individual components and translate them to a single interactive GUI interface using the following GUI components, container, the event listeners, and event subclasses to enhance your application as a more GUI-appropriate interface: GUI components Container Event listeners Event subclasses (at least 3–4 utilized) ActionEvent ItemEvent FocusEvent KeyEvent MouseEvent WindowEvent ActionPerformed Method Part 2 For this assignment, you are being asked to make sure you are exception handling by verifying that all of the customer-entered information is valid before the order is submitted to ensure order accuracy. The customer information that the customer must now enter that should be validated includes the following: Entered user name (must fill in a name) Entered at least one sub to order Selected all three attributes for sub (such as bread type, sub type, and sub size) Entered delivery address that includes street, city, state, and zip code Entered telephone number xxx-xxx-xxxx In this assignment, you are adding in error handling to make sure the customer is filling in all of the required information. To accomplish this task, you will be utilizing the following Java classes: Methods in the character class and StringBuilder class to validate and manipulate characters in a string Try… Catch for the exception handling of all input fields Deliverable The following are the Unit 4 Individual Project deliverables: Update the title page for the Design Document with the project name (Unit 4 IP) and the date. Add the following section header: Phase 4 Revised Application Screenshots. Add screenshots of each distinct screen from your running application. Name the document yourname_ITSD424_IP4.doc. Submit the design document and the zipped Java project files for grading.

Explanation / Answer

Java Swings

Program in Java Swing:

import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JButton;
import java.awt.Color;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JTextField;
import javax.swing.JLabel;
import javax.swing.JTextArea;
import javax.swing.JRadioButton;
import javax.swing.JToggleButton;
import javax.swing.JScrollBar;
import javax.swing.JComboBox;
import javax.swing.JCheckBox;
public class CustomerDetails {

   private JFrame frame;
   private JTextField textField;
   private JTextField textfield1;
   private JTextField textfield2;
   //Launch application.
   public static void main(String[] args) {
       EventQueue.invokeLater(new Runnable() {
           public void run() {
               try {
                   CustomerDetails window = new CustomerDetails();
                   window.frame.setVisible(true);
                    }
                                catch (Exception e) {
                   e.printStackTrace();
                                }
           }
       });
   }
   //Create the application.
   public CustomerDetails() {
       initialize();
   }
   //Initialize the components of the frame.
   private void initialize() {
       frame = new JFrame();
       frame.setBounds(100, 100, 730, 489);
       frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
       frame.getContentPane().setLayout(null);
  
       textField = new JTextField();
       textField.setBounds(128, 28, 86, 20);
       frame.getContentPane().add(textField);
       textField.setColumns(10);
      
       JLabel lname = new JLabel("Name");
       lname.setBounds(65, 31, 46, 14);
       frame.getContentPane().add(lname);
      
       JLabel lphone = new JLabel("Phone");
       lphone.setBounds(65, 68, 46, 14);
       frame.getContentPane().add(lphone);
      
       textfield1 = new JTextField();
       textfield1.setBounds(128, 65, 86, 20);
       frame.getContentPane().add(textfield1);
       textfield1.setColumns(10);
      
       JLabel lemail = new JLabel("Email Id");
       lemail.setBounds(65, 115, 46, 14);
       frame.getContentPane().add(lemail);
      
       textfield2 = new JTextField();
       textfield2.setBounds(128, 112, 247, 17);
       frame.getContentPane().add(textfield2);
       textfield2.setColumns(10);
      
       JLabel laddress = new JLabel("Address");
       laddress.setBounds(65, 162, 46, 14);
       frame.getContentPane().add(laddress);
              
       JTextArea textarea1 = new JTextArea();
       textarea1.setBounds(126, 157, 212, 40);
       frame.getContentPane().add(textarea1);
      
       JButton bclear = new JButton("Clear");
      
       bclear.setBounds(312, 387, 89, 23);
       frame.getContentPane().add(bclear);
      
       JLabel lgender = new JLabel("Gender");
       lgender.setBounds(65, 228, 46, 14);
       frame.getContentPane().add(lgender);
      
       JLabel lmale = new JLabel("Male");
       lmale.setBounds(128, 228, 46, 14);
       frame.getContentPane().add(lmale);
      
       JLabel lfemale = new JLabel("Female");
       lfemale.setBounds(292, 228, 46, 14);
       frame.getContentPane().add(lfemale);
      
       JRadioButton radioButton = new JRadioButton("");
       radioButton.setBounds(337, 224, 109, 23);
       frame.getContentPane().add(radioButton);
      
       JRadioButton radioButton1 = new JRadioButton("");
       radioButton1.setBounds(162, 224, 109, 23);
       frame.getContentPane().add(radioButton1);
      
       JLabel Bread = new JLabel("Bread");
       Bread.setBounds(65, 288, 67, 14);
       frame.getContentPane().add(Bread);
      
       JComboBox<String> comboBox = new JComboBox<String>();
       comboBox.addItem("Select");
       comboBox.addItem("Brown");
       comboBox.addItem("Wheat");
       comboBox.addItem("Multi-grain");
       comboBox.addItem("Fruit");
       comboBox.addItem("White bread");
       comboBox.addActionListener(new ActionListener() {
           public void actionPerformed(ActionEvent arg0) {
           }
       });
       comboBox.setBounds(180, 285, 91, 20);
       frame.getContentPane().add(comboBox);
      
      
       JButton bsubmit = new JButton("submit");
      
       bsubmit.setBackground(Color.BLUE);
       bsubmit.setForeground(Color.MAGENTA);
       bsubmit.setBounds(65, 387, 89, 23);
       frame.getContentPane().add(bsubmit);
      
      
       bsubmit.addActionListener(new ActionListener() {
           public void actionPerformed(ActionEvent arg0) {
               if(textField.getText().isEmpty()||(textfield1.getText().isEmpty())||(textfield2.getText().isEmpty())||(textarea1.getText().isEmpty())||((radioButton1.isSelected())&&(radioButton.isSelected()))||(comboBox.getSelectedItem().equals("Select")))
                   JOptionPane.showMessageDialog(null, "Missing Data");
               else      
               JOptionPane.showMessageDialog(null, "Data Submitted");
           }
       });
      
       bclear.addActionListener(new ActionListener() {
           public void actionPerformed(ActionEvent e) {
               textfield1.setText(null);
               textfield2.setText(null);
               textField.setText(null);
               textarea1.setText(null);
               radioButton.setSelected(false);
               radioButton1.setSelected(false);
               comboBox.setSelectedItem("Select");
              
              
           }
       });
   }
}