tutorial ruby bagian 4

Upload: slametz-pembuka

Post on 09-Apr-2018

226 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/7/2019 Tutorial Ruby Bagian 4

    1/9

    TUTORIAL RUBY DENGAN GUI SHOES

    Oleh: SLAMET NURHADI

    TEKNIK INFORMATIKA

    UNIVERSITAS NASIONAL

  • 8/7/2019 Tutorial Ruby Bagian 4

    2/9

    Image

    Shoes.app :title =>"Sample calc", :resizable =>false, :width => 460, :height => 520 do

    image 'd:/ruby.png'end

    Simple calc

    Shoes.app :title =>"Sample calc", :resizable =>false, :height => 250, :width => 200, :resizable =>false do

    def do_calc@number = @previous.send(@op, @number) if @op@op = nilend

    @previous, @number, @op = 0, 0, nil

    background "#33ffff".."#333399", :curve => 5, :margin=> 2

    stack :margin => 2 dostack :margin => 8 do

  • 8/7/2019 Tutorial Ruby Bagian 4

    3/9

    @number_field = para strong(@number)end

    flow :width => 218, :margin => 4 do

    %w(7 8 9 / 4 5 6 * 1 2 3 - 0 Clr = +).each do |btn|button btn, :width => 46, :height => 46 docase btnwhen /[0-9]/@number = @number.to_i * 10 + btn.to_i

    when 'Clr'@previous, @number, @op = 0, 0, nil

    when '='do_calc

    elsedo_calc@previous, @number = @number, nil@op = btn

    end@number_field.replace strong @numberend

    endend

    endend

  • 8/7/2019 Tutorial Ruby Bagian 4

    4/9

    Shoes.app :title =>"editbox", :resizable => false,:width => 250, :height => 300 do

    background "#666666".."#000000"

    stack do@msg = para 'Hello', :stroke =>white@el = edit_line "We love Ruby."button('ok'){ @msg.text = @el.text}@eb = edit_box "We love Shoes."button('ok'){ @msg.text = @eb.text}

    end

    end

    Shoes.app :title =>"listbox", :resizable => false,:width => 450, :height => 60 do

    background "#666666".."#000000"para "Pilih jurusan\n", :stroke =>whitebutton('OK'){@msg.text = @e.text}

  • 8/7/2019 Tutorial Ruby Bagian 4

    5/9

    @e = list_box :items => ['Teknik Informatika','Telekomunikasi', 'Sistem Informasi', 'ManajemenInformatika'], :height => 30

    @msg = para '', :stroke =>white

    End

    Shoes.app :title =>"animasi", :resizable => false,:width => 300, :height => 300 do

    background "#666666".."#000000"

    def swap s1, s2tmp = s2.style.to_as1.style.to_a.each{|k, v| s2.style k => v}tmp.each{|k, v| s1.style k => v}

    end

    nostroker1 = rect 50, 50, 100, 100, :fill => mediumslatebluer2 = rect 100, 100, 100, 100, :fill => sandybrownr3 = rect 150, 150, 100, 100, :fill => orchid

    button('swap 1-2'){swap r1, r2}

    button('swap 2-3'){swap r2, r3}button('swap 1-3'){swap r1, r3}

    end

  • 8/7/2019 Tutorial Ruby Bagian 4

    6/9

    Shoes.app :width => 240, :height => 161, :resizable =>false do

    background "#666666".."#000000"flow :width => 100, :height => 150, :left => 2, :top

    => 2, :scroll => true dobackground bisque

    30.times do |i|color = COLORS.keys.map{|sym|sym.to_s}.sort_by{rand}

    para "colorful jellybeans", :stroke =>send(color.first)

    endend

    end

  • 8/7/2019 Tutorial Ruby Bagian 4

    7/9

    filename =ask_open_fileShoes.app :title => "Open ", :width =>300, :height => 70

    dopara File.read(filename)

    end

  • 8/7/2019 Tutorial Ruby Bagian 4

    8/9

    Shoes.app :title => "Open ", :width =>300, :height => 70dobutton "Open File" do

    filename =ask_open_filepara File.read(filename)endend

    Shoes.app :title => "Open ", :width =>300, :height => 70dobackground "#666666".."#000000"

    button "Open Folder" dofilename =ask_open_folderpara File.read(folder)endend

  • 8/7/2019 Tutorial Ruby Bagian 4

    9/9

    Shoes.app :title => "Save ", :width =>300, :height => 70dobackground "#FFCC00".."#000000"

    button "save Folder" dofilename =ask_save_folderpara File.read(folder)

    endend