MVC Paradigm The MVC paradigm breaks applications or interfaces into three parts: the model, the view, and the controller. A --> 25 % B --> 60 % C -->

Slides:



Advertisements
Similar presentations
1 Event Listeners Some Events and Their Associated Event Listeners Act that Results in the EventListener Type User clicks a button, presses Enter while.
Advertisements

Introduction to Java Classes, events, GUI’s. Understand: How to use TextPad How to define a class or object How to create a GUI interface How event-driven.
Events ● Anything that happens in a GUI is an event. For example: – User clicks a button, presses return when typing text, or chooses a menu item ( ActionEvent.
1 Event Driven Programming with Graphical User Interfaces (GUIs) A Crash Course © Rick Mercer.
Creating a GUI with Swing. Introduction Very useful link: Swing – is a part of JFC (Java Foundation.
Unit 111 Java GUI Components and Events  Learning Outcomes oDistinguish between GUI components and containers. oIdentify and distinguish top-level containers.
Lecture 19 Graphics User Interfaces (GUIs)
Graphical User Interfaces
MSc IT Programming Methodology (2). Which printer [a] LPT1 or [b] LPT2?: How many copies do you wish to print?: [P]rint now or [C]ancel?: Print all pages.
1 Class 8. 2 Chapter Objectives Use Swing components to build the GUI for a Swing program Implement an ActionListener to handle events Add interface components.
Lesson 35: Review of the Java GUI. The JFrame, Container and JButton.
1 Event Driven Programming wirh Graphical User Interfaces (GUIs) A Crash Course © Rick Mercer.
Consolidation. Code making (i.e. making ciphers) is undertaken by a cryptographer whereas cryptanalysts try to break ciphers in order to gain intelligence.
Graphical User Interface CSI 1101 N. El Kadri. Plan - agenda Graphical components Model-View-Controller Observer/Observable.
MIT AITI 2003 Lecture 17. Swing - Part II. The Java Event Model Up until now, we have focused on GUI's to present information (with one exception) Up.
עקרונות תכנות מונחה עצמים תרגול 4 - GUI. Outline  Introduction to GUI  Swing  Basic components  Event handling.
1 Event Driven Programs Rick Mercer. 2 So what happens next?  You can layout a real pretty GUI  You can click on buttons, enter text into a text field,
Java Event Handling CSIS 3701: Advanced Object Oriented Programming.
CS Lecture 01 Frames and Components and events Lynda Thomas
GUI Chapter 10 Graphics context and objects Creating a window based application JFrame, JTextField, JButton Containers and Controls Graphics commands Layout.
1 CSC111H Graphical User Interfaces (GUIs) Introduction GUIs in Java Understanding Events A Simple Application The Containment Hierarchy Layout Managers.
Graphic User Interface. Graphic User Interface (GUI) Most of us interact with computers using GUIs. GUIs are visual representations of the actions you.
Object-Oriented Programming (Java), Unit 18 Kirk Scott 1.
Swing GUI Components You can create graphics components to place on your applet using classes available in the Swing package ( javax.swing ) Class names.
Introduction to GUI Programming with Java Graphical User Interfaces With AWT and Swing Towson University *Ref:
1 / 67 COP 3503 FALL 2012 SHAYAN JAVED LECTURE 14 Programming Fundamentals using Java 1.
 GUI – Graphic User Interface  Up to now in the programs we have written all output has been sent to the standard output device i.e.: the DOS console.
1 Class 6. 2 Objectives Objectives Enable your applications to perform actions in response to JButton clicks Get the text the user enters in a textfield.
Class Class 20 Objectives Use JCheckbox, JRadioButton, and a JComboBox in a UID.
Java GUI. Graphical User Interface (GUI) a list a button a text field a label combo box checkbox.
CompSci Event Handling. CompSci Event Handling The Plan  Sequential (Single Thread) Model  Event Model  Making the GUI interactive  Examples.
Ch13 Creating windows and applets. Short overview AWT (Abstract Windowing Toolkit) Early Java development used graphic classesEarly Java development used.
A simple swing example GETTING STARTED WITH WIND CHILL.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter Chapter 7-2 ( Book Chapter 14) GUI and Event-Driven Programming.
GUI Basics. Agenda What GUI How to make in java Creating frames Frequently used GUI components Layout Managers.
Computer Science 209 GUIs Model/View/Controller Layouts.
Graphical User Interfaces A Graphical User Interface (GUI) in Java is created with at least three kinds of objects: –components, events, and listeners.
Sadegh Aliakbary Sharif University of Technology Fall 2011.
1 Event Driven Programs Rick Mercer. 2 So what happens next?  You can layout a real pretty GUI  You can click on buttons, enter text into a text field,
Event-Driven Programming F Procedural programming is executed in procedural order. F In event-driven programming, code is executed upon activation of events.
Chapter 10 - Writing Graphical User Interfaces1 Chapter 10 Writing Graphical User Interfaces.
Swing GUI Components So far, we have written GUI applications which can ‘ draw ’. These applications are simple, yet typical of all Java GUI applications.
MIT AITI 2004 Swing Event Model Lecture 17. The Java Event Model In the last lecture, we learned how to construct a GUI to present information to the.
5-1 GUIs and Events Rick Mercer. 5-2 Event-Driven Programming with Graphical user Interfaces  Most applications have graphical user interfaces to respond.
1 A Quick Java Swing Tutorial. 2 Introduction Swing – A set of GUI classes –Part of the Java's standard library –Much better than the previous library:
Java Visual Applications CSIS 3701: Advanced Object Oriented Programming.
GUI.1 Graphical User Interfaces GUIs. GUI.2 The Plan Components Flat Layouts Hierarchical Layouts Designing a GUI Coding a GUI.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter Chapter 7 ( Book Chapter 14) GUI and Event-Driven Programming.
Lecture 6 Object Oriented Programming Using Java By Rashid Ahmad Department of Computer Science University of Peshawar.
Multiple buttons and action calls
Modular Event Handling
GUIs and Events Rick Mercer.
Introduction Many Java application use a graphical user interface or GUI (pronounced “gooey”). A GUI is a graphical window or windows that provide interaction.
CSC 205 Programming II Lecture 5 AWT - I.
Chapter 8 Event Handling.
CompSci 230 S Programming Techniques
Java Applet What is a Java Applet? How is applet compiled?
Web Design & Development Lecture 11
A First Look at GUI Applications
GUIs Model/View/Controller Layouts
Processing Timer Events
Chapter 4 Interface Types and Polymorphism Part 2
Architectural Patterns for Interactive Software
Ellen Walker Hiram College
Graphical user interface-based programming
Introduction to Event Handling
Component-Based Software Engineering
Objects At Their Best— Java's Abstract Window Toolkit
Programming Graphical User Interface (GUI)
CiS 260: App Dev I Chapter 6: GUI and OOD.
Presentation transcript:

MVC Paradigm The MVC paradigm breaks applications or interfaces into three parts: the model, the view, and the controller. A --> 25 % B --> 60 % C --> 15 % Model Users interact with a controller (e.g., buttons), and make changes to the model (e.g., data), which is then reflected in the view (e.g., graph). Control View(s) Draw Graph

MVC Relationships The Controller has references to both the view and the model; the controller is the base of the triad. The Model might have a reference to the view, to allow for notification of changes. The model does not know who controls it, however. The View has a reference to the model, for gathering data. View also has reference to the Controller, to notify of successful updates. (References are minimal, perhaps to a base class, to allow swapping of controls.) Model View Controller MVC Relationships

import java. awt. ; import java. awt. event. ; import javax. swing import java.awt.*; import java.awt.event.*; import javax.swing.*; public class CounterDisplay extends JFrame implements ActionListener{ JButton incButton, decButton; JTextField counterField; //constructor public CounterDisplay(){ setLayout(new FlowLayout()); incButton = new JButton("INC"); decButton = new JButton("DEC"); counterField = new JTextField("1", 5); //add button and textfield to the frame add(incButton); add(decButton); add(counterField); //register the listener incButton.addActionListener(this); counterField.addActionListener(this); setSize(150,100); setVisible(true); } public void actionPerformed(ActionEvent e){ //if the event is generated by the incButton if (e.getSource() == incButton){ counterField.setText((new Integer(Integer.parseInt(counterField.getText())+1)).toString()); //decButton public static void main(String[] args){ CounterDisplay app = new CounterDisplay(); //create the display instance app.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

public class Counter{ private int value; //constructor public Counter(int v){ value = v;} //set a value public void setValue(int v) {value = v;} //get current value public int getValue() {return value;} //increment the counter public void inc() {value++;} //decrement the counter public void dec() {value --;} }

/. Example of Model-Control-View. class CounterDisplay /** Example of Model-Control-View * class CounterDisplay * Control and display a Counter object */ public class CounterDisplay2 extends JFrame implements ActionListener{ Counter counter; //the Counter object to be controlled and displayed JButton incButton, decButton; JTextField counterField; //constructor public CounterDisplay2 (Counter aCounter){ counter = aCounter; setLayout(new FlowLayout()); incButton = new JButton("INC"); decButton = new JButton("DEC"); counterField = new JTextField("1", 5); //add button and textfield to the frame add(incButton); add(decButton); add(counterField); //register the listener incButton.addActionListener(this); counterField.addActionListener(this); setSize(150,100); setVisible(true); } public void actionPerformed(ActionEvent e){ //if the event is generated by the incButton if (e.getSource() == incButton){ counter.inc(); System.out.println(counter.getValue()); counterField.setText((new Integer(counter.getValue())).toString()); //if the event is generated by the decButton if (e.getSource() == decButton){ counter.dec(); //if ENTER is press on the text field if(e.getSource() == counterField){ counter.setValue(Integer.parseInt(counterField.getText()));

Another Example ShapeEditor