Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

How can I add the load function to this code as well as when I save these files of persons how can I make it

How can I add the load function to this code as well as when I save these files of persons how can I make it so I can view the entries of persons I saved as well as when I press the new button while I was creating a person how do I have it say save before when I try to create a new person and haven't saved that yet? So implement this in simpler terms Select "New." You should get the "Save first?" pop up .Say no ,then load the file you just made. View current list of entries import javax.swing. * ; import java.awt. * ; import java.awt.event. * ; import java.io . File; public class GuiDemo extends JFrame { private JMenuBar menuBar; private JMenu fileMenu; private JMenuItem newMenuItem, saveMenuItem, saveAsMenuItem, exitMenuItem; private JPanel mainPanel; private JButton personButton, registeredPersonButton, occcPersonButton; private JLabel nameLabel, idLabel; private JTextField nameField, idField; private JDialog saveDialog; private JButton saveButton, cancelButton; public GuiDemo (){ super (" GUI Demo" ) ; setSize (400,300) ; setDefaultCloseOperation ( JFrame . DO _ NOTHING _ ON _ CLOSE ) ; menuBar =new JMenuBar () ; fileMenu =new JMenu (" File ") ; menuBar.add ( fileMenu ) ; newMenuItem =new JMenuItem (" New ") ; saveMenuItem =new JMenuItem (" Save ") ; saveAsMenuItem =new JMenuItem (" Save As ...") ; exitMenuItem =new JMenuItem (" Exit ") ; fileMenu.add ( newMenuItem ) ; fileMenu.add ( saveMenuItem ) ; fileMenu.add ( saveAsMenuItem ) ; fileMenu.addSeparator () ; fileMenu.add ( exitMenuItem ) ; saveMenuItem.setEnabled ( false ) ; saveAsMenuItem.setEnabled ( false ) ; setJMenuBar ( menuBar ) ; mainPanel =new JPanel () ; mainPanel.setLayout ( new GridLayout (3,2,10,10)) ; personButton =new JButton (" Person ") ; registeredPersonButton =new JButton (" Registered Person" ) ; occcPersonButton =new JButton (" OCCC Person" ) ; nameLabel =new JLabel (" Name: ") ; idLabel =new JLabel (" ID: ") ; nameField =new JTextField () ; idField =new JTextField () ; mainPanel.add ( personButton ) ; mainPanel.add ( registeredPersonButton ) ; mainPanel.add ( occcPersonButton ) ; mainPanel.add ( nameLabel ) ; mainPanel.add ( nameField ) ; mainPanel.add ( idLabel ) ; mainPanel.add ( idField ) ; nameField.setEnabled ( false ) ; idField.setEnabled ( false ) ; add ( mainPanel ) ; saveDialog =new JDialog ( this ,"Save", true ) ; saveDialog.setLayout ( new FlowLayout ()) ; //Create the buttons and add them to the save dialog saveButton =new JButton (" Save ") ; cancelButton =new JButton (" Cancel ") ; saveDialog.add ( saveButton ) ; saveDialog.add ( cancelButton ) ; //Set the size and location of the save dialog saveDialog.setSize (200,100) ; saveDialog.setLocationRelativeTo ( this ) ; //Add action listeners to the buttons and menu items personButton.addActionListener ( new PersonButtonListener ()) ; registeredPersonButton.addActionListener ( new RegisteredPersonButtonListener ()) ; occcPersonButton.addActionListener ( new OcccPersonButtonListener ()) ; newMenuItem.addActionListener ( new NewMenuItemListener ()) ; saveMenuItem.addActionListener ( new SaveMenuItemListener ()) ; saveAsMenuItem.addActionListener ( new SaveAsMenuItemListener ()) ; exitMenuItem.addActionListener ( new ExitMenuItemListener ()) ; saveButton.addActionListener ( new SaveButtonListener ()) ; cancelButton.addActionListener ( new CancelButtonListener ()) ; //Add a window listener to the frame addWindowListener ( new WindowCloseListener ()) ; }//Define a private inner class that implements ActionListener for the person button private class PersonButtonListener implements ActionListener { public void actionPerformed ( ActionEvent e ){//Enable the name field and disable the id field nameField.setEnabled ( true ) ; idField.setEnabled ( false ) ; nameField.setText ("") ; idField.setText ("") ; // Enable the save and save as menu items Screenshot of remaining code is belowsaveMenuItem. setEnabled (true);
saveAsMenuItem. setEnabled (true); }}
private class OcccPersonButtonListener implements ActionListener {
public void actionPerformed (ActionEvent e
nameField.setEnabled (true);
idField.setEnabled (true);
nameField.setText ("Mary Doe");
idField.setText ("123456789");
saveMenuItem. setEnabled (false);
saveAsMenuItem. setEnabled (false); }}
private class NewMenuItemListener implements ActionListener {
public void actionPerformed (ActionEvent e
nameField.setEnabled (false);
idField.setEnabled (false); nameField.setText ("") ;
idField. setText ("");
saveMenuItem. setEnabled (false);
saveAsMenuItem. setEnabled (false) ; }}
private class SaveMenuItemListener implements ActionListener {
public void actionPerformed (Act
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Learning MySQL Get A Handle On Your Data

Authors: Seyed M M Tahaghoghi

1st Edition

0596529465, 9780596529468

More Books

Students also viewed these Databases questions

Question

=+d) Are all of these rolls within the specification limits?

Answered: 1 week ago

Question

4. Explain how to use fair disciplinary practices.

Answered: 1 week ago

Question

3. Give examples of four fair disciplinary practices.

Answered: 1 week ago