Inheritance Review CSC 171 FALL 2004 LECTURE 19. READING Read Horstmann, Chapter 11 Look at Chapter 12 – Will not be on MT or Final – One lab Begin Reading.

Slides:



Advertisements
Similar presentations
Introduction to Java 2 Programming
Advertisements

Java GUI building with the AWT. AWT (Abstract Window Toolkit) Present in all Java implementations Described in (almost) every Java textbook Adequate for.
Graphical User Interfaces
Unit 3 Graphical User Interface (GUI) Dr. Magdi AMER.
Graphic User Interfaces Layout Managers Event Handling.
CMSC 341 Building Java GUIs. 09/26/2007 CMSC 341 GUI 2 Why Java GUI Development? Course is about Data Structures, not GUIs. We are giving you the opportunity.
Corresponds with Chapter 12
Inheritance Part I. Lecture Objectives To learn about inheritance To understand how to inherit and override superclass methods To be able to invoke superclass.
(C) 2010 Pearson Education, Inc. All rights reserved. Java™ How to Program, 8/e.
Chapter 13 Inheritance. An Introduction to Inheritance Inheritance: extend classes by adding methods and fields (variables) Example: Savings account =
The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Adrian Ilie COMP 14 Introduction to Programming Adrian Ilie July 20, 2005.
Slides prepared by Rose Williams, Binghamton University Chapter 17 Swing I.
1 Evan Korth New York University Inheritance and Polymorphism Professor Evan Korth New York University.
GUI and Event-Driven Programming Recitation – 3/6/2009 CS 180 Department of Computer Science, Purdue University.
1 Evan Korth New York University Inheritance and Polymorphism Professor Evan Korth New York University.
1 GUI Elements in Java Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
COMP 14 Introduction to Programming Miguel A. Otaduy June 7, 2004.
Layout Mangers CSC 171 FALL 2001 LECTURE 14. History: The Transistor William Shockley, John Bardeen, and Walter Brattain invent the transfer resistance.
Unit 11 Object-oriented programming: Graphical user interface Jin Sa.
GUI and event-driven programming An introduction.
Java Programming Chapter 10 Graphical User Interfaces.
OOP (Java): Layout/ OOP Objectives – –describe the basic layout managers for GUIs Semester 2, GUI Layout.
Using Inheritance to Customize Frames Use inheritance for complex frames to make programs easier to understand Design a subclass of JFrame Store the components.
Inheritance and Class Hierarchies Ellen Walker CPSC 201 Data Structures Hiram College.
Java Software Solutions Lewis and Loftus Chapter 10 1 Copyright 1997 by John Lewis and William Loftus. All rights reserved. Graphical User Interfaces --
MSc Workshop - © S. Kamin, U.Reddy Lect 5 – GUI Prog - 1 Lecture 5 – GUI Programming r Inner classes  this and super r Layout r Reading: m.
CIS 068 Welcome to CIS 083 ! Introduction to GUIs: JAVA Swing.
Layout Management Containers can arrange their components. Our container is a JPanel, and it can set the way it’s components will be laid out : mypanel.setLayout.
Applets and Frames CS 21a: Introduction to Computing I First Semester,
Introduction to GUI in Java 1. Graphical User Interface Java is equipped with many powerful,easy to use GUI component such as input and output dialog.
Specialization and Inheritance Chapter 8. 8 Specialization Specialized classes inherit the properties and methods of the parent or base class. A dog is.
Adding Graphics to a Frame Application Applets: Can generate drawings by overriding paint Frame: Do not draw directly on a frame. Draw graphics on a JPanel.
Java Programming: Advanced Topics 1 Common Elements of Graphical User Interfaces Chapter 6.
1 Why layout managers Can we perform layout without them? –Yes. A container’s layout property can be set to null. Absolute positioning: specify size and.
Chapters (ArrayList / Generic)
AP Computer Science A – Healdsburg High School 1 Interfaces, Abstract Classes and the DanceStudio - Similarities and Differences between Abstact Classes.
Copyright © 2002, Systems and Computer Engineering, Carleton University c-Gui3.ppt * Object-Oriented Software Development Part 18-c Building.
MT311 Java Application Development and Programming Languages Li Tak Sing ( 李德成 )
Object Oriented Programming Engr. M. Fahad Khan Lecturer, Software Engineering Department University of Engineering & Technology, Taxila.
Applets and Frames. Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved L14: GUI Slide 2 Applets Usually.
GUI Programming using NetBeans. RHS – SOC 2 GUI construction We have previously talked about elements in a (simple) GUI –Frames, Panes and Dialogs –Text.
GUI Basics. What is GUI? A graphical user interface (GUI) is a type of user interface item that allows people to interact with programs in more ways than.
1 / 67 COP 3503 FALL 2012 SHAYAN JAVED LECTURE 14 Programming Fundamentals using Java 1.
Computer Science 209 GUIs Model/View/Controller Layouts.
J McQuillanSE204:2004/2005: Lecture 3Slide 1 Specialised Components Can create specialised components. Do this by subclassing the component that you are.
AWT Layout Managers (Chapter 10) Java Certification Study Group January 21, 1999 Mark Roth.
Inheritance and Class Hierarchies Chapter 3. Chapter 3: Inheritance and Class Hierarchies2 Chapter Objectives To understand inheritance and how it facilitates.
1 Layout Managers Layout managers –Provided for arranging GUI components –Provide basic layout capabilities –Processes layout details –Programmer can concentrate.
Graphical User Interface (GUI) Two-Dimensional Graphical Shapes.
CSI 3125, Preliminaries, page 1 Inheritance. CSI 3125, Preliminaries, page 2 Inheritance Using inheritance, can create a general class that defines traits.
1 Object-Oriented Programming Inheritance. 2 Superclasses and Subclasses Superclasses and Subclasses  Superclasses and subclasses Object of one class.
Inheritance INHERITANCE: extend existing classes by adding or redefining methods, and adding instance fields Suppose we have a class Vehicle: public class.
Chapter 10 - Writing Graphical User Interfaces1 Chapter 10 Writing Graphical User Interfaces.
Graphical User Interface (GUI)
Event Handler Methods Text field Object Responder JAVA AWT Environment: Messages are sent between JAVA Objects Screen Event Notification Press Button.
Introduction to GUI in 1 Graphical User Interface 3 Nouf Almunyif.
Introduction to GUI Programming in Java: Frames, Simple Components, and Layouts.
GUI.1 Graphical User Interfaces GUIs. GUI.2 The Plan Components Flat Layouts Hierarchical Layouts Designing a GUI Coding a GUI.
Chapter 7 A First Look at GUI Applications Layout Managers.
Christopher Budo, Davis Nygren, spencer franks, Luke miller
Lecture 12 Inheritance.
GUIs Model/View/Controller Layouts
Tim McKenna Layout Mangers in Java Tim McKenna
Week 4 Object-Oriented Programming (1): Inheritance
Chap 7. Building Java Graphical User Interfaces
Graphical User Interfaces -- Introduction
Tim McKenna Layout Mangers in Java Tim McKenna
Creating Graphical User Interfaces
Advanced Programming Behnam Hatami Fall 2017.
Presentation transcript:

Inheritance Review CSC 171 FALL 2004 LECTURE 19

READING Read Horstmann, Chapter 11 Look at Chapter 12 – Will not be on MT or Final – One lab Begin Reading Chapter 13

Object: The Cosmic Superclass All classes extend Object Most useful methods: – String toString() – boolean equals(Object otherObject) – Object clone() // Clone copies objects

Abstract Classes We saw with Interfaces, a way to define a signature for a method, without implementation – requiring later implementation We can do this in the context of inheritance using sub/superclass hierarchies using abstract methods and classes

Abstract Methods public abstract class BankAccount { public abstract void deductFees(); } Can’t be instantiated

___________________ is a method for extending existing classes by adding methods and fields.

__Inheritance__________ is a method for extending existing classes by adding methods and fields.

The more general class is called a _____________________. The more specialized class that inherits from it is called the _____________________.

The more general class is called a ___SUPERCLASS___. The more specialized class that inherits from it is called the ____SUBCLASS__________.

Every class extends the _____________ class either directly or indirectly.

Every class extends the ___Object______ class either directly or indirectly.

Inheriting from a class differs from realizing an interface. The subclass inherits ________________ and ______________ from the superclass.

Inheriting from a class differs from realizing an interface. The subclass inherits _________behavior_______ and ___state___________ from the superclass.

