chapter 2 finished

This commit is contained in:
2021-05-23 14:05:42 +02:00
parent a66d361cab
commit e111832ab7
4 changed files with 72 additions and 2 deletions
+22
View File
@@ -0,0 +1,22 @@
// helloGUIWorld.vala
int main (string[] args) {
Gtk.init (ref args);
var window = new Gtk.Window ();
window.title = "Hello UI World";
window.border_width = 10;
window.window_position = Gtk.WindowPosition.CENTER;
window.set_default_size (400, 150);
window.destroy.connect (Gtk.main_quit);
var button = new Gtk.Button.with_label ("Click me!");
button.clicked.connect ( () => {
button.label = "Thank you!";
});
window.add (button);
window.show_all ();
Gtk.main ();
return 0;
}
+2 -2
View File
@@ -1,9 +1,9 @@
// helloObjectWorld.vala
class HelloWorld {
private string? name;
private string name;
public HelloWorld (string name) {
public HelloWorld (string? name) {
this.name = name;
}
+24
View File
@@ -0,0 +1,24 @@
// helloObjectWorld.vala
class HelloWorld {
private string name;
public HelloWorld (string? name) {
this.name = name;
}
public void greet () {
var fullGreeting = "Hello " + this.name + "!\n";
stdout.printf (fullGreeting);
}
}
int main (string[] args) {
if ( args.length < 2 ) {
stderr.printf ("Usage: %s <name>\n", args[0]);
return -1;
}
HelloWorld helloWorldObject = new HelloWorld (args [1]);
helloWorldObject.greet();
return 0;
}
+24
View File
@@ -0,0 +1,24 @@
// helloObjectWorld.vala
class HelloWorld {
private string name;
public HelloWorld (string? name) {
this.name = name;
}
public void greet () {
var fullGreeting = "Hello " + this.name + "!\n";
stdout.printf (fullGreeting);
}
}
int main (string[] args) {
if ( args.length < 2 ) {
stderr.printf ("Usage: %s <name>\n", args[0]);
return -1;
}
HelloWorld helloWorldObject = new HelloWorld (args [1]);
helloWorldObject.greet();
return 0;
}