Counter Practical whats going on - PowerPoint PPT Presentation

1 / 25
About This Presentation
Title:

Counter Practical whats going on

Description:

Digit units -Digit tens -Digit hundreds. Counter(JFrame f) void increment() void decrement ... { units = new Digit(..., frame); tens = new Digit(..., frame) ... – PowerPoint PPT presentation

Number of Views:52
Avg rating:3.0/5.0
Slides: 26
Provided by: davidc142
Category:

less

Transcript and Presenter's Notes

Title: Counter Practical whats going on


1
Counter Practicalwhats going on?
  • David Corsar
  • dcorsar_at_csd.abdn.ac.uk

2
Last week
  • Last week we looked at how to
  • Use rectangle as a supplier class for displaying
    a rectangle and getting it to change colour
  • Use 2 supplier classes (MovingSun and Oval) in
    the Sun Picture practical, and combine with a
    simple controller class (SunPicture) which tells
    MovingSun what to do

3
Counter Practical
  • We also started the Counter practical, today we
    will look at how it works

4
Counter practical Classes
Makes the 3 digit counter, tells each digit to
increment, decrement, makeZero where appropriate
Displays a Digit of the counter
Controller class provides window for Counter to
display and tells it what to do depending on
button press
5
What happens when it runs
  • Load BlueJ, create new CounterWindow
  • BlueJ creates a new instance of CounterWindow,
    calling its Constructor

public CounterWindow() window new
ThreeButtonFrame("Counter") counter new
Counter(window)
6
What happens when it runs
  • Load BlueJ, create new CounterWindow
  • BlueJ creates a new instance of CounterWindow,
    calling its Constructor
  • CounterWindow initialises counter to a new
    Counter instance

public CounterWindow() window new
ThreeButtonFrame("Counter") counter new
Counter(window)
7
What happens when it runs
  • Load BlueJ, create new CounterWindow
  • BlueJ creates a new instance of CounterWindow,
    calling its Constructor
  • CounterWindow initialises counter to a new
    Counter instance
  • Counter then initialises its 3 Digits

public Counter(JFrame frame) units new
Digit(..., frame) tens new Digit(...,
frame) hundreds new Digit(..., frame)
8
What happens when it runs
  • Load BlueJ, create new CounterWindow
  • BlueJ creates a new instance of CounterWindow,
    calling its Constructor
  • CounterWindow initialises counter to a new
    Counter instance
  • Counter then initialises its 3 Digits

public Counter(JFrame frame) units new
Digit(..., frame) tens new Digit(...,
frame) hundreds new Digit(..., frame)
9
What happens when it runs
  • Load BlueJ, create new CounterWindow
  • BlueJ creates a new instance of CounterWindow,
    calling its Constructor
  • CounterWindow initialises counter to a new
    Counter instance
  • Counter then initialises its 3 Digits

public Counter(JFrame frame) units new
Digit(..., frame) tens new Digit(...,
frame) hundreds new Digit(..., frame)
10
What happens when it runs
  • Load BlueJ, create new CounterWindow
  • BlueJ creates a new instance of CounterWindow,
    calling its Constructor
  • CounterWindow initialises counter to a new
    Counter instance
  • Counter then initialises its 3 Digits

public Counter(JFrame frame) units new
Digit(..., frame) tens new Digit(...,
frame) hundreds new Digit(..., frame)
11
What happens when it runs
  • Load BlueJ, create new CounterWindow
  • BlueJ creates a new instance of CounterWindow,
    calling its Constructor
  • CounterWindow initialises counter to a new
    Counter instance
  • Counter then initialises its 3 Digits

public Counter(JFrame frame) units new
Digit(..., frame) tens new Digit(...,
frame) hundreds new Digit(..., frame)
12
What happens when it runs
  • Load BlueJ, create new CounterWindow
  • BlueJ creates a new instance of CounterWindow,
    calling its Constructor
  • CounterWindow initialises counter to a new
    Counter instance
  • Counter then initialises its 3 Digits

public Counter(JFrame frame) units new
Digit(..., frame) tens new Digit(...,
frame) hundreds new Digit(..., frame)
13
What happens when it runs
  • Load BlueJ, create new CounterWindow
  • BlueJ creates a new instance of CounterWindow,
    calling its Constructor
  • CounterWindow initialises counter to a new
    Counter instance
  • Counter then initialises its 3 Digits

public Counter(JFrame frame) units new
Digit(..., frame) tens new Digit(...,
frame) hundreds new Digit(..., frame)
14
What happens when it runs
  • Load BlueJ, create new CounterWindow
  • BlueJ creates a new instance of CounterWindow,
    calling its Constructor
  • CounterWindow initialises counter to a new
    Counter instance
  • Counter then initialises its 3 Digits
  • Everything is set up ready to be used

public CounterWindow() window new
ThreeButtonFrame("Counter") counter new
Counter(window)
15
What happens when it runs
  • User clicks right button, calls rightAction on
    CounterWindow

public void rightAction()
counter.increment()
16
What happens when it runs
  • User clicks right button, calls rightAction on
    CounterWindow

public void rightAction()
counter.increment()
17
What happens when it runs
  • Increment tells the relevant digits to increment
  • Lets say units 9, tens 9, hundreds 0,

public void increment() units.increment() if
(units.getValue() 10) units.makeZero() tens.i
ncrement() if (tens.getValue()
10) tens.makeZero() hundreds.increment() if
(hundreds.getValue() 10) makeZero()
18
What happens when it runs
  • Increment tells the relevant digits to increment
  • now units 10, tens 9, hundreds 0,

public void increment() units.increment() if
(units.getValue() 10) units.makeZero() tens.i
ncrement() if (tens.getValue()
10) tens.makeZero() hundreds.increment() if
(hundreds.getValue() 10) makeZero()
19
What happens when it runs
  • Increment tells the relevant digits to increment
  • now units 10, tens 9, hundreds 0,

public void increment() units.increment() if
(units.getValue() 10) units.makeZero() tens.i
ncrement() if (tens.getValue()
10) tens.makeZero() hundreds.increment() if
(hundreds.getValue() 10) makeZero()
20
What happens when it runs
  • Increment tells the relevant digits to increment
  • now units 0, tens 9, hundreds 0,

public void increment() units.increment() if
(units.getValue() 10) units.makeZero() tens.i
ncrement() if (tens.getValue()
10) tens.makeZero() hundreds.increment() if
(hundreds.getValue() 10) makeZero()
21
What happens when it runs
  • Increment tells the relevant digits to increment
  • now units 0, tens 10, hundreds 0,

public void increment() units.increment() if
(units.getValue() 10) units.makeZero() tens.i
ncrement() if (tens.getValue()
10) tens.makeZero() hundreds.increment() if
(hundreds.getValue() 10) makeZero()
22
What happens when it runs
  • Increment tells the relevant digits to increment
  • now units 0, tens 10, hundreds 0,

public void increment() units.increment() if
(units.getValue() 10) units.makeZero() tens.i
ncrement() if (tens.getValue()
10) tens.makeZero() hundreds.increment() if
(hundreds.getValue() 10) makeZero()
23
What happens when it runs
  • Increment tells the relevant digits to increment
  • now units 0, tens 0, hundreds 0,

public void increment() units.increment() if
(units.getValue() 10) units.makeZero() tens.i
ncrement() if (tens.getValue()
10) tens.makeZero() hundreds.increment() if
(hundreds.getValue() 10) makeZero()
24
What happens when it runs
  • Increment tells the relevant digits to increment
  • now units 0, tens 0, hundreds 1,

public void increment() units.increment() if
(units.getValue() 10) units.makeZero() tens.i
ncrement() if (tens.getValue()
10) tens.makeZero() hundreds.increment() if
(hundreds.getValue() 10) makeZero()
25
What happens when it runs
  • Increment tells the relevant digits to increment
  • now units 0, tens 0, hundreds 1
  • Now finished with increment and rightAction
  • Waiting for next click
Write a Comment
User Comments (0)
About PowerShow.com