Recent comments


Syndicate


Follow Me

Twitter Facebook

Hello FXRuby

To illustrate how simple, clean and fun FXRuby is, Here's a sample Hello World:

require 'fox16'

include Fox

class HelloWindow < FXMainWindow
  
  def initialize(app)
    super(app, "Hello World!", :width => 200, :height => 100)
  end
  
  def create
    super
    show(PLACEMENT_SCREEN)
  end
  
end

if __FILE__ == $0
  FXApp.new do |app|
    HelloWindow.new(app)
    app.create
    app.run
  end
end

Now I know this is a bit overkill for a simple hello world but it actually looks elegant to me. What this does is it extends FXMainWindow widget and customize the create method by showing the form and centering it on the screen right after it is created.

The condition at the bottom checks if the file is being run as standalone. If it is, we pass a code block that creates a new instance of our class and away we go.

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

More information about formatting options

By submitting this form, you accept the Mollom privacy policy.