| Java |
| import javax.swing.*; import java.awt.*; import java.awt.event.*; import java.util.*; public class AnimasiTombol extends JFrame implements ActionListener { JButton jbLight1 = new JButton(); JButton jbLight2 = new JButton(); JButton jbLight3 = new JButton(); JButton jbLight4 = new JButton(); JButton jbLight5 = new JButton(); JButton jbLight6 = new JButton(); JButton jbLight7 = new JButton(); JButton jbLight8 = new JButton(); JButton jbLight9 = new JButton(); JButton jbLight10 = new JButton(); JButton jbRight = new JButton(" GRK KE KANAN > "); JButton jbLeft = new JButton(" < GRK KE KIRI "); JButton stop = new JButton("STOP"); JButton keluar = new JButton("KELUAR"); javax.swing.Timer timer = new javax.swing.Timer(1000, this); int jbNo = 1; int status=0; public AnimasiTombol() { setLayout(null); setComponents(); setTitle("WARNA BERJALAN"); setSize(610, 120); setVisible(true); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setResizable(false); setLocationRelativeTo(null); } public void setComponents() { jbLight1.setBounds(10, 20, 50, 20); jbLight2.setBounds(70, 20, 50, 20); jbLight3.setBounds(130, 20, 50, 20); jbLight4.setBounds(190, 20, 50, 20); jbLight5.setBounds(250, 20, 50, 20); jbLight6.setBounds(310, 20, 50, 20); jbLight7.setBounds(370, 20, 50, 20); jbLight8.setBounds(430, 20, 50, 20); jbLight9.setBounds(490, 20, 50, 20); jbLight10.setBounds(550, 20, 50, 20); jbLight1.setBackground(Color.green); jbLight2.setBackground(Color.black); jbLight3.setBackground(Color.black); jbLight4.setBackground(Color.black); jbLight5.setBackground(Color.black); jbLight6.setBackground(Color.black); jbLight7.setBackground(Color.black); jbLight8.setBackground(Color.black); jbLight9.setBackground(Color.black); jbLight10.setBackground(Color.black); jbLeft.setBounds(10, 50, 125, 20); jbRight.setBounds(150, 50, 140, 20); stop.setBounds(400, 50, 80, 20); keluar.setBounds(500, 50, 80, 20); add(jbLight1); add(jbLight2); add(jbLight3); add(jbLight4); add(jbLight5); add(jbLight6); add(jbLight7); add(jbLight8); add(jbLight9); add(jbLight10); add(jbRight); add(jbLeft); add(stop); add(keluar); jbRight.addActionListener(this); jbLeft.addActionListener(this); stop.addActionListener(this); keluar.addActionListener(this); } public void setButtonLight() { jbLight1.setBackground(Color.black); jbLight2.setBackground(Color.black); jbLight3.setBackground(Color.black); jbLight4.setBackground(Color.black); jbLight5.setBackground(Color.black); jbLight6.setBackground(Color.black); jbLight7.setBackground(Color.black); jbLight8.setBackground(Color.black); jbLight9.setBackground(Color.black); jbLight10.setBackground(Color.black); switch ( jbNo ) { case 1: jbLight1.setBackground(Color.yellow); break; case 2: jbLight2.setBackground(Color.yellow); break; case 3: jbLight3.setBackground(Color.yellow); break; case 4: jbLight4.setBackground(Color.yellow); break; case 5: jbLight5.setBackground(Color.yellow); break; case 6: jbLight6.setBackground(Color.yellow); break; case 7: jbLight7.setBackground(Color.yellow); break; case 8: jbLight8.setBackground(Color.yellow); break; case 9: jbLight9.setBackground(Color.yellow); break; case 10: jbLight10.setBackground(Color.yellow); break; } } public void actionPerformed(ActionEvent ae) { if (ae.getSource()==jbLeft) { status=0; timer.start(); } else if (ae.getSource()==jbRight) { status=1; timer.start(); } else if (ae.getSource()==stop) { timer.stop(); } else if (ae.getSource()==keluar) { System.exit(0); } else if (ae.getSource()==timer) { if (status==0) { jbNo-=1; } else if (status==1) { jbNo+=1; } if (jbNo>10) { jbNo=1; } else if(jbNo==0) { jbNo=10; } setButtonLight(); } } public static void main(String[] args) { new AnimasiTombol(); } } |
Animasi tombol warna berjalan PDF Print E-mail Java
Sabtu, Juli 16, 2011 |
Label:
JAVA
0Comments
visual basic 6.0
Sabtu, Juli 16, 2011 |
Label:
visual basic 6.0
Membuat Fungsi Terbilang Dengan Visual Basic 6.0
Fungsi terbilang adalah fungsi yang melakukan konversi dari angka menjadi teks terbilangnya, misalnya 123,4567 menjadi seratus dua puluh tiga koma empat lima enam tujuh.
1.Buatlah sebuah project baru dengan template Standard.EXE.
2.Rancanglah sebuah form seperti terlihat pada gambar 1. Beberapa properti form tersebut harus diberi nilai sebagai berikut:
| Kontrol | Properti | Nilai |
| Form | Caption | Terbilang |
| TextBox1 | Name | txtAngka |
| TextBox2 | Name | txtTerbilang |
| | Multiline | True |
| CommandButton1 | Name | cmdTerbilang |
| | Caption | &Terbilang |
| CommandButton2 | Name | cmdExit |
| | Caption | E&xit |
Gambar.1
3. Kemudian tambahkan sebuah modul dengan cara klik kanan pada Project Explorer dan pada
menu yang muncul pilih Add > Module. Bandingkan dengan gambar 2.
Gambar.2
4. Pada module baru tersebut tambahkan kode program seperti disajikan pada listing 1.
5. Kemudian klik ganda tombol Terbilang dan tambahkan kode program seperti disajikan pada
listing 2.
6. Langkah terakhir, klik ganda tombol Exit dan tambahkan kode program seperti disajikan pada
listing 3.
7.Hasil eksekusi program tersebut ditampilkan pada gambar 3. Masukkan suatu angka pada
kotak teks Angka, klik tombol Terbilang, teks terbilang dari angka tersebut akan muncul pada
kotak teks Terbilang.
Gambar.3
LISTING PROGRAM:
Listing 1. Fungsi terbilang
Public Function Terbilang(x As Double) As String
Dim tampung As Double
Dim teks As String
Dim bagian As String
Dim i As Integer
Dim tanda As Boolean
Dim letak(5)
letak(1) = "ribu "
letak(2) = "juta "
letak(3) = "milyar "
letak(4) = "trilyun "
If (x = 0) Then
Terbilang = "nol"
Exit Function
End If
If (x < 2000) Then
tanda = True
End If
teks = ""
If (x >= 1E+15) Then
Terbilang = "Nilai terlalu besar"
Exit Function
End If
For i = 4 To 1 Step -1
tampung = Int(x / (10 ^ (3 * i)))
If (tampung > 0) Then
bagian = ratusan(tampung, tanda)
teks = teks & bagian & letak(i)
End If
x = x - tampung * (10 ^ (3 * i))
Next
teks = teks & ratusan(x, False)
Terbilang = teks
End Function
Function ratusan(ByVal y As Double, ByVal flag As Boolean) As String
Dim tmp As Double
Dim bilang As String
Dim bag As String
Dim j As Integer
Dim angka(9)
angka(1) = "se"
angka(2) = "dua "
angka(3) = "tiga "
angka(4) = "empat "
angka(5) = "lima "
angka(6) = "enam "
angka(7) = "tujuh "
angka(8) = "delapan "
angka(9) = "sembilan "
Dim posisi(2)
posisi(1) = "puluh "
posisi(2) = "ratus "
bilang = ""
For j = 2 To 1 Step -1
tmp = Int(y / (10 ^ j))
If (tmp > 0) Then
bag = angka(tmp)
If (j = 1 And tmp = 1) Then
y = y - tmp * 10 ^ j
If (y >= 1) Then
posisi(j) = "belas "
Else
angka(y) = "se"
End If
bilang = bilang & angka(y) & posisi(j)
ratusan = bilang
Exit Function
Else
bilang = bilang & bag & posisi(j)
End If
End If
y = y - tmp * 10 ^ j
Next
If (flag = False) Then
angka(1) = "satu "
End If
bilang = bilang & angka(y)
ratusan = bilang
End FunctionListing 2. Event click pada cmdTerbilang
Private Sub cmdTerbilang_Click()
Dim angka As Double
Dim teks As String
angka = Val(txtAngka.Text)
teks = Terbilang(angka)
txtTerbilang.Text = teks
End SubListing 3. Event click pada cmdExit
Private Sub cmdExit_Click()
End
End Sub
Langganan:
Postingan (Atom)






