const Application = new Lang.Class({
//A Class requires an explicit Name parameter. This is the Class Name.
Name: 'Application',
//create the application
_init: function() {
this.application = new Gtk.Application();
//connect to 'activate' and 'startup' signals to handlers.
this.application.connect('activate', Lang.bind(this, this._onActivate));
this.application.connect('startup', Lang.bind(this, this._onStartup));
},
//create the UI
_buildUI: function() {
this._window = new Gtk.ApplicationWindow({ application: this.application,
title: "Hello World!" });
},
//handler for 'activate' signal
_onActivate: function() {
//show the window and all child widgets
this._window.show_all();
},
//handler for 'startup' signal
_onStartup: function() {
this._buildUI();
}
});
GtkApplication은 GTK+를 초기화합니다. 또한 창을 만들 때 자동으로 붙인
첫 창 만들기로 시작하겠습니다. _window 변수를 만들고 Gtk.ApplicationWindow 새 객체를 할당하겠습니다.
창에 title 속성을 설정해야합니다. 제목은 원하는대로 지을 수 있습니다. 안전한 방편으로, UTF-8 인코딩으로 작성하시는게 좋습니다.
이제 제목과 동작하는 "닫기" 단추가 붙은 창을 만들었습니다. 이제 실제 "Hello World" 문구를 찍어보겠습니다.