• Nie Znaleziono Wyników

Class1.vb Budujemy klas

N/A
N/A
Protected

Academic year: 2021

Share "Class1.vb Budujemy klas"

Copied!
3
0
0

Pełen tekst

(1)

vb_MiPO_2017_z1

Copyright ©2017, mgr inż. Jacek Jusis, mgr inż. Łukasz Woźnicki, mgr inż.Janusz Bonarowski

1 Class1.vb

Budujemy klasę Stopien_walu.

Klasa ta pozwoli tworzyć kolejne instancje pojedynczego, niezależnego stopnia przechowując jego parametry – czyli jego średnicę i długość

Tryby pracy będziemy określać poprzez zmienną wyliczeniową TrybPracy Public Class Stopien_walu

Private _Srednica_stopnia As Single Private _Dlugosc_stopnia As Single

Public Property Srednica_stopnia As Single Get

Return _Srednica_stopnia End Get

Set(value As Single)

_Srednica_stopnia = value End Set

End Property

Public Property Dlugosc_stopnia As Single Get

Return _Dlugosc_stopnia End Get

Set(value As Single)

_Dlugosc_stopnia = value End Set

End Property End Class

Public Enum TrybPracy NicNieRob

NowyStopien End Enum

Wał będzie się składał z wielu stopni. Parametry stopnia i kolejność stopni musi być zapamiętywana. Możemy to rozwiązać w różny sposób:

Umieszczając kolejne stopnie (1) w tabeli, (2) w obiekcie Collection lub (3) w obiekcie Lista. Ze względu na wygodę obsługi,

do przechowania kolejnych stopni wału posłużymy się obiektem Lista.

Form1.vb

Public Class Form1

Dim objRys As System.Drawing.Graphics

Dim objPioroWal As New System.Drawing.Pen(Color.Red, 2) Dim objPioroOs As New System.Drawing.Pen(Color.Green) Dim X_osi As Integer = 50

Dim Y_osi As Integer = 200 Dim x_pocz As Integer = X_osi Dim mode As TrybPracy

Dim Kolekcja_stopni_walu As New List(Of Stopien_walu)

Private Sub Form1_MouseMove(sender As Object, e As MouseEventArgs) Handles MyBase.MouseMove LabelKoordynaty.Text = "X=" & e.X & " Y=" & e.Y

End Sub

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load objRys = Me.CreateGraphics

mode = TrybPracy.NicNieRob End Sub

Private Sub Form1_Paint(sender As Object, e As PaintEventArgs) Handles MyBase.Paint Call RysujOsie()

End Sub

(2)

vb_MiPO_2017_z1

Copyright ©2017, mgr inż. Jacek Jusis, mgr inż. Łukasz Woźnicki, mgr inż.Janusz Bonarowski

2

Private Sub RysujOsie()

objRys.DrawLine(objPioroOs, X_osi, 50, X_osi, 350) objRys.DrawLine(objPioroOs, X_osi, Y_osi, 700, Y_osi) End Sub

Private Sub Form1_MouseClick(sender As Object, e As MouseEventArgs) Handles MyBase.MouseClick 'objRys.DrawLine(Pens.Blue, 150, 100, 220, 150)

'objRys.DrawRectangle(Pens.Blue, 150, 100, 80, 150) 'objRys.DrawArc(Pens.Blue, 350, 150, 100, 100, 0, 150) 'objRys.DrawEllipse(Pens.Blue, 250, 150, 50, 80) 'objRys.DrawLine(objPioroOs, X_osi, 50, X_osi, 350) 'objRys.DrawLine(objPioroOs, X_osi, Y_osi, 700, Y_osi) Dim x1 As Single

Dim y1 As Single

Dim mojStopien As Stopien_walu 'Dim mojStopien As New Stopien_walu x1 = e.X

y1 = e.Y

If mode = TrybPracy.NowyStopien Then mojStopien = New Stopien_walu

mojStopien.Dlugosc_stopnia = x1 - x_pocz mojStopien.Srednica_stopnia = (Y_osi - y1) * 2

objRys.DrawRectangle(objPioroWal, x_pocz, y1, x1 - x_pocz, (Y_osi - y1) * 2) 'x_pocz = x1

x_pocz = x_pocz + mojStopien.Dlugosc_stopnia Kolekcja_stopni_walu.Add(mojStopien)

End If End Sub

Private Sub NowyWałekToolStripMenuItem_Click(sender As Object, e As EventArgs) _

Handles NowyWałekToolStripMenuItem.Click mode = TrybPracy.NicNieRob

x_pocz = X_osi

Kolekcja_stopni_walu.Clear() objRys.Clear(SystemColors.Control) Call RysujOsie()

End Sub

Private Sub StopnieBezFazyToolStripMenuItem_Click(sender As Object, e As EventArgs) _ Handles StopnieBezFazyToolStripMenuItem.Click mode = TrybPracy.NowyStopien

End Sub

Private Sub NicNieRóbToolStripMenuItem_Click(sender As Object, e As EventArgs) _

Handles NicNieRóbToolStripMenuItem.Click mode = TrybPracy.NicNieRob

End Sub

Private Sub SkasujToolStripMenuItem_Click(sender As Object, e As EventArgs) _

Handles SkasujToolStripMenuItem.Click objRys.Clear(SystemColors.Control)

Call RysujOsie() End Sub

Private Sub PokażToolStripMenuItem_Click(sender As Object, e As EventArgs) _

Handles PokażToolStripMenuItem.Click Call Narysuj()

End Sub

Private Sub Narysuj()

Dim wsk_kolekcji As Stopien_walu x_pocz = X_osi

For Each wsk_kolekcji In Kolekcja_stopni_walu

objRys.DrawRectangle(objPioroWal, x_pocz, Y_osi - wsk_kolekcji.Srednica_stopnia / 2, wsk_kolekcji.Dlugosc_stopnia, wsk_kolekcji.Srednica_stopnia) x_pocz = x_pocz + wsk_kolekcji.Dlugosc_stopnia

Next End Sub End Class

(3)

vb_MiPO_2017_z1

Copyright ©2017, mgr inż. Jacek Jusis, mgr inż. Łukasz Woźnicki, mgr inż.Janusz Bonarowski

3 Wywołanie diagramu UML

Diagram UML możemy wywołać klikając, w oknie Solution Explorer, prawym klawiszem myszy na pliku Class1.vb, rys. 1 i z kontekstowego menu wybierając View Class Diagram.

Rysunek 1. Wywołanie diagramu UML

Rysunek 2. Diagram UML

Cytaty

Powiązane dokumenty

W przypadku, gdy chcemy zapisać nasz program należy użyć polecenia menu ‘File/Save All’ po czym podać nazwę pliku zawierającego kod programu (.cpp) oraz

Private Sub CzytajKolekcjęToolStripMenuItem_Click(sender As Object, e As EventArgs) _ Handles CzytajKolekcjęToolStripMenuItem.Click 'Odczyt kolekcji z wielu

An order for computer with software is realized in the company SPRINT as follows: In case of new customers the sales department requires making prepayment, while in other cases, it

Not returning the book in time makes the necessary to pay the penalty for each day of the retention copy, the penalty shall be calculated in time return the book.. If the

TransportMean IsTransportability(shipment) – is it possible to carry this shipment by this transport mean CityPlan Time(start, end, mean) – returns the time needed to reach the goal

Workstations (in the number 15) are connected to the server (Xeon 3400, 8GB RAM) through a local area network (Ethernet), while the readings of counters are transferred from portable

• abstrakcyjna klasa (abstract class) (nazwa klasy napisana kursywą) – klasa nie może mieć bezpośredniego egzemplarza. • elementy statyczne (static elements) – atrybuty

Atrybut lub operacja jest widoczna tylko dla innych elementów tej