Now let's subclass GtkWindow
and imagine that we want to change the behavior of the set_title
function of GtkWindow
. The function is used to set the window's title with the specified string passed in the argument. The new behavior that we want to introduce here is to always add a special word into the window's title whenever we set the set_title
function.
Create a new Vala project called
custom-overriding
.In the
src/custom_overriding.vala
file, use the following code:using GLib; using Gtk; public class CustomWindow : Window { public CustomWindow () { } public new void set_title(string newTitle) { title = "Custom: " + newTitle; } static int main (string[] args) { Gtk.init (ref args); var window = new CustomWindow (); window.set_title ("My window"); window.show_all (); window.destroy.connect(Gtk.main_quit); Gtk.main (); return 0; } }
Our JavaScript equivalent code looks...