One advantage of inheritance is _______________________.

One advantage of inheritance is ___code reuse___________.

When defining a subclass, you specify added ___________________, added _______________, and changed or ____________________ methods.

When defining a subclass, you specify added _instance fields________, added _methods___________, and changed or _overridden________ methods.

Sets of classes can form complex inheritance ________________________.

Sets of classes can form complex inheritance _____hierarchies______.

A subclass has __________ access to private fields fo its superclass.

A subclass has _____NO___ access to private fields of its superclass.

Use the ____________________ keyword to call a method of the superclass.

Use the _______super_______ keyword to call a method of the superclass.

To call the superclass constructor, you use the _____________ keyword in the ____________ statement of the subclass constructor.

To call the superclass constructor, you use the __super______ keyword in the __first______ statement of the subclass constructor.

A _________________ reference can be cast/converted to a ____________ reference, but not the other way around.

A ______subclass_____ reference can be cast/converted to a ___superclass____ reference, but not the other way around.

An _______________ method is one whose implementation is not specified.

An __abstract____ method is one whose implementation is not specified.

An ___________________ class cannot be instantiated.

An _____abstract________ class cannot be instantiated.

A field or method that is not declared as public, private, or protected can be accessed by all classes in the same ___________, which is usually not desirable.

A field or method that is not declared as public, private, or protected can be accessed by all classes in the same ____package_______, which is usually not desirable.

A field or method that is not declared as public, private, or protected can be accessed by all classes in the same ______________.

A field or method that is not declared as public, private, or protected can be accessed by all classes in the same _package____.

____________________ features can be accessed by all subclasses and all classes in the same package.

_Protected_______ features can be accessed by all subclasses and all classes in the same package.

You should define the __________________ method to yield a string that describes the object state.

You should define the _toString________ method to yield a string that describes the object state.

You should define the ____________________ method to test whether two objects have equal state.

You should define the _____equals______ method to test whether two objects have equal state.

The ____________________________- method makes a new object with the same state as an existing object.

The ______clone______________- method makes a new object with the same state as an existing object.

Excercise Vehicle Car Truck Sedan Coupe PickupTruck SUV Minivan Bicycle Motorcycle

Excercise Student Professor TA Employee Secretary DepartmentChair Janitor SeminarSpeaker Person Course Seminar Lecture

CHAPTER 12 – MORE GUI Applications

FRAME BASED APPLICATION public static void main(String[] args) { JFrame appFrame = new JFrame(); appFrame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE); appFrame.setContentPane(rectPanel); appFrame.pack(); appFrame.show(); }

Layout Management Container arranges its components By default, JPanel places components from left to right, then starts a new row if needed Panel layout carried out by FlowLayout layout manager Can set other layout managers panel.setLayout(new BorderLayout());

Border Layout Border layout places components into positions (center, north, west, south, east) panel.add(textField, BorderLayout.SOUTH );

Border Layout Content pane of frame has border layout by default frame.getContentPane().add(textField, BorderLayout.SOUTH); Border layout grows components to fit area To avoid growth, place component into panel (with flow layout), then add panel to content pane

Grid Layout Lays out components in rows and columns All components have the same size Add components left to right (top row first, then second row, etc.) panel.setLayout(new GridLayout(4, 3)); panel.add(button7); panel.add(button8); panel.add(button9); panel.add(button6);

Grid Layout

A Combo Box, Check Boxes, and Radio Buttons

Menu Items Pull-Down Menus Add menu items to the menu JMenuItem fileNew = new JMenuItem("New"); Add action listener to the menu item ActionListener l =...; fileNew.addActionListener(l);

Putting it all together

Menus