![]()
![]()
COMP2100
Lab 6: Graphical User Interfaces IISummary
You will add a date feature to the eClock application.
Aims
Build on your knowledge of GUI programming with EXG.
Develop your ability to find information in the EXG and GTK documentation.
Exercise 1. Getting the source code
Download the compressed archive file eclock.tar.gz and unpack it into a new directory. This contains the source code for the basic eClock, together with a Makefile an Ace file, and a gtk_cecil. Compile it (by typing ``make'' and run it.
Take a few minutes to browse through the classes: there are only three, totalling just under 250 lines of code. We already worked through a lot of this in Lecture 16.
Exercise 2. A date function
If you examine the short form of class EXG_TIME you will see that it has queries for the day of the week, the day of the month, the month and the year, all integers. But it doesn't have a convenient way of extracting the date as a string. Your task is to fix that by writing a new class SMART_TIME which inherits from EXG_TIME and just adds one new feature, a query date which returns a string giving the full date, in the format
Friday 12 April 2002This class doesn't need any creation clause or creation routine, just that one new query. You may add other hidden features if you want, to help with the implementation of date. I think you might find it useful to have a couple of arrays of strings containing the names of the days of the week and the months of the year. You can do these using ``once'' functions.
As a matter of policy, the date function should not call read_time, because that would change the state of the object. It's up to the client to call read_time, and then the queries should all return information about the time that read_time was last called.
Test your new class with the test program provided. It's called "test_time". The Eiffel code is in test_time.e and I've provided you with a ready-made Ace file test_time.ace and a section in the Makefile. Once you've written class SMART_TIME, you should be able to compile the test program by simply typing make test_time.
Don't continue to Exercise 3 until you have this working.
Exercise 3. Adding a date display to the eClock
Now modify class VIEW in the eClock program so that it puts a label displaying the date at the bottom of the window, below the clock face. Whenever the display is updated, it should refresh this (just in case it was midnight and the date changed).
You will need to use a GTK_VBOX and stack the widgets vertically. Play with the spacing and sizing until it looks right to you.
*Exercise 4. Turn it into an alarm clock
You will need a dialog box for setting the alarm. You will need a menu with an item for turning the alarm on and off and another for setting it. You will need to display the status in some way: perhaps a coloured hand or another label above the date, or some other visual cue. You will need a popup message box and maybe an audible beep for when the alarm goes off. There are quite a few issues to think about here.
(In 2000, Assignment 2 was to build the whole alarm clock from scratch, so this is just the last part of that, but instead of specifying the behaviour, I'm letting you do the design.)
![]()
![]()
Copyright © 2004, Ian Barnes, The Australian National University
Feedback & Queries to
comp2100@iwaki.anu.edu.au
Version 2004.1, 5 April 2004, 17:13:07