© 2006 Pearson Addison-Wesley. All rights reserved 9.1.1 Inheritance Systems Merchandise ElectronicsClothing TelevisionCamcorderShirtDressShoe DigitalAnalog.

Slides:



Advertisements
Similar presentations
Chapter 18 Building the user interface. This chapter discusses n Javas graphical user interface. n Swing: an enhancement of a library called the Abstract.
Advertisements

Rectangles moving and responding to the mouse. We want a window with a pile of rectangles in it When we click a rectangle it changes from filled to unfilled.
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.
Web Design & Development Lecture 19. Java Graphics 2.
The Point Class public class Point { public double x; public double y; public Point(double x0, double y0) { x = x0; y = y0; } public double distance(Point.
Graphics You draw on a Graphics object The Graphics object cannot directly be created by your code, instead one is generated when the method paintComponent.
Graphics Chapter 16.  If you want to draw shapes such as a bar chart, a clock, or a stop sign, how do you do it?
Inheritance // A simple class hierarchy. // A class for two-dimensional objects. class TwoDShape { double width; double height; void showDim() { System.out.println("Width.
Chapter 5 Programming Graphics. Chapter Goals To be able to write simple applications To display graphical shapes such as lines and ellipses To use colors.
More Java Drawing in 2D Animations with Timer. Drawing Review A simple two-dimensional coordinate system exists for each graphics context or drawing surface.
INTERFACES IN JAVA 1.Java Does not support Multiple Inheritance directly. Multiple inheritance can be achieved in java by the use of interfaces. 2.We need.
Lecture 10.2 Different Types of Loops, including for and do.
Applets An applet is similar to a Java program, but it runs within a Web-browser on a client machine. For security, you cannot change anything on a client.
Comp 249 Programming Methodology Chapter 7 - Inheritance – Part A Dr. Aiman Hanna Department of Computer Science & Software Engineering Concordia University,
© 2006 Pearson Addison-Wesley. All rights reserved Inheritance When one class inherits another class, the new class becomes a specialized version.
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.
CS102--Object Oriented Programming Lecture 7: – Inheritance Copyright © 2008 Xiaoyan Li.
1 Lecture 06(Abstract Classes)Lecture 9 Abstract Classes Overview  Abstract Classes: A Definition.  Declaring Abstract Classes.  Abstract Methods: A.
© 2006 Pearson Addison-Wesley. All rights reserved8-1 The final Modifier A method marked final indicates that it cannot be overridden with a new definition.
Slides prepared by Rose Williams, Binghamton University Chapter 20 Java Never Ends.
Slides prepared by Rose Williams, Binghamton University Chapter 11 Recursion.
Slides prepared by Rose Williams, Binghamton University Chapter 6 Arrays.
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.
Chapter 3 Describing Syntax and Semantics. Copyright © 2007 Addison-Wesley. All rights reserved 3–2.
Web Design & Development Lecture 18. Java Graphics.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 20.1 Test-Driving the Screen Saver Application.
Chapter 15 Graphics and Java 2D™ Java How to Program, 8/e (C) 2010 Pearson Education, Inc. All rights reserved.
Inheritance Like father like son Image from:
CSC 205 Java Programming II Polymorphism. Topics Polymorphism The principle of substitution Dynamic binding Object type casting Abstract class The canonical.
Canvas and Graphics CS 21a. 9/26/2005 Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved L17: Canvas.
Graphics Copyright © 2015 by Maria Litvin, Gary Litvin, and Skylight Publishing. All rights reserved. Java Methods Object-Oriented Programming and Data.
Lecture 8.3 The Use of JComponent. © 2006 Pearson Addison-Wesley. All rights reserved More About the Standard Drawing Classes java.awt.Container.
-Sai Phalgun Tatavarthy. Outline What is a “Graphing Calculator”? Graphics, Graphics2D classes Methods of Graphics object Custom Painting The paintComponent()
Graphic User Interface. Graphic User Interface (GUI) Most of us interact with computers using GUIs. GUIs are visual representations of the actions you.
© 2006 Pearson Addison-Wesley. All rights reserved How to Design a Supplier 1) Determine the public methods. (Don’t forget the constructor(s).) 2)
Creating Your Own Widgets CompSci 230 S Software Construction.
Lecture 8.5 Animating with EventTimer. © 2006 Pearson Addison-Wesley. All rights reserved A Crash Course in the Use of Timed Events What kinds of.
EVENTS Wiring together objects, code, and actions.
Java Graphics Graphical Components as objects. Graphics A Component is ◦A rectangular region of a computer screen ◦A graphical entity ◦Can sometimes contains.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 21.1 Test-Driving the Painter Application.
(C) 2010 Pearson Education, Inc. All rights reserved.  Class Graphics (from package java.awt) provides various methods for drawing text and shapes onto.
BallWorld.java A structured walkthrough. Key Features: 2 classes are created Execution is done through the procedure called “main” which are decleared.
Inheritance Notes Chapter 6 1. Inheritance  you know a lot about an object by knowing its class  for example what is a Komondor? 2
Computer Science 209 The Adapter Pattern. The Context of the Adapter Pattern I want to use an existing class (the adaptee) without modifying it The context.
Classes Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
4.3.1 Non-void Methods Parameters are largely one-way communication.  Shared instances variables is one way to accomplish this. calling codemethod parameter.
Application development with Java Lecture 21. Inheritance Subclasses Overriding Object class.
29-July-2002cse Inheritance © 2002 University of Washington1 Inheritance CSE 142, Summer 2002 Computer Programming 1
Lecture 3.1 Using Graphics with JFrame. © 2006 Pearson Addison-Wesley. All rights reserved javax.swing.JFrame - int x - int y - int width - int.
CSI 3125, Preliminaries, page 1 AWT. CSI 3125, Preliminaries, page 2 AWT Java AWT (Abstract Windowing Toolkit) is an API to develop GUI or window-based.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 27.1 Test-Driving the Drawing Shapes Application.
© 2006 Pearson Addison-Wesley. All rights reserved Non-void Methods Parameters are largely one-way communication.  Shared instances variables is.
Lecture 8.2 Aggregation and Inheritance. © 2006 Pearson Addison-Wesley. All rights reserved Designing with Aggregation and Inheritance Software.
CS/ENGRD 2110 SPRING 2016 Lecture 2: Objects and classes in Java 1.
Graphics JavaMethods An Introduction to Object-Oriented Programming Maria Litvin Gary Litvin Copyright © 2003 by Maria Litvin, Gary Litvin, and Skylight.
CS202 Java Object Oriented Programming GUI Programming – Color and Drawing Methods Chengyu Sun California State University, Los Angeles.
Creating Your Own Widgets
Aggregation and Inheritance
public class Doubler extends Base {
Java Swing.
Introduction to Object-oriented Program Design
Inheritance "Question: What is the object oriented way of getting rich? Answer: Inheritance.“ “Inheritance is new code that reuses old code. Polymorphism.
4.14 GUI and Graphics Case Study: Creating Simple Drawings (Cont.)
Class Hierarchies and Type Conformance
Class Everything if Java is in a class. The class has a constructor that creates the object. public class ClassName private Field data (instance variables)
CS/ENGRD 2110 Spring 2019 Lecture 2: Objects and classes in Java
Inheritance Lakshmish Ramaswamy.
Presentation transcript:

© 2006 Pearson Addison-Wesley. All rights reserved Inheritance Systems Merchandise ElectronicsClothing TelevisionCamcorderShirtDressShoe DigitalAnalog

© 2006 Pearson Addison-Wesley. All rights reserved Another Hierarchy AcademicDisciplines Mathematics Engineering AlgebraGeometryIndustrialElectricalCivilProbability

© 2006 Pearson Addison-Wesley. All rights reserved Ancestors & Descendants ClosedFigure Ellipse Polygon Circle Square QuadrilateralPentagonTriangle

© 2006 Pearson Addison-Wesley. All rights reserved Conformance ClosedFigure Ellipse Polygon Circle Square QuadrilateralPentagonTriangle A type conforms to itself or any ancestor. A conforms to B means A B Conformance is _____________!

© 2006 Pearson Addison-Wesley. All rights reserved Rule for Using Conformance An expression is permitted anywhere that its type conforms. assignment object = expression; expression must conform to object parameter passage object. method(arg1, arg2, … argN); arg1 must conform to parm1 arg2 must conform to parm2... argN must conform to parmN expressions expression Anything with type that conforms to expression can be substituted in its place. Remember: Conformance is directional! public void method(parm1, parm2,…parmN) { … } public void method(parm1, parm2,…parmN) { … }

© 2006 Pearson Addison-Wesley. All rights reserved OvalRectangleLine JComponent Inheritance java.awt. Component «queries» + Color getBackground() + Color getForeground() + int getX() + int getY() + int getWidth() + int getHeight() + Container getParent() «update» + void setBackground( Color ) + void setForeground( Color ) + void setBounds(int, int, int, int) + void setSize( int, int ) + void setLocation( int, int ) + void paint( Graphics ) + void repaint() javax.swing. JComponent «constructor» + JComponent() «queries» + int getX() + int getY() + int getWidth() + int getHeight() «update» + void paint( Graphics ) + void paintChildren() + void setBackground( Color ) + void setForeground( Color ) java.awt. Container «update» + void add( Component ) + void add( Component, int ) + void remove( Component ) + void removeAll( )

© 2006 Pearson Addison-Wesley. All rights reserved Using Inheritance and Conformance Write a function that returns true exactly when its Oval parameter has a height of 10 or greater. public boolean isTenOrMoreHigh( Component v ) { return v.getHeight() >= 10; } What is the advantage of using a parameter of type Component, instead of an Oval ?

© 2006 Pearson Addison-Wesley. All rights reserved Testing for Type conformance Java provides the following operator to test for type conformance. instanceof Syntax expression instanceof className Semantics This is a Boolean expression that evaluates to true exactly when the type of expression conforms to className. Example if (myVar instanceof Component)...