Whats wrong with the Java code below? Thank you! Source code: package FlowLayout; public class FlowLayout extends FlowLayout2 {         public static void main(String[] args) // This is int main()     {         FlowLayout2 frame = new FlowLayout2();          frame.setSize(300, 200);         frame.setVisible(true);     } } ====================================================================================== ====================================================================================== package FlowLayout; // Import needed packages import java.awt.event.ActionListener; import javax.swing.JComboBox; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JTextField; public class FlowLayout2 extends JFrame implements ActionListener {     // Declare protected class members     protected JFrame frame;     protected JPanel panel;     protected JTextField textBox;     protected JComboBox comboBox;          public FlowLayout2() // Class Constructor     {         // Create a JFrame to hold the components         frame = new JFrame("Dropdown App");         frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);                  // Create a panel to hold the components         panel = new JPanel();              // Create a text box         textBox = new JTextField(13);                  // Create a ComboBox         String[] options = {"Date & Time", "Save", "Change Color", "Logout"};         comboBox = new JComboBox<>(options);         comboBox.addActionListener(this);         comboBox.setEditable(true);                       // Add the ComboBox to the panel         panel.add(comboBox);                  // Add the Text Field         panel.add(textBox);         // Set the layout manager for the panel         panel.setLayout(new java.awt.FlowLayout());         // Add the panel to the frame         frame.getContentPane().add(panel);     } }   ========================================================================================== ========================================================================================== package FlowLayout; // Import needed packages import java.awt.Color; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.FileWriter; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; import javax.swing.JFrame; import javax.swing.JOptionPane; public class FlowLayout3 extends FlowLayout2 implements ActionListener {     public void actionPerformed(ActionEvent eventOccurred) // method for listening for actions     {         if(eventOccurred.getSource() == "Date & Time") // If date_time is heard, display date and time         {             DateTimeFormatter dateTimeFormat = DateTimeFormatter.ofPattern("MM/dd/YYYY hh:mm:ss");                          LocalDateTime current=LocalDateTime.now();             textBox.setText(dateTimeFormat.format(current));         }         if(eventOccurred.getSource()== "Save") // If write_to_file is heard, write          {                                              // whatever is displayed to a .txt file                String save = textBox.getText();             try // Try block for exceptions             {                 FileWriter saving = new FileWriter("Log.txt");                 saving.write(save);                 saving.close();                                  // So that the User is aware that the data was saved to a file                 JOptionPane.showMessageDialog(this, "Everything displayed has been saved in a file named \'Log.txt\'.");             }             catch(Exception menuException) // Catch block for the exceptions thrown             {                 textBox.setText("Exception is " + menuException);             }         }         if(eventOccurred.getSource() == "Change Color") // If change_color is selected,         {                                              // Make the background green.               frame.getContentPane().setBackground(Color.GREEN);         }         if(eventOccurred.getSource() == "Logout") // If exit_application is selected         {                                                  // logout of the application             frame.setVisible(false);             JOptionPane.showMessageDialog(this, "See ya, have a great day!");         }         frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // Make sure the application closes     } }

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Whats wrong with the Java code below?

Thank you!

Source code:

package FlowLayout;


public class FlowLayout extends FlowLayout2
{    
    public static void main(String[] args) // This is int main()
    {
        FlowLayout2 frame = new FlowLayout2(); 
        frame.setSize(300, 200);
        frame.setVisible(true);
    }
}


======================================================================================
======================================================================================


package FlowLayout;

// Import needed packages
import java.awt.event.ActionListener;

import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextField;

public class FlowLayout2 extends JFrame implements ActionListener
{
    // Declare protected class members
    protected JFrame frame;
    protected JPanel panel;
    protected JTextField textBox;
    protected JComboBox<String> comboBox;
    
    public FlowLayout2() // Class Constructor
    {
        // Create a JFrame to hold the components
        frame = new JFrame("Dropdown App");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        
        // Create a panel to hold the components
        panel = new JPanel();
    
        // Create a text box
        textBox = new JTextField(13);
        
        // Create a ComboBox
        String[] options = {"Date & Time", "Save", "Change Color", "Logout"};
        comboBox = new JComboBox<>(options);
        comboBox.addActionListener(this);
        comboBox.setEditable(true);
        
    
        // Add the ComboBox to the panel
        panel.add(comboBox);
        
        // Add the Text Field
        panel.add(textBox);

        // Set the layout manager for the panel
        panel.setLayout(new java.awt.FlowLayout());

        // Add the panel to the frame
        frame.getContentPane().add(panel);
    }
}

 

==========================================================================================
==========================================================================================


package FlowLayout;


// Import needed packages
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.FileWriter;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

import javax.swing.JFrame;
import javax.swing.JOptionPane;

public class FlowLayout3 extends FlowLayout2 implements ActionListener
{
    public void actionPerformed(ActionEvent eventOccurred) // method for listening for actions
    {
        if(eventOccurred.getSource() == "Date & Time") // If date_time is heard, display date and time
        {
            DateTimeFormatter dateTimeFormat = DateTimeFormatter.ofPattern("MM/dd/YYYY hh:mm:ss");
            
            LocalDateTime current=LocalDateTime.now();
            textBox.setText(dateTimeFormat.format(current));
        }

        if(eventOccurred.getSource()== "Save") // If write_to_file is heard, write 
        {                                              // whatever is displayed to a .txt file   
            String save = textBox.getText();
            try // Try block for exceptions
            {
                FileWriter saving = new FileWriter("Log.txt");
                saving.write(save);
                saving.close();
                
                // So that the User is aware that the data was saved to a file
                JOptionPane.showMessageDialog(this, "Everything displayed has been saved in a file named \'Log.txt\'.");
            }
            catch(Exception menuException) // Catch block for the exceptions thrown
            {
                textBox.setText("Exception is " + menuException);
            }
        }

        if(eventOccurred.getSource() == "Change Color") // If change_color is selected,
        {                                              // Make the background green.  
            frame.getContentPane().setBackground(Color.GREEN);
        }

        if(eventOccurred.getSource() == "Logout") // If exit_application is selected
        {                                                  // logout of the application
            frame.setVisible(false);
            JOptionPane.showMessageDialog(this, "See ya, have a great day!");
        }
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // Make sure the application closes
    }
}

Expert Solution
steps

Step by step

Solved in 3 steps

Blurred answer
Knowledge Booster
Array
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education