Hello world/Graphical
In this User Output task, the goal is to display the string "Goodbye, World!" on a GUI object (alert box, plain window, text area, etc.).
![Task](http://static.miraheze.org/rosettacodewiki/thumb/b/ba/Rcode-button-task-crushed.png/64px-Rcode-button-task-crushed.png)
You are encouraged to solve this task according to the task description, using any language you may know.
See also: User Output - text
ActionScript
trace("Goodbye, World!");
Ada
<ada> with Gdk.Event; use Gdk.Event; with Gtk.Label; use Gtk.Label; with Gtk.Window; use Gtk.Window; with Gtk.Widget; use Gtk.Widget;
with Gtk.Handlers; with Gtk.Main;
procedure Windowed_Goodbye_World is
Window : Gtk_Window; Label : Gtk_Label;
package Handlers is new Gtk.Handlers.Callback (Gtk_Widget_Record); package Return_Handlers is new Gtk.Handlers.Return_Callback (Gtk_Widget_Record, Boolean);
function Delete_Event (Widget : access Gtk_Widget_Record'Class) return Boolean is begin return False; end Delete_Event;
procedure Destroy (Widget : access Gtk_Widget_Record'Class) is begin Gtk.Main.Main_Quit; end Destroy;
begin
Gtk.Main.Init; Gtk.Window.Gtk_New (Window); Gtk_New (Label, "Goodbye, World!"); Add (Window, Label); Return_Handlers.Connect ( Window, "delete_event", Return_Handlers.To_Marshaller (Delete_Event'Access) ); Handlers.Connect ( Window, "destroy", Handlers.To_Marshaller (Destroy'Access) ); Show_All (Label); Show (Window);
Gtk.Main.Main;
end Windowed_Goodbye_World; </ada>
AppleScript
display dialog "Goodbye, World!" buttons {"Bye"}
C
#include int main (int argc, char **argv) { GtkWidget *window; gtk_init(&argc, &argv); window = gtk_window_new (GTK_WINDOW_TOPLEVEL); gtk_window_set_title (GTK_WINDOW (window), “Goodbye, World”); g_signal_connect (G_OBJECT (window), “delete-event”, gtk_main_quit, NULL); gtk_widget_show_all (window); gtk_main(); return 0; }
Where hWnd is a valid window handle corresponding to a control in the application
#include "windows.h" void SayGoodbyeWorld(HWND hWnd) { SetWindowText(hWwnd, _T("Goodbye, World!")); }
C#
using Gtk; using GtkSharp; public class GoodbyeWorld { public static void Main(string[] args) { Gtk.Window window = new Gtk.Window(); window.Title = "Goodbye, World"; window.DeleteEvent += delegate { Application.Quit(); }; window.ShowAll(); Application.Run(); } }
C++
#include <gtkmm.h> int main(int argc, char *argv[]) { Gtk::Main app(argc, argv); Gtk::MessageDialog msg("Goodbye, World!"); msg.run(); }
All Win32 APIs work in C++ the same way as they do in C. See the C example.
Where pWnd is a pointer to a CWnd object corresponding to a valid window in the application.
#include "afx.h" void ShowGoodbyeWorld(CWnd* pWnd) { pWnd->SetWindowText(_T("Goodbye, World!")); }
Clean
import StdEnv, StdIO Start :: *World -> *World Start world = startIO NDI Void (snd o openDialog undef hello) [] world where hello = Dialog "" (TextControl "Goodbye, World!" []) [WindowClose (noLS closeProcess)]
eC
MessageBox:
import "ecere" MessageBox goodBye { contents = "Goodbye, World!" };
Label:
import "ecere" Label label { text = "Goodbye, World!", hasClose = true, opacity = 1, size = { 320, 200 } };
Titled Form + Surface Output:
import "ecere" class GoodByeForm : Window { text = "Goodbye, World!"; size = { 320, 200 }; hasClose = true; void OnRedraw(Surface surface) { surface.WriteTextf(10, 10, "Goodbye, World!"); } } GoodByeForm form {};
Icon
link graphics procedure main() local w WOpen("size=80,20") | stop("No window") WWrites("goodbye world") WDone() end
J
wdinfo'Goodbye, World!'
Java
<java>import javax.swing.*; public class OutputSwing {
public static void main(String[] args) throws Exception { JOptionPane.showMessageDialog (null, "Goodbye, World!");//alert box JFrame window = new JFrame("Goodbye, World!");//text on title bar JTextArea text = new JTextArea(); text.setText("Goodbye, World!");//text in editable area JButton button = new JButton("Goodbye, World!");//text on button //so the button and text area don't overlap window.setLayout(new FlowLayout()); window.add(button);//put the button on first window.add(text);//then the text area window.pack();//resize the window so it's as big as it needs to be window.setVisible(true);//show it //stop the program when the window is closed window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); }
}</java>
JavaScript
This pops up a small dialog, so it might be termed GUI display.
alert("Goodbye, World!");
MAXScript
messageBox "Goodbye world"
Objective-C
To show a modal alert:
NSAlert *alert = [[[NSAlert alloc] init] autorelease]; [alert setMessageText:@"Goodbye, World!"]; [alert runModal];
OCaml
<ocaml>let delete_event evt = false
let destroy () = GMain.Main.quit ()
let main () =
let window = GWindow.window in let _ = window#set_title "Goodbye, World" in let _ = window#event#connect#delete ~callback:delete_event in let _ = window#connect#destroy ~callback:destroy in let _ = window#show () in GMain.Main.main ()
let _ = main () ;; </ocaml>
ocaml -I +labltk labltk.cma
Just output as a label in a window: <ocaml>let () =
let main_widget = Tk.openTk () in let lbl = Label.create ~text:"Goodbye, World" main_widget in Tk.pack [lbl]; Tk.mainLoop();;</ocaml>
Output as text on a button that exits the current application: <ocaml>let () =
let action () = exit 0 in let main_widget = Tk.openTk () in let bouton_press = Button.create main_widget ~text:"Goodbye, World" ~command:action in Tk.pack [bouton_press]; Tk.mainLoop();;</ocaml>
Perl
Just output as a label in a window:
use Tk; $main = MainWindow->new; $main->Label(-text => 'Goodbye, World')->pack; MainLoop();
Output as text on a button that exits the current application:
use Tk; $main = MainWindow->new; $main->Button( -text => 'Goodbye, World', -command => \&exit, )->pack; MainLoop();
use Gtk2 '-init'; $window = Gtk2::Window->new; $window->set_title('Goodbye world'); $window->signal_connect( 'destroy' => sub { Gtk2->main_quit; } ); $label = Gtk2::Label->new('Goodbye, world'); $window->add($label); $window->show_all; Gtk2->main;
PHP
if (!class_exists('gtk')) { die("Please load the php-gtk2 module in your php.ini\r\n"); } $wnd = new GtkWindow(); $wnd->set_title('Goodbye world'); $wnd->connect_simple('destroy', array('gtk', 'main_quit')); $lblHello = new GtkLabel("Goodbye, World!"); $wnd->add($lblHello); $wnd->show_all(); Gtk::main();
PostScript
In the geenral Postscript context, the show command will render the string that is topmost on the stack at the currentpoint in the previously setfont. Thus a minimal PostScript file that will print on a PostScript printer or previewer might look like this:
%!PS % render in Helvetica, 12pt: /Helvetica findfont 12 scalefont setfont % somewhere in the lower left-hand corner: 50 dup moveto % render text (Goodbye World) show % wrap up page display: showpage
Python
import tkMessageBox result = tkMessageBox.showinfo("Some Window Label", "Goodbye, World!")
Note: The result is a string of the button that was pressed.
import pygtk pygtk.require('2.0') import gtk window = gtk.Window() window.set_title('Goodbye, World') window.connect('delete-event', gtk.main_quit) window.show_all() gtk.main()
RapidQ
MessageBox("Goodbye, World!", "RapidQ example", 0)
Ruby
require 'gtk2' window = Gtk::Window.new window.title = 'Goodbye, World' window.signal_connect(:delete-event) { Gtk.main_quit } window.show_all Gtk.main
Smalltalk
MessageBox show: 'Goodbye, world.'
Tcl
Just output as a label in a window:
pack [label .l -text "Goodbye, World"]
Output as text on a button that exits the current application:
pack [button .b -text "Goodbye, World" -command exit]
Vedit macro language
Displaying the message on status line. The message remains visible until the next keystroke, but macro execution continues.
Statline_Message("Goodbye, World!")
Displaying a dialog box with the message and default OK button:
Dialog_Input_1(1,"`Vedit example`,`Goodbye, World!`")
Visual Basic .NET
Module GoodbyeWorld Sub Main() Messagebox.Show("Goodbye, World!") End Sub End Module