Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Answer this question about this statement in the constructor of the controller class (see below for java code): this.theView.addWindowListener(new MailingListWindowAdapter()); Where is this addWindowListener() method

Answer this question about this statement in the constructor of the controller class (see below for java code):

this.theView.addWindowListener(new MailingListWindowAdapter());

  • Where is this addWindowListener() method defined? Identify a specific class and how that class relates to the view class. Also briefly explain how you figured it out.

public class MailingListController { private MailingListView theView; private MailingListModel theModel;

public MailingListController(MailingListView theView, MailingListModel theModel) { this.theView = theView; this.theModel = theModel;

// register listeners this.theView.addWindowListener(new MailingListWindowAdapter()); this.theView.addAddListener(new MailingListListener()); this.theView.addRemoveListener(new MailingListListener()); }

// ADD #1. listener class for ActionEvent of add button of view class

// algorithm /* call View method to retrieve user input call Model method to add email if succeeded retrieve status msg from Model and display in View (result label) else retrieve status msg from Model and display in popup winodw in View end if

*/

// ADD #2. listener class for ActionEvent of remove button of view class

// algorithm /* call View method to retrieve user input call Model method to remove email if succeeded retrieve status msg from Model and display in View (result label) else retrieve status msg from Model and display in popup winodw in View end if

*/

// Handle window closing event. // WindowAdapter is an abstract class which implements WindowListener interface class MailingListWindowAdapter extends WindowAdapter { public void windowClosing(WindowEvent e) // specified in WindowListener interface { theModel.closeDown(); // this method will ask model to save updated mailing list System.exit(0); // now exit this application } // end windowClosing } // end class MailingListWindowAdapter

} // end class MailingListController

MailingListView:

import javax.swing.*; // GUI components JXXX import java.awt.*; // layout managers; Color, Font import java.awt.event.ActionListener;

@SuppressWarnings("serial") public class MailingListView extends JFrame { // GUI part private JTextField emailField; // user input of email address private JButton addButton; // Add private JButton removeButton; // Remove private JLabel resultLabel; // for output: result

//*****************************************

public MailingListView() { setTitle("Welcome to Fantastic Group"); setLocationRelativeTo(null); setDefaultCloseOperation(EXIT_ON_CLOSE); createContents(); pack(); // automatically set window size based on components added }

private void createContents() { // JPanel version setLayout(new GridLayout(0, 1, 0, 5)); // single column, 5 pixel vertical gap (between rows)

// title section: just one label JPanel titlePanel = new JPanel(new FlowLayout(FlowLayout.CENTER)); JLabel titleLabel = new JLabel("Join Our Mailing List"); titleLabel.setFont(new Font("Tahoma", Font.BOLD, 20)); // http://docs.oracle.com/javase/tutorial/uiswing/components/html.html titleLabel.setForeground(Color.BLUE); titlePanel.add(titleLabel);

// section with textfield, and buttons JPanel contentPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));

emailField = new JTextField(20); emailField.setText("enter your email address");

addButton = new JButton("Add"); removeButton = new JButton("Remove");

contentPanel.add(emailField); contentPanel.add(addButton); contentPanel.add(removeButton);

// result section JPanel resultPanel = new JPanel(); resultLabel = new JLabel(); resultPanel.add(resultLabel);

add(titlePanel); add(contentPanel); add(resultPanel); } // end createContens

// getxxx/setxxx public String getEmail() { return "emailField"; }

public void setEmail(String email) { this.emailField = mail; }

public void setResult(String result) { this.resultLabel = result; }

// open a popup that contains the error msg passed void displayErrorMessage(String errorMessage) { OptionPane.showMessageDialog(this, errorMessage, errorMessage, JOptionPane.ERROR_MESSAGE); }

// If the addButton is clicked execute an event handling method in // the controller named actionPerformed void addAddListener(ActionListener listenForAddButton) { String command = ((AbstractButton) listenForAddButton).getActionCommand(); if (command.equals("Add")) { statusLabel.setText("Add succeeded"); } }

// If the removeButton is clicked execute an event handling method in // the controller named actionPerformed void addRemoveListener(ActionListener listenForRemoveButton) { String command = ((AbstractButton) listenForRemoveButton).getActionCommand(); if (command.equals("Remove")) { statusLabel.setText("Remove succeeded."); } }

} // end class MailingListView

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

Icdt 88 2nd International Conference On Database Theory Bruges Belgium August 31 September 2 1988 Proceedings Lncs 326

Authors: Marc Gyssens ,Jan Paredaens ,Dirk Van Gucht

1st Edition

3540501711, 978-3540501718

More Books

Students also viewed these Databases questions

Question

(a) Determine an appropriate coding for this experiment.

Answered: 1 week ago

Question

6. Identify seven types of hidden histories.

Answered: 1 week ago

Question

What is human nature?

Answered: 1 week ago