JAP Hybrid 6

Choose a study mode

Play Quiz
Study Flashcards
Spaced Repetition
Chat to Lesson

Podcast

Play an AI-generated podcast conversation about this lesson
Download our mobile app to listen on the go
Get App

Questions and Answers

In the MVC pattern, what is the primary responsibility of the 'Controller'?

  • Storing and managing application data.
  • Defining the visual representation of the data.
  • Handling user input and directing the view to change displayed items. (correct)
  • Managing the application's configuration settings.

In the context of Java Swing, what role does the DefaultButtonModel object play within a JButton?

  • It is responsible for the visual representation of the button.
  • It handles the event listeners for button clicks.
  • It stores the state of the button, such as whether it's pressed or released. (correct)
  • It manages the layout of the button within its container.

What is the main purpose of the event-dispatching queue in Swing's MVC architecture?

  • To handle the posting of GUI events and ensure thread safety during component updates. (correct)
  • To manage database connections.
  • To manage network communications.
  • To perform complex calculations for data models.

What problem does the Observer pattern solve in the context of MVC?

<p>Automatically updating multiple views when the model's data changes. (A)</p> Signup and view all the answers

Which of the following is a key characteristic of the Observable class in Java's implementation of the Observer pattern?

<p>It requires inheritors to explicitly set a 'changed' flag before notifying observers. (B)</p> Signup and view all the answers

In the Observer pattern, what is the role of the update() method?

<p>To push changes from the observable to the observer. (D)</p> Signup and view all the answers

What is the purpose of a splash screen in a GUI application?

<p>To indicate that the application is launching, advertise the product, or provide basic information. (A)</p> Signup and view all the answers

What is the primary function of a JProgressBar component in Java Swing?

<p>To indicate the progress of a task or operation. (A)</p> Signup and view all the answers

What does it mean when a progress bar is in 'indeterminate mode'?

<p>The progress bar displays an animation to indicate that work is occurring, but the completion time is unpredictable. (D)</p> Signup and view all the answers

What is the role of ProgressMonitorInputStream?

<p>To monitor the amount of data read from an input stream and display a progress monitor dialog automatically. (B)</p> Signup and view all the answers

What is a key limitation of using ProgressMonitor in Java Swing?

<p>It cannot be reused once it has completed its task. (A)</p> Signup and view all the answers

In UML, which of the following is considered a 'structural thing'?

<p>Collaboration (A)</p> Signup and view all the answers

What does a 'Class' represent in UML?

<p>A set of identical objects defining functionality and properties. (B)</p> Signup and view all the answers

In UML, what is the purpose of an 'interface'?

<p>To specify a set of operations that classes can implement. (B)</p> Signup and view all the answers

What does an 'activity diagram' portray in UML?

<p>The behavioral aspects of a system, representing the flow of activities. (A)</p> Signup and view all the answers

In UML, what is the purpose of an 'interaction diagram'?

<p>To envision the flow of messages between components in a system. (C)</p> Signup and view all the answers

In UML, what does the 'Dependency' relationship signify?

<p>A relationship where a change in one element affects another element. (A)</p> Signup and view all the answers

In UML, what is the key characteristic of a 'Generalization' relationship?

<p>It represents an 'is-a' relationship between a parent and child class, also known as inheritance. (C)</p> Signup and view all the answers

What is the purpose of the 'Realization' relationship in UML?

<p>To describe how an interface is implemented by a class. (C)</p> Signup and view all the answers

Which of the following is NOT a type of UML diagram?

<p>Story Board Diagram (B)</p> Signup and view all the answers

Flashcards

MVC Architecture

A design pattern that separates data (model), UI (view), and input control (controller).

UI Delegate

An object that combines a view and a controller to simplify the MVC paradigm.

Observable Class

A class that keeps track of objects to be informed when a change happens.

Observer Interface

An interface class that has a single member function named update().

Signup and view all the flashcards

JProgressBar

A GUI element indicating the progress of a program activity.

Signup and view all the flashcards

Progress Monitor

A dialog box that contains a progress bar and additional information.

Signup and view all the flashcards

ProgressMonitorInputStream

Displays a progress monitor dialog automatically while an input stream is read.

Signup and view all the flashcards

Splash Screen

A window displayed briefly to show the application is loading.

Signup and view all the flashcards

UML 'Things'

A real-world concept in UML represented by structural, behavioral, grouping, and annotational types.

Signup and view all the flashcards

UML Relationships

