BAHASA PEMOGRAMAN
RUBY
dengan SHOES
TEKNIK INFORMATIKA
UNIVERSITAS NASIONAL
1.Animasi Tombol
Animasi tombol, buat kode seperti dibawah ini lalu simpan dengan
ekstensi .rb
Shoes.app do
flow :margin => 12 do
# Set up three buttons
button "One"
@two = button "Two"
button "Three"
# Bounce the second button
animate do |i|
@two.displace(0, (Math.sin(i) * 6).to_i)
end
end
end
buat kode seperti dibawah ini lalu simpan dengan ekstensi .rb
Shoes.app do
flow :margin => 12 do
# Set up three buttons
button "One"
@two = button "Two"
button "Three"
# Bounce the second button
animate do |i|
@two.move(40, 40 + (Math.sin(i) * 6).to_i)
end
end
end
2.Style Tombol
Style pada Tombol, buat kode seperti dibawah ini lalu simpan
dengan ekstensi .rb
Shoes.app do
# A button which take up the whole page
@b = button "All of it", :width => 1.0, :height => 1.0
# When clicked, show the styles
@b.click { alert(@b.style.inspect) }
End
Style pada Tombol, buat kode seperti dibawah ini lalu simpan
dengan ekstensi .rb
Shoes.app do
stack :width => 120 do
@b = button "Click me", :width => "100%" do
alert "button.width = #{@b.width}\n" +
"button.style[:width] = #{@b.style[:width]}"
end
end
end
Style pada Tombol, buat kode seperti dibawah ini lalu simpan
dengan ekstensi .rb
Shoes.app do
stack :width => 120 do
@b = button "Click me", :width => "100%" do
alert "button.width = #{@b.width}\n" +
"button.style[:width] = #{@b.style[:width]}"
end
@c = button "Click me", :width => "100%" do
alert "button.width = #{@b.width}\n" +
"button.style[:width] = #{@b.style[:width]}"
end
end
end
3.Tombol
Membuat Tombol sederhana, buat kode seperti dibawah ini lalu
simpan dengan ekstensi .rb
Shoes.app do
button "OK!"
button "Are you sure?"
end
Shoes.app do
button "OK!" do
append { para "Well okay then." }
end
button "Are you sure?" do
append { para "Your confidence is inspiring." }
end
end
Shoes.app do
@b1 = button "OK!"
@b1.click { para "Well okay then." }
@b2 = button "Are you sure?"
@b2.click { para "Your confidence is inspiring." }
End
4.CheckBox
Shoes.app do
stack do
flow { check; para "Teknik Informatika" }
flow { check; para "Sistem Informasi" }
flow { check; para "Telekomunikasi" }
flow { check; para "Manajemen Informatika" }
end
end
Shoes.app do
@list = ['Teknik Informatika', 'Sistem Informasi',
'Telekomunikasi', 'Manajemen Informatika']
stack do
@list.map! do |name|
flow { @c = check; para name }
[@c, name]
end
button "What's been checked?" do
selected = @list.map { |c, name| name if
c.checked? }.compact
alert("You selected: " + selected.join(', '))
end
end
end
5.EditBox
Shoes.app do
edit_box
edit_box :width => 100, :height => 100
end
Shoes.app do
edit_box do |e|
@counter.text = e.text.size
end
@counter = strong("0")
para @counter, " characters"
end
6.EditLine
Shoes.app do
para "Choose a fruit:"
list_box :items => ["Grapes", "Pears", "Apricots"]
end
Shoes.app do
para "Choose a fruit:"
list_box :items => ["Grapes", "Pears", "Apricots"],
:width => 120, :choose => "Apricots" do |list|
@fruit.text = list.text
end
@fruit = para "No fruit selected"
End
8.Progress
Shoes.app do
para "Among these films, which do you prefer?\n"
radio; para strong("The Taste of Tea"), " by Katsuhito Ishii\n"
Shoes.app do
stack do
para "Among these films, which do you prefer?"
flow do
radio :films
para "The Taste of Tea by Katsuhito Ishii"
end
flow do
radio :films
para "Ketika Cinta Bertasbih by Habiburrahman al syirazi"
end
flow do
radio :films
para "Laskar Pelangi by Andrea Hirata"
end
end
end