Membuat Aplikasi Jam Analog - Visual Basic 6.0

Selasa, 19 Juni 2012


Kali ini kita akan membahas cara membuat 'Jam Analog' yang dibuat dengan menggunan Microsoft Visual Basic 6.0. Langsung saja, pertama kali yang harus anda lakukan adalah membuka aplikasi 'Microsoft Visual Basic 6.0'. Pastikan Visual Basic telah terinstal di komputer anda. Atau bila anda ingin yang lebih mudah, download Visual Basic 6.0 versi Portable. (cari di google dengan menggunakan kata kunci 'Visual Basic 6.0 portable', tanpa tanda kutip).

Langkah  - langkah pembuatan jam analog adalah sebagai berikut :
1. Ubah Properti 'Name' Form1 menjadi 'frmMain', BackColor = black, BorderStyle = 0, DrawWidth = 3, ForeColor = White, Height = 3075,MaxButton = False, MinButton = False, StartUpPosition = 2, Width = 2625.

2. Kemuadian gambar 3 buah jarum jam dengan menggunakan Line Tool (Detik, Menit, Jam) dengan catatan, ketiga line tersebut berada mempunyai titik pusat yang sma. Ganti Properti 'Name'nya menjadi (Linehour,lineMinute,lineSecond)

3. Buat sebuah Label di bawah ketiga jarum jam tadi, ganti Properti 'Name'nya menjadi Lbltime

4. Masukkan sebuah objek 'Timer',ganti Properti 'Name'nya menjadi tmrClock dan atur Properti 'Intervalnya' = 1

5. Setelah semua objek telah dimasukkan di Design View, lalu klik menu 'View + Code'
kemudian copy paste kode di bawah ini.
Source kode untuk aplikasi Jam Analog :

Option Explicit

Private Const pi As Double = 3.14159265358979

Private Declare Function CreateRoundRectRgn Lib "gdi32" (ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long, ByVal X3 As Long, ByVal Y3 As Long) As Long
Private Declare Function ReleaseCapture Lib "user32" () As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Declare Function SetWindowRgn Lib "user32" (ByVal hWnd As Long, ByVal hRgn As Long, ByVal bRedraw As Boolean) As Long


Private Sub MakeRoundObject(objObject As Object, Value As Long)
Static lngHeight, lngLong, lngReturn, lngWidth As Long

lngWidth = objObject.Width / Screen.TwipsPerPixelX
lngHeight = objObject.Height / Screen.TwipsPerPixelY

SetWindowRgn objObject.hWnd, CreateRoundRectRgn(0, 0, lngWidth, lngHeight, Value, Value), True
End Sub

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyEscape Then
App.TaskVisible = False
Unload Me
End
End If
End Sub

Private Sub Form_Load()
Dim intX As Integer

Call MakeRoundObject(frmMain, 20)
Call tmrClock_Timer

For intX = 0 To 360 Step 6
If intX Mod 30 = 0 Then
Me.DrawWidth = 6
Me.PSet (1100 * Cos(intX * pi / 180) + lineSecond.X1, 1100 * Sin(intX * pi / 180) + lineSecond.Y1)
Else
Me.DrawWidth = 3
Me.PSet (1100 * Cos(intX * pi / 180) + lineSecond.X1, 1100 * Sin(intX * pi / 180) + lineSecond.Y1)
End If
Next intX
End Sub

Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
ReleaseCapture
SendMessage Me.hWnd, &HA1, 2, 0&
End Sub

Private Sub lblTime_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Call Form_MouseDown(Button, Shift, X, Y)
End Sub

Private Sub tmrClock_Timer()
Dim dblSecond As Double, dblMinute As Double, dblHour As Double

dblSecond = Second(Now) * 6 - 90
dblMinute = (Minute(Now) + Second(Now) / 60) * 6 - 90
dblHour = (Hour(Now) + Minute(Now) / 60) * 30 - 90

lineSecond.X2 = 1000 * Cos(dblSecond * pi / 180) + lineSecond.X1
lineSecond.Y2 = 1000 * Sin(dblSecond * pi / 180) + lineSecond.Y1
lineMinute.X2 = 900 * Cos(dblMinute * pi / 180) + lineMinute.X1
lineMinute.Y2 = 900 * Sin(dblMinute * pi / 180) + lineMinute.Y1
lineHour.X2 = 700 * Cos(dblHour * pi / 180) + lineHour.X1
lineHour.Y2 = 700 * Sin(dblHour * pi / 180) + lineHour.Y1

lblTime.Caption = Format(Now, "hh:mm:ss")
End Sub

Setelah selesai, ketika anda klik tombol 'Start', maka akan muncul hasil dari 'Aplikasi Jam Analog' kira - kira seperti ini :
Description: Jam Analog - Trik Komputer

Selamat Mencoba... :)

1 komentar:

Unknown mengatakan...

salah kali mba code-nya... hahaha... yang betul di bawah ini :

------------------------------------------------

( Code )

Dim dblSecond As Double, dblMinute As Double, dblHour As Double

dblSecond = Second(Now) * 6 - 90
dblMinute = (Minute(Now) + Second(Now) / 60) * 6 - 90
dblHour = (Hour(Now) + Minute(Now) / 60) * 30 - 90

LineSecond.X2 = 1000 * Cos(dblSecond * pi / 180) + LineSecond.X1
LineSecond.Y2 = 1000 * Sin(dblSecond * pi / 180) + LineSecond.Y1
LineMinute.X2 = 900 * Cos(dblMinute * pi / 180) + LineMinute.X1
LineMinute.Y2 = 900 * Sin(dblMinute * pi / 180) + LineMinute.Y1
LineHour.X2 = 700 * Cos(dblHour * pi / 180) + LineHour.X1
LineHour.Y2 = 700 * Sin(dblHour * pi / 180) + LineHour.Y1

LblTime.Caption = Format(Now, "hh:mm:ss")

------------------------------------------------

tapi yang untuk timer-nya, kata-nya sekolah-nya di ( Universitas Muria Kudus ) masak gak bisa jadi di ViBa ( Visual Basic ) 6.0 PE ( Professional Edition ) saya, belum di coba ya... gak jadi sih, hahaha...

Posting Komentar