Illustrates meaningful connections, defining application functionality.

Signup and view all the flashcards

UML Diagrams

Graphical implementations of UML models using symbols and text.

Signup and view all the flashcards

Structural Diagram

A type of UML diagram that represents the static view by portraying structure.

Signup and view all the flashcards

Behavioral Diagram

A type of UML diagram that depicts behavioral features, dealing with dynamic parts.

Signup and view all the flashcards

Interaction Diagram

A UML diagram that depicts interactions between objects and data flow.

Signup and view all the flashcards

UML Dependency

A kind of relationship where a change in target affects the source.

Signup and view all the flashcards

UML Association

Links associating entities in the UML model.

Signup and view all the flashcards

UML Generalization

Relationship between a general thing and a specific kind.

Signup and view all the flashcards

UML Realization

A semantic relationship where one defines behavior, the other implements it.

Signup and view all the flashcards

Event-Dispatching Queue

The queue that handles the posting of GUI events, including repainting.

Signup and view all the flashcards

Observer Pattern

A design pattern where modifying one object instantly updates all dependent objects.

Signup and view all the flashcards

Study Notes

MVC Examples

  • Examples provide a better understanding of the MVC model

Some Examples

  • A view displays a set of data in a Swing JList component
  • A scrollbar is added as a controller, directing the view to change displayed items
  • Another controller, such as a Swing JTextField, takes user input and requests the model to add a new value
  • The model notifies the view of the change, and the view requests the updated data set
  • A scenario includes 2 controllers: one for mouse interaction with a scrollbar and the other to accept user input to add to the model
  • An application can have any number of controllers and views.
  • Consider an application presenting database information in a table and pie chart
  • The table can be scrolled using horizontal and vertical scroll bars
  • New data can be entered via text fields
  • An example has a model, two views, and three controllers
  • Scrollbar controllers update the table view
  • The text field controller updates the model
  • UML sequence diagrams display the interaction among Model, View, and Controller objects

Delegation – View and Controller

  • Separation between scrollbars and the table they control may be a concern
  • Separating the GUI among multiple elements is required
  • Variables and events enable communication between the controller GUI and the view GUI
  • Swing JTextField acts as both a view (displaying data) and a controller (changing data)
  • Many components support user interaction like scrolling
  • Interaction between multiple controllers and views can be complex
  • The MVC paradigm is simplified by combining views and controllers
  • Swing designers call a combined view/controller a UI delegate

Delegates

  • In a delegate, the view and controller communicates as needed
  • Separating view and controller communication is ideal, but not always possible
  • Separating Model and Delegate is more beneficial
  • The delegate communicates with the model like a separate view and controller
  • Separation between the model and user interaction is key
  • Model-View-Controller design is still applied when combining views and controllers into the delegate, but simplified
  • Each Java Swing component contains a model and a UI delegate.
  • The model maintains information about the component's state
  • The UI delegate is responsible for drawing the component on the screen
  • The UI delegate reacts to events using AWT
  • Separating the model and UI delegate in the MVC design is advantageous
  • Multiple views can be tied to a single model
  • Data can change in one place, and all views update accordingly
  • Separating the delegate from the model allows users to change what a component looks like without affecting its data
  • Swing can provide each component with its own pluggable look-and-feel using this approach and lightweight design

Programmer Perspective

  • Programmers using Swing components don't typically need to consider the MVC architecture
  • User interface components have wrapper classes like JButton or JTextField that store the model and view
  • The wrapper class asks the model for content information
  • The wrapper class forwards requests to the view when the display needs to change
  • JButton is a wrapper class inheriting from JComponent
  • It contains the DefaultButtonModel object, view data (button label/icon), and a BasicButton object for the button view
  • The Swing MVC architecture has side effects
  • Developers should not use independent threads to change model states in components
  • Updates to a component's model state should occur from the event dispatching queue once the component has been painted
  • The event-dispatching queue communicates events, including those that repaint components
  • Issues arise from the MVC architecture related to performance and potential race conditions
  • Swing components draw themselves based on state values in the model
  • Incorrect repainting can occur if state values change during the repainting process
  • Locking the entire model or cloning data to prevent repainting issues can hinder performance
  • State changes should occur serially with refreshes, so changes in component state do not coincide with Swing repaints, preventing race conditions

