• Tidak ada hasil yang ditemukan

Programming in Java

N/A
N/A
Protected

Academic year: 2024

Membagikan "Programming in Java"

Copied!
7
0
0

Teks penuh

(1)

Programming in Java

CBCS BHCS03 By Parul Chachra

(2)

Chapter 31

Introducing Swing

Reference: Schildt, H. Java: The Complete Reference. 7th ediEon. McGraw-

Hill EducaEon

(3)

The MVC Architecture

•  By separaEng a component into a model, a view, and a controller, the specific

implementaEon of each can be changed without affecEng the other two

•  For instance, different view implementaEons can render the same component in different ways without affecEng the model or the

controller

(4)

MVC Architecture

source: hQps://www.guru99.com/mvc-tutorial.html

(5)

Swing and MVC

•  The high level of separaEon between the view and the controller in MVC is not beneficial for Swing components

•  Instead, Swing uses a modified version of MVC that combines the view and the controller into a single logical enEty called the UI delegate.

•  For this reason, Swing’s approach is called either the Model-Delegate architecture

•  As the view (look) and controller (feel) are separate from the model, the look and feel can be changed without affecEng how the component is used within a program

(6)

Swing and MVC

•  Most Swing components contain two objects.

•  The first represents the model which is responsible for storing the state of the

component. Models are defined by interfaces

•  The second represents the UI delegate which controls the display of the component and its event handling

•  For example, the model for a buQon is defined by the Bu,onModel interface

•  UI delegates are classes that inherit

ComponentUI. For example, the UI delegate for a buQon is Bu,onUI

(7)

Components and Containers

•  A component is an independent visual control, such as a push buQon or slider

•  A container holds a group of components.

•  Furthermore, in order for a component to be displayed, it must be held within a container

•  All Swing GUIs will have at least one container

•  Because containers are components, a

container can also hold other containers. This enables Swing to define what is called a

containment hierarchy, at the top of which must be a top-level container.

Referensi

Dokumen terkait

that uses Model View Controller ( MVC ) architectural pattern.It can be concluded that development of the Content Management System using MVC and ORM resulting in an

The Zend Framework also provides a complete implementation of the Model-View- Controller (MVC) pattern, which allows application business logic to be separated from the user

The flatMap method is applied using a lambda expression that returns an Optional instance of itself.. While not the same object, they

A unique system-level HTTP handler takes care of dispatching incoming requests to a specific controller class so that the instance of the class executes a given action method

A Simple Swing ApplicaEon • Swing programs differ from both the console-based programs and the AWT-based programs, for example, – They use a different set of components and a different

A Simple Swing ApplicaEon • main is executed on the main thread • Thus, main cannot directly instanEate a SwingDemo object • Instead, it must create a Runnable object that

• Its signature is shown here: int getClickCount • getBuPon method returns a value that represents the buPon that caused the event: int getBuPon • The return value will be one

• This is done by using addMouseListener and addMouseMo4onListener , which, as menFoned, are members of Component • They are shown here: void addMouseListenerMouseListener ml