Account class publicMethods: -------------------------- example2 "Sample code for Section 8.5 Test by executing: Account example2 inspect " |transaction account| account := Account newBalance: 2500. transaction := Transaction newAmount: -300 date: Date today. account handleTransaction: transaction. transaction := Transaction newAmount: 625 date: (Date newDay: 20 month: #Jan year: 1995). account handleTransaction: transaction. transaction := Transaction newAmount: -50 date: (Date newDay: 5 month: #Mar year: 2002). account handleTransaction: transaction. "account inspect." ^account Account publicMethods: --------------------- balanceAsString "Sample code for Section 12.5 or 12.7. This conversion may alternatively be done in class AccountWindow" ^balance printString handleTransaction: aTrans "Sample code for Section 8.4" balance := balance + aTrans getAmount. log add: aTrans. logAsStrings "Sample code for Section 12.6 or 12.7. This conversion may alternatively be done in class AccountWindow" ^log asArray collect: [:trans | trans asString]. transactionAmount: anInteger date: aDate "Sample code for Section 8.7" self handleTransaction: (Transaction newAmount: anInteger date: aDate). Account privateMethods: ----------------------- initialBalance: anInteger "Sample code for section 8.4. This method should definitely be private (Section 8.8)" log := SortedCollection new. balance := anInteger Transaction class publicMethods: ------------------------------ newAmount: anInteger date: aDate "Sample code for Section 8.3" ^super new initialAmount: anInteger date: aDate Transaction publicMethods: ------------------------- <= anotherTransaction "Sample code for Section 8.4" ^self getDate <= anotherTransaction getDate asString "Sample code for Section 12.6" ^ date printString, ' ', amount printString getAmount "Sample code for Section 8.4" ^amount getDate "Sample code for Section 8.4" ^date Transaction privateMethods: -------------------------- initialAmount: anInteger date: aDate "Sample code for Section 8.4. This method should definitely be private (Section 8.8)" amount := anInteger. date := aDate. AccountWindow class publicMethods: ---------------------------------- example2 "Sample code for Section 12.5, 12.6, or 12.7 Test by executing: AccountWindow example2 " ^AccountWindow new openOn: Account example2. AccountWindow publicMethods: ----------------------------- openOn: anAccount "Sample code for Section 12.5, 12.6, or 12.7" account := anAccount. self open. AccountWindow privateMethods: ------------------------------ balance "Sample code for Section 12.5 or 12.7" ^account balanceAsString createWorkRegion "Sample code for Section 12.7. This code includes the code for Sections 12.5 or 12.6" | textWidget listWidget| textWidget := workRegion createText: 'My balance widget' argBlock: [:w | w editMode: XmMULTILINEEDIT; value: (self perform: #balance); leftAttachment: XmATTACHFORM; rightAttachment: XmATTACHFORM; topAttachment: XmATTACHFORM; bottomAttachment: XmATTACHPOSITION; bottomPosition: 10 "percent"]. textWidget manageChild. listWidget := workRegion createList: 'My log widget' argBlock: [:w | w items: (self perform: #listItems); leftAttachment: XmATTACHFORM; rightAttachment: XmATTACHFORM; topAttachment: XmATTACHWIDGET; topWidget: textWidget; bottomAttachment: XmATTACHFORM]. listWidget manageChild. listItems "Sample code for Section 12.6 or 12.7" ^account logAsStrings DoodleWindow class publicMethods: --------------------------------- example "Sample code for Section 12.11 Test by executing: DoodleWindow example " ^DoodleWindow new open DoodleWindow privateMethods: ----------------------------- buttonMotion: event "Sample code for Section 12.11" "A ButtonMotion event has occured in the DrawingArea." drawable drawLine: gc x1: oldX y1: oldY x2: event x y2: event y. oldX := event x. oldY := event y. buttonPress: event "Sample code for Section 12.11" "A ButtonPress event has occured in the DrawingArea." oldX := event x. oldY := event y.