MVC: The Observer/Observable Pattern

  • Pattern name: Observer/Observable
  • Category: Behavioral
  • Problem: How to update objects when another object changes state
  • This relates to the "model-view" aspect of MVC or "Document-View Architecture"
  • If data changes, multiple views need to update themselves
  • The observer pattern solves this problem
  • Java's java.util library includes this solution
  • Solution: Two object types needed to implement the observer pattern in Java
  • The Observable class tracks objects that need to be informed when a change happens

Observables

  • The Observable class tracks objects that need to be informed when a change happens whether the "state" has changed or not
  • Observable class uses the notifyObservers() method to tell them to update
  • notifyObservers() is part of the base class Observable
  • There are two changable aspects of the observer pattern: the size of the observing objects list and how an update transpires
  • The observer pattern allows modification of observing objects list and update occurrences
  • Observer is an interface class with one member function, update()
  • The update function is called when the observed object decides it is time to update all observers
  • update() can have optional arguments for generality.
  • It allows the observed object to pass the updating object (Observer) and extra information -The observed object decides when and how to update -- called Observable
  • Observable uses a flag to indicate changes, to notify Observers only when appropriate
  • Control of the flag's state is restricted to inheritors of the Observer class so that only an inheritor decides when there is a change
  • Most of the work is done in notifyObservers(). If the flag is not set, nothing happens
  • Otherwise, clears the changed flag to prevent repeated calls to notifyObservers() from wasting time
  • setChanged() is the member function to call in derived-class code, used for changed flags
  • Observer and Observer work asynchronously and independently

Splash Screen

  • A splash screen is an initial window that can appears as an application launches
  • Intended to indicate to the user when the application is launching during long startup times
  • Used for advertising a product or basic info
  • Used for providing information that is only needed once per visit

Basic Steps

  • Display splash-screen image and something over the image
  • Splash-screen has an overlay surface with an alpha channel, accessible with a traditional interface
  • Example code: obtain a SplashScreen object, then create a graphics context as
    • JWindow window = new JWindow();
    • window.getContentPane().add(new JLabel("", new ImageIcon("splash.gif"), SwingConstants.CENTER));
    • window.setBounds(500, 150, 300, 200);
    • window.setVisible(true); try { Thread.sleep(5000); } catch (Exception e) {
  • JFrame frame = new JFrame();
  • frame.add(new JLabel("Welcome"));
  • frame.setVisible(true);
  • frame.setSize(300, 100);
  • frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); window.dispose();

Progress Bar and Monitors: Terminology

  • Progress Bars and Progress Monitors show the progress of a slow activity
  • A JProgressBar is a Swing component that shows the program's activity.
  • A ProgressMonitor is a dialog box with a progress bar and other data
  • A ProgressMonitorInputStream displays a progress monitor dialog while the input stream is read automatically

Progress Basics

  • A progress bar uses a rectangle with the proportion filled in with color
  • The bar indicates the progress of an activity
  • Progress bars can have an indeterminate mode, where there is an annimation to indicate that work is occuring
  • Progress can be a growing color bar, or a string showing “N%” like
    • %52
  • Look and Feels vary, with Windows Look and Feel using a bar created with adjacent rectangles
  • If task length is unknown can switch progress bar to the indeterminate mode
  • web browsers use this

Creating Progress Bars

  • default Java Look and Feel, the progress bar shows a colored rectangle back and forth
  • Progress bars should switch to a determinate mode when there is meaningful information becoming available
  • To create a progress bar, construct a progress bar by providing the minimum and maximum value and an optional orientation:
    • JProgressBar progressBar = new JProgressBar(0, 1000);
    • JProgressBar progressBar = new JProgressBar(StringConstants.VERTICAL,0, 1000);
  • These can be set using the Maximum() and Minimum() methods
  • Progress bars do not respond to user actions.
  • Update the bar value calling setValue() method.
  • to display a string “N%” must call setStringPainted(true), the progress bar calculates the completion percentage and automatically displays the resulting sting
  • To change or set the string, call setString() method:
    • If (progressBar.getValue() > 500) progressBar.setString("Half done");
  • To use a progress bar it must be placed inside a container
  • A ProgressMonitor contains a progress bar. Typically, it contains a Cancel button
  • Check isCanceled() to see if ProgressMonitor is running, and exit the monitiored task if cancelled
  • To construct progress monitor, supply the following parameters:
    • The parent component over which the dialog box should pop-up. If null, the dialog box will pop-up in the center of the screen. An object which should be a string, icon, or some other component) that is displayed on the dialog box.
    • A note to display below the object. It null, no note is displayed.
    • The minimum and maximum values
  • A progress monitor can’t measure or cancel. You need to call setProgress() method (equal to setValue() for progress bars). When finished, dialog box will close.

Bar Behaviour

  • Cancel button executes close()
  • Monitors wait 500 ms before determining to popup
  • The monitor also waits until progress exceeds wait value. The dialog box will appear if too long ( +2000 ms)
  • Adjust minimum waiting period with setMillisToDecideToPopup().
  • Adjust minimum progress time with setMillisToPopup().

Progress Bars and Monitors Summarized

  • Monitor cancelation hard to handle. Instead, need handler to call isCancelled() periodically to see if the user has clicked Cancel

  • If needing increased progress monitor control, use progress bars. Progress bars can be reused, but progress monitors cannot be reused- must be created

  • Swing API has another monitor called the ProgressMonitorInputStream for monitoring data from stream. Allows the programmer to monitor the reading

  • Includes a reference progressMonitor to a object inside itself for reading updates For the most part the ProgressMonitorInputStream class contains many of the methods you can find in the InputSteram class.

  • When it is created, the ProgressMonitorInputStream attempts to read the amount of data available and updates automatically the progress monitor.

  • File should be sufficiently large to see progress dialog

  • Progress monitor stream uses the available() method of the InputStream class to determine the total number of bits in the stream, it works well for files and HTTP URLs but it does not work well with streams which allow blocking

  • JavaFX has similar controls ProgressBar and ProgressIndicator, but no ProgressMonitor. See link for details

About UML Notations

  • UML is a block composed of things, relationships, and diagrams. Diagrams give play an essential role in UML diagram construction
  • There are basic blocks
    1. UML Building Blocks
    2. Relationships
    3. Diagrams

UML Things

  • Terms for real-world concepts divided into
    • Structural things
    • Behavioral Things
    • Grouping Things
    • Annotational Things
  • Structural things refer to the model's static properties or physical notions
    • Classes are sets of objects with attributes and function as well as abstract functions
    • An Object inidvidualizes the description of a class or system operation. notation is similar with objects names underlined
    • An interface is a set of operations describing functionality of a class, interface is implemented with interface implementation
    • Collaboration represents interaction to meet goals; symbolized by a dotted ellipse with a name inside
    • A Use case represents a set of actions that a system executes to achieve a goal
    • Actors come under the use case and acts as a system
  • Components are physical artifacts of the system
  • A node as an element

Behavioral Things

  • Includes dynamic model aspects such as state machine, activity or interaction
  • A State Machine definies entities undergoing software development, and keeps a record of the various states
  • Interaction Diagram
    • Activity diagram depicts the execution for system entities. It consists of states and decision boxes
    • Interaction Diagram: to envision messages between components

Grouping and Annotations

  • A package serves as a grouping mechanism in UML
    • Grouping is when a binding occurs for UML elements, packages are the structural grouping of an element
  • Annotations capture remarks, description and comments. Models describe. The only thing is notes, sticky notes

Relationships

  • Shows connecting of components with 4 associations
    • Dependency: Change affects element change from source. Depicts an entity
    • Note dotted line follow by arrows like: .. ->
    • Association - A set of joins with UML model. Tell a relationship
    • Note: dotted with two arrows <-- Association ->
    • Portrays parent child inheritance with a line followed by an empty arrowhead
    • Realization connects behaviours with implementation which exists in interfaces and dotted line with arrow

Diagrams

  • Diagrams are models with graphics symbols and text- each has a different meaning with each diagram

  • UML2.0 UML diagrams come in thirteen styles which can be structural or behavioural

UML Diagram Types

  • Structural Diagrams are static systems and how they interact in a system which is how components interact and what resides in the system
    • Object Diagram
    • Package Diagram
    • Deployment Diagram Behavioral Diagrams are system features and dynamic element in the system
    • Activity Diagram
    • State machine Diagram
    • Use case Diagram Interaction subset
    • Subset behavior and flow between objects
    • Timing diagram
    • Collaboration Diagram

Studying That Suits You

Use AI to generate personalized quizzes and flashcards to suit your learning preferences.

Quiz Team

Related Documents

More Like This

MVC and MVVM Patterns in Software Design
16 questions
Architectural Patterns and Their Benefits
16 questions
MVC Design Pattern Overview
8 questions
Architectural Design and MVC Patterns
48 questions
Use Quizgecko on...
Browser
Browser