Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using Gtk;
- public long fibonacci (int n)
- {
- if (n < 2) {
- return n;
- } else {
- return (fibonacci(n - 1) + fibonacci(n - 2));
- }
- }
- public static int main (string[] args)
- {
- Gtk.init (ref args);
- var window = new Window ();
- window.title = "Fibonacci GTK+";
- window.set_border_width (12);
- window.set_default_size (70, 70);
- window.set_position (Gtk.WindowPosition.CENTER);
- window.destroy.connect (Gtk.main_quit);
- var loop = new MainLoop();
- long result = 0;
- var headerbar = new HeaderBar ();
- var entry = new Entry ();
- var button = new Button.with_label ("Calcular");
- var label = new Label ("Resultado");
- var box = new Box (Orientation.VERTICAL, 0);
- headerbar.title = "Fibonacci GTK+";
- headerbar.show_close_button = true;
- box.pack_start (entry, false, true, 0);
- box.pack_start (label, false, true, 12);
- box.pack_start (button, false, true, 0);
- window.set_titlebar (headerbar);
- window.add (box);
- window.show_all ();
- /*** LOGICA ***/
- button.clicked.connect ( ()=> {
- result = fibonacci (int.parse (entry.get_text ()));
- label.set_label (result.to_string ());
- loop.quit();
- });
- loop.run ();
- Gtk.main ();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement