Overview of our Approach Program Structure –Data, variables, and parameters –Basic control structures (conditionals, loops and Threads) –Class definitions.

Slides:



Advertisements
Similar presentations
2D Graphics Drawing Things. Graphics In your GUI, you might want to draw graphics E.g. draw lines, circles, shapes, draw strings etc The Graphics class.
Advertisements

Chapter 6 Objects and Classes F OO Programming Concepts F Creating Objects and Object Reference Variables –Differences between primitive data type and.
Programming Languages and Paradigms
L3:CSC © Dr. Basheer M. Nasef Lecture #3 By Dr. Basheer M. Nasef.
Chapter 6 Introduction to Defining Classes
GUI and Swing, part 2 The illustrated edition. Scroll bars As we have previously seen, a JTextArea has a fixed size, but the amount of text that can be.
Defining classes and methods Recitation – 09/(25,26)/2008 CS 180 Department of Computer Science, Purdue University.
Lecture 2Slide 1 Event Driven Computing Basic Interaction Handling –Interactive programs - must pay attention to the user interface.
1 Frameworks. 2 Framework Set of cooperating classes/interfaces –Structure essential mechanisms of a problem domain –Programmer can extend framework classes,
Chapter 6 Graphical User Interface (GUI) and Object-Oriented Design (OOD)
Chapter 41 Defining Classes and Methods Chapter 4.
Chapter Day 5. © 2007 Pearson Addison-Wesley. All rights reserved2-2 Agenda Day 5 Questions from last Class?? Problem set 1 Posted  Introduction on developing.
Graphics Programming. In this class, we will cover: The difference between AWT and Swing Creating a frame Frame positioning Displaying information in.
Java Programming, 3e Concepts and Techniques Chapter 3 Manipulating Data Using Methods.
ObjectDraw and Objects Early Chris Nevison Barbara Wells.
Programming What is a program? –A set of instructions –Understood by a computer.
Review CSC 171 FALL 2004 LECTURE 21. Topics Objects and Classes Fundamental Types Graphics and Applets Decisions Iteration Designing Classes Testing and.
About the Presentations The presentations cover the objectives found in the opening of each chapter. All chapter objectives are listed in the beginning.
Java Review Structure of a graphics program. Computer Graphics and User Interfaces Java is Object-Oriented A program uses objects to model the solution.
Drawing pictures with Java. JFrame: the basic Java window The swing package contains classes, objects and methods that can be used to create a consistent.
Copyright © 2003 ProsoftTraining. All rights reserved. Sun Certified Java Programmer Exam Preparation Guide.
Chapter 3 Introduction to Event Handling and Windows Forms Applications.
CSE 341, S. Tanimoto Concepts 1- 1 Programming Language Concepts Formal Syntax Paradigms Data Types Polymorphism.
Java Programming, 2E Introductory Concepts and Techniques Chapter 3 Manipulating Data Using Methods.
Programming Languages and Paradigms Object-Oriented Programming.
20-753: Fundamentals of Web Programming Copyright © 1999, Carnegie Mellon. All Rights Reserved. 1 Lecture 16: Java Applets & AWT Fundamentals of Web Programming.
Chapter 8: Writing Graphical User Interfaces
Week 3 Introduction to Computer Science and Object-Oriented Programming COMP 111 George Basham.
Teaching Loops Facilitated by introducing simple threads Few interesting loop examples before arrays –Boring calculations –Interaction –Drawing –Animation.
(c) University of Washington08-1 CSC 143 Models and Views Reading: Ch. 18.
Chapter 3 Syntax, Errors, and Debugging Fundamentals of Java.
APCS Java AB 2004 Review of CS1 and CS2 Review for AP test #1 Sources: 2003 Workshop notes from Chris Nevison (Colgate University) AP Study Guide to go.
1 Introduction Modules  Most computer programs solve much larger problem than the examples in last sessions.  The problem is more manageable and easy.
Lesson 34: Layering Images with Java GUI. The FlowLayout RECAP.
Graphic User Interface. Graphic User Interface (GUI) Most of us interact with computers using GUIs. GUIs are visual representations of the actions you.
CNS 1410 Graphical User Interfaces. Obectives Students should understand the difference between a procedural program and an Event Driven Program. Students.
Applications Development
1 Principles of Computer Science I Prof. Nadeem Abdul Hamid CSC 120 – Fall 2005 Lecture Unit 2 - Using Objects.
Chapter 6 Introduction to Defining Classes. Objectives: Design and implement a simple class from user requirements. Organize a program in terms of a view.
(C) 2010 Pearson Education, Inc. All rights reserved.  Class Graphics (from package java.awt) provides various methods for drawing text and shapes onto.
The Abstract Window Toolkit (AWT) supports Graphical User Interface (GUI) programming. AWT features include: a rich set of user interface components; a.
SWEN 5130Requirements Engineering Algebraic Specification Slide 1 Algebraic Specification u Specifying abstract types in terms of relationships between.
Object Oriented Programming.  Interface  Event Handling.
Intro to Applets. Applet Applets run within the Web browser environment Applets bring dynamic interaction and live animation to an otherwise static HTML.
A Class of Our Own We’ve used many classes: –Location –FilledRect –Color –Text –And More! –But what if we want to make our own class?
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 26 - Java Object-Based Programming Outline 26.1Introduction.
Java Object Oriented Programming Encapsulation, Inheritance, Polymorphism (Java: An Eventful Approach - Ch. 17, 21.7), Slides Credit: Bruce, Danyluk and.
Chapter 5 Introduction to Defining Classes
UMass Lowell Computer Science Java and Distributed Computing Prof. Karen Daniels Fall, 2000 Lecture 9 Java Fundamentals Objects/ClassesMethods Mon.
Chapter 7: Class Inheritance F Superclasses and Subclasses F Keywords: super and this F Overriding methods F The Object Class F Modifiers: protected, final.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Objects and Classes.
Liang, Introduction to Java Programming, Fifth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 6 Objects and Classes.
Graphics Tools and Parameters Chris Nevison Barbara Wells.
Creating a Java Application and Applet
Written by: Dr. JJ Shepherd
CompSci 44.1 Game Package Introduction to Jam’s Video Game Package.
Dr. Ahmet Cengizhan Dirican BIL 374 Internet Technologies 6. Dynamic Documents With JavaScript.
CS 112 Introduction to Programming Java Graphics Yang (Richard) Yang Computer Science Department Yale University 208A Watson, Phone:
UMass Lowell Computer Science Java and Distributed Computing Prof. Karen Daniels Fall, 2000 Lecture 10 Java Fundamentals Objects/ClassesMethods.
Chapter 5 Introduction to Defining Classes Fundamentals of Java.
CSE S. Tanimoto Java Introduction 1 Java A Programming Language for Web-based Computing.
Java Programming: Guided Learning with Early Objects
Chapter 3 Syntax, Errors, and Debugging
Java Primer 1: Types, Classes and Operators
Java Programming: Guided Learning with Early Objects
Java Classes (Java: An Eventful Approach, Ch. 6),
Implementing Non-Static Features
Corresponds with Chapter 5
Introduction to Computer Science and Object-Oriented Programming
Presentation transcript:

Overview of our Approach Program Structure –Data, variables, and parameters –Basic control structures (conditionals, loops and Threads) –Class definitions ( with interfaces but not inheritance) –I/O (that means GUI for us) Data Structures –Recursive class definitions and arrays Data Processing –Strings and streams –Sorting and searching

Program Structure Object-Oriented Graphics Primitives Mouse Event Handling Methods Instance Variables and Parameters Conditionals Class definitions Loops and Threads GUI components {}

Library Support A collection of “Drawable” classes –Line, FramedRect, FilledOval, … A “DrawingCanvas” –Collects and displays a set of Drawables –Functions as a “Component” in Java AWT or Swing.

Library Support A “WindowController” class –Student programs extend WindowController –WindowController: Extends Applet Supports simplified mouse events Creates “canvas” to hold Drawables ActiveObject class which extends Thread –Exceptionless sleep + simple getTime. –Automatic termination

WindowController Event Handling Methods Students determine response to mouse events by overriding methods: public void onMousePress( Location pos ) { new FilledRect( pos, width, height, canvas ); } –No “listener” setup required –Receives mouse coordinates as parameter

Event Handling Methods Methods to handle basic mouse events: –onMousePress, onMouseRelease, onMouseClick, onMouseDrag, onMouseMove, onMouseEnter, onMouseExit Override begin method for initialization

Graphic Constructors Drawable constructors expect position, shape, and canvas where object will appear new FilledRectangle( x, y,width,height,canvas); Objects appear “immediately” Drawing primitives can occur in any method

Canvas Coordinates Screen coordinates are measured in pixels Upper left corner of canvas is (0,0) Coordinates are encoded as double’s Location class used to encode a coordinate pair as a single object new FilledRectangle(corner,width,height,canvas);

Drawable Mutator Methods Methods are provided to modify location and appearance of displayed objects –box.moveTo( newX, newY ); –border.setColor( Color.red ); Changes appear “immediately”

Objects in Action Our graphical primitives were inspired by “mini- worlds” –Buggles and Bagels (Wellesley) –Karel the Robot (Bergin) Common advantages –Highly interactive, “tangible” learning experience Weakness of “mini-worlds” –Primitives introduced are not used throughout course

Drawable Stacking Object overlap determined by control of logical layering within canvas –box.sendToBack(); –circle.sendForward(); Objects can be temporarily hidden –frame.hide(); –circle.show(); VS.

Accessor Methods Methods provide access to attributes of graphical objects –box.getX() –oval.getWidth() Boolean methods to determine geometric relationships –box.contains( somepoint ) –box.overlaps( someoval )

Non-geometric Graphics Arbitrary GIF and JPEG images can be incorporated in drawings on canvas picture = getImage( “mountains.jpeg” ); new VisibleImage( picture, x, y, canvas );

Non-geometric Graphics (cont.) Text can also be included in drawings: new Text(“Hello World”, x, y, canvas);

Objects in Action Our graphics primitives were inspired by “mini- worlds” –Buggles and Bagels (Wellesley) –Karel the Robot (Bergin) Common advantages –Highly interactive, “tangible” learning experience Weakness of “mini-worlds” –Primitives introduced are not used throughout course

Introduction by Immersion Begin with intuitive explanations of simple example programs to introduce: –A small set of graphic primitives –Context of event driven programs

An Example public class Touched extends WindowController { public void onMousePress(Location point) { new Text("I'm Touched.", 100, 90, canvas); } public void onMouseRelease(Location point) { canvas.clear(); }

Introducing Events Limit attention to correspondence between mouse actions and handlers –Keep handler code simple –Avoid using parameters Don’t even mention the “event loop” –New paradigm == new virtual machine

Event Handling as a New Paradigm The standard paradigm: “A program is a sequence of instructions that specify how to accomplish a goal” Event-driven paradigm: “A program is a collection of sequences of instructions each of which specifies how to react to some event/request.”

Benefits of Event-driven Model Consistent with student experience. –GUI interfaces suggest programs are reactive More General –“main program” is just a “begin” event More Object-oriented –Object = collection of methods/behaviors –Program = object

Introducing Graphics Introduce conceptual framework in class –Coordinate system –Constructor and method syntax Explore details in lab –Litany of constructors and methods –Relationship between parameters and behavior

A Graphics Sandbox Self-paced, guided introduction

“Hello World?” Students write simple interactive program in first lab (after graphics sandbox experience) –Involves simple naming –Involves simple event handling –Reinforces syntax and behavior of graphics primitives

Variables and Assignment Start with instance variables of object types –Motivated by desire to modify objects someGraphic = new FilledRect(... );... someGraphic.move(5,5); –Examples often involve communication between “begin” and event handling methods. Actually introduced during 1st lab

Formal Parameters Mouse event handling methods receive cursor location as a single parameter –Students declare and use these formals –Actual/formal correspondence not an issue –Examples illustrate limited scope and lifetime of parameter values Some values must be saved using instance variables

What About Numbers? Early use of numeric values is limited –Initially, only numeric literals are used –First, non-constant numeric values come from accessor methods getX(), getY(), getWidth() –Introduce numeric expressions and assignments –Introduce random number generator class

Conditionals & Event Handling Introduce class definitions after conditionals to enrich example classes defined. With conditionals, students can complete surprisingly sophisticated programs –Event handling implicitly provides the iterative behavior needed without explicit loops

Box Dragging without Loops public void onMousePress( Location mouse ) { grabbed = box.contains(mouse); lastMouse = mouse; } public void onMouseDrag( Location mouse ) { if ( grabbed ) { box.move( mouse.getX() - lastMouse.getX(), mouse.getY() - lastMouse.getY() ); lastMouse = mouse; } }

Covering Conditionals Include traditional topics –Conditions based on numeric comparisons –Logical operations & booleans –Nested conditionals Graphics provides some unusual examples –Accessors that return booleans if ( box.contains(mousePosition) )...