Imports System
Public Class MainClass
Shared Sub Main()
Dim win As New Window(1, 2)
Dim lb As New ListBox(3, 4, "Stand alone list box")
Dim b As New Button(5, 6)
win.DrawWindow( )
lb.DrawWindow( )
b.DrawWindow( )
Dim winArray(3) As Window
winArray(0) = New Window(1, 2)
winArray(1) = New ListBox(3, 4, "List box in array")
winArray(2) = New Button(5, 6)
Dim i As Integer
For i = 0 To 2
winArray(i).DrawWindow( )
Next i
End Sub
End Class
Public Class Window
Public Sub New(ByVal top As Integer, ByVal left As Integer)
Me.top = top
Me.left = left
End Sub
Public Overridable Sub DrawWindow( )
Console.WriteLine("Window: drawing Window at {0}, {1}", top, left)
End Sub
Protected top As Integer
Protected left As Integer
End Class
Public Class ListBox
Inherits Window
Public Sub New(ByVal top As Integer, ByVal left As Integer, ByVal contents As String)
MyBase.New(top, left)
listBoxContents = contents
End Sub
Public Overrides Sub DrawWindow( )
MyBase.DrawWindow( )
Console.WriteLine("Writing string to the listbox: {0}", listBoxContents)
End Sub
Private listBoxContents As String ' new member variable
End Class 'ListBox
Public Class Button
Inherits Window
Public Sub New(ByVal top As Integer, ByVal left As Integer)
MyBase.New(top, left)
End Sub
Public Overrides Sub DrawWindow( )
Console.WriteLine( _
"Drawing a button at {0}, {1}" + ControlChars.Lf, top, Left)
End Sub 'DrawWindow
End Class 'Button
|