Sie sind auf Seite 1von 14

Objects as Classes

Peter Blanchfield

Introduction to Software Engineering

Monday, 20 February 2012

Slide

The Software to be designed

What have we got


Frame Panel Tank Alien But also

Peter Blanchfield

Introduction to Software Engineering

Monday, 20 February 2012

Slide

Objects

Need to Identify Then decide classes


What attributes What methods Hierarchy? Dependencies

Peter Blanchfield

Introduction to Software Engineering

Monday, 20 February 2012

Slide

Objects

The Frame!
What has it got? Title Close, minimize, maximize

Peter Blanchfield

Introduction to Software Engineering

Monday, 20 February 2012

Slide

Objects

The Panel
This is where things are drawn It has a way to draw itself That includes its background image It goes in the frame

Peter Blanchfield

Introduction to Software Engineering

Monday, 20 February 2012

Slide

Objects

These two things


The Frame a JFrame The Panel a JPanel Imported package!
import javax.swing.*;

Come from

The compiler will not include anything you dont use

Peter Blanchfield

Introduction to Software Engineering

Monday, 20 February 2012

Slide

Diagram

We can diagram a class First we have a box with the name Let us start with the Frame

SpaceFrame

Peter Blanchfield

Introduction to Software Engineering

Monday, 20 February 2012

Slide

JFrame

Our frame will be a special form of a JFrame


This is in the javax swing package
import javax.swing.*;

JFrame

We can show that the JFrame is the general form


SpaceFrame

Peter Blanchfield

Introduction to Software Engineering

Monday, 20 February 2012

Slide

Panel

In the same way the Panel inherits from the JPanel


JPanel

AlienLandingPanel

Peter Blanchfield

Introduction to Software Engineering

Monday, 20 February 2012

Slide

The Panel is an attribute of the Frame


It is our drawing canvas It is added to the JFrame We use the add(object) method of the JFrame class We divide our class model with two lines SpaceFrame One section will hold the attributes alienLandingPanel The other the methods
add(Object)

Peter Blanchfield

Introduction to Software Engineering

Monday, 20 February 2012

Slide

10

Inheritance

The SpaceFrame will inherit from the JFrame Creating a new more special version of JFrame We can override JFrame methods Or use them direct
For example the JFrame constructor has a form with a title This can be called from the SpaceFrame constructor
super(name);

Alternatively the parent setName method can be called


super.setName(name);

In both these cases name is a string that you have assigned the actual name to. Might be an SpaceFrame constructor parameter
Introduction to Software Engineering Monday, 20 February 2012 Slide

Peter Blanchfield

11

Model Parameter
SpaceFrame

SpaceFrame(name:String)

Peter Blanchfield

Introduction to Software Engineering

Monday, 20 February 2012

Slide

12

The relationship

The AlienLandingPanel is not inherited from the SpaceFrame But they are related One AlienLandingPanel will be added to the SpaceFrame
SpaceFrame AlienLandingPanel

Contains

Is In

Peter Blanchfield

Introduction to Software Engineering

Monday, 20 February 2012

Slide

13

Multiplicity

This is a one to one relationship


SpaceFrame AlienLandingPanel

Contains

Peter Blanchfield

Introduction to Software Engineering

Monday, 20 February 2012

Slide

14

Das könnte Ihnen auch gefallen