当前位置: 首页 > 工具软件 > fxruby > 使用案例 >

FXRuby代码笔记---一个基础的app

席乐童
2023-12-01

ClipMainWindow.rb

require 'fox16'
require 'customer'

include Fox

class ClipMainWindow < FXMainWindow
  def initialize(anApp)
    # Initialize base class first
    super(anApp, "Clipboard Example", :opts => DECOR_ALL, :width => 400, :height => 300)

    # Place the list in a sunken frame
    sunkenFrame = FXVerticalFrame.new(self,
			LAYOUT_FILL_X|LAYOUT_FILL_Y|FRAME_SUNKEN|FRAME_THICK, :padding => 0)
    #FXVerticalFrame是用来给其子窗口做布局提示用的,自上而下布局,或者自下而上布局

	
    # Customer list
    customerList = FXList.new(sunkenFrame, :opts => LIST_BROWSESELECT|LAYOUT_FILL_X|LAYOUT_FILL_Y)
    #FXList列表,每个选项包含一个用可选择的文字描述,
    #当状态改变会产生SEL_SELECTED或者SEL_DESELECTED两个事件。 
    $customers.each do |customer|
      customerList.appendItem(customer.name, nil, customer)
    end
  end
  
  def create
    super
    show(PLACEMENT_SCREEN)
  end
end

if __FILE__ == $0
#当前运行的文件和当前文件是一致及本文件不是作为其他文件的库文件使用时候执行以下代码
  FXApp.new("ClipboardExample", "FXRuby") do |theApp|
    ClipMainWindow.new(theApp)
    theApp.create
    theApp.run
  end
end

 

customer.rb

# customer.rb

Customer = Struct.new("Customer", :name, :address, :zip)
#Struct可以理解为C中struct 第一个参数是结构名,后面为字段名
$customers = []
$customers << Customer.new("Reed Richards", "123 Maple, Central City, NY", 010111)
$customers << Customer.new("Sue Storm", "123 Maple, Anytown, NC", 12345)
$customers << Customer.new("Benjamin J. Grimm", "123 Maple, Anytown, NC", 12345)
$customers << Customer.new("Johnny Storm", "123 Maple, Anytown, NC", 12345)
 
 类似资料: