DOC PREVIEW
TRINITY CSCI 1311 - Using Polymorphism
Pages 9

This preview shows page 1-2-3 out of 9 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 9 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 9 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 9 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 9 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

1Using Polymorphism11/26/20072Opening Discussion■Let's look at some solutions to the interclass problem.■Minute essay responsesArrays and bracketsThe add method can add to a list at any point.The differences between arrays and lists are syntax and the array is a fixed size with a fixed number of slots.Which you use depends on application, but most people use arrays by default because of the simpler syntax.Multidimensional arrays.3Inheritance and Subtyping■Last class we talked about inheritance, what it provides to us, and how we do it in Java.Code reuseSubtyping■We use the extends keyword when a class inherits from a class or implements when a class inherits from an interface.■Abstract classes can't be instantiated. Abstract methods aren't implemented in that class.■Interfaces are like completely abstract classes.■All classes in Java inherit from the Object class.4Polymorphism■The term polymorphism comes from Greek and it literally means many shapes. In programming it means many types.■A polymorphic type is a type that can represent many other types. A polymorphic operation/method is one that can work with many different types.■Polymorphism gives us a lot of power in our programming and can drastically reduce the amount of code we have to write because one method can be used with many different types.■Subtyping from inheritance gives us polymorphism.5GUI Libraries in Java■The GUI libraries in Java probably use inheritance more than any other set of libraries.■There are two main packages that you use when doing GUIs in Java.java.awt – the Abstract Window Toolkit was the original GUI library. It still has important helper classes.javax.swing – this is a “pure” Java library built on top of AWT that we will be using.■Let's look in that API at the Swing classes.6Components■Everything that goes into a GUI in Java inherits from Component. (In Swing they inherit from JComponent.)■This is where polymorphism comes into play because the code can be written to work with a Component and it will work with a button, check box, drop box, or any other component.■The Swing library has all the basic components you would expect to be able to put into GUIs as well as many others.7JFrame■For windows in the Swing library you use JFrames.■Let's look at the JFrame class and write some code to open up a window.■Now let's add one component to that frame.8Layout Managers■What we just wrote only has one limitation, we only got to add one component to the frame.■For adding multiple elements we use Layout Managers. These are classes that control how things go into a GUI container.■There are many layout types, but we will only deal with a few.FlowLayoutGridLayoutBorderLayout■Some Swing components have their own layouts.9Minute Essay■Have you done any of the reading recently? What have you read? Has it helped?■Interclass Problem – Write a GUI that brings up a frame and puts one button and one text box in the frame. Experiment with how to lay it out to make it look


View Full Document

TRINITY CSCI 1311 - Using Polymorphism

Course: Csci 1311-
Pages: 9
Documents in this Course
Arrays

Arrays

12 pages

Arrays

Arrays

10 pages

Applets

Applets

5 pages

Arrays

Arrays

8 pages

Methods

Methods

12 pages

Drawing

Drawing

8 pages

Load more
Download Using Polymorphism
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Using Polymorphism and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Using Polymorphism 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?