Hello world/Graphical
You are encouraged to solve this task according to the task description, using any language you may know.
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.).
See also: Hello world/Text
ActionScript
<lang actionscript> var textField:TextField = new TextField(); stage.addChild(textField); textField.text = "Goodbye, World!" </lang>
Ada
<lang 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;</lang>
AppleScript
<lang applescript>display dialog "Goodbye, World!" buttons {"Bye"}</lang>
Applesoft BASIC
<lang Applesoft BASIC> 1 LET T$ = "GOODBYE, WORLD!"
2 LET R = 5:GX = 3:GY = 2:O = 3:XC = R + GX:YC = R * 2 + GY 3 TEXT : HOME : TEXT : HGR : HCOLOR= 7: HPLOT 0,0: CALL 62454: HCOLOR= 6 4 LET L = LEN (T$): FOR I = 1 TO L:K = ASC ( MID$ (T$,I,1)):XO = XC:YO = YC: GOSUB 5:XC = XO + 1:YC = YO: GOSUB 7: NEXT : END 5 IF K > 64 THEN K = K + LC: GOSUB 20:LC = 32: RETURN 6 LET LC = 0: ON K > = 32 GOTO 20: RETURN 7 GOSUB 20:XC = XC + R * 2 + GX: IF XC > 279 - R THEN XC = R + GX:YC = YC + GY + R * 5 8 RETURN 9 LET XC = XC - R * 2: RETURN 10 LET Y = R:D = 1 - R:X = 0 11 IF D > = 0 THEN Y = Y - 1:D = D - Y * 2 12 LET D = D + X * 2 + 3 13 IF O = 1 OR O = 3 THEN GOSUB 17 14 IF O = 2 OR O = 3 THEN GOSUB 19 15 LET X = X + 1: IF X < Y THEN 11 16 LET O = 3:E = 0: RETURN 17 HPLOT XC - X,YC + Y: HPLOT XC + X,YC + Y: HPLOT XC - Y,YC + X: IF NOT E THEN HPLOT XC + Y,YC + X 18 RETURN 19 HPLOT XC - X,YC - Y: HPLOT XC + X,YC - Y: HPLOT XC - Y,YC - X: HPLOT XC + Y,YC - X: RETURN 20 LET M = K - 31 21 ON M GOTO 32,33,34,35,36,37,38,39,40,41,42,43,44 22 LET M = M - 32 23 ON M GOTO 64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87 24 LET M = M - 32 25 ON M GOTO 96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,10,112,113,114,115,116,117,118,119,120,121 32 RETURN 33 HPLOT XC - R,YC - R * 2 TO XC - R,YC + R - GY: HPLOT XC - R,YC + R: GOTO 9: REM ! 44 HPLOT XC - R,YC + R + R / 2 TO XC - R,YC + R: GOTO 9: REM , 71 LET O = 2:YC = YC - R: GOSUB 10:YC = YC + R: HPLOT XC - R,YC TO XC - R,YC - R: HPLOT XC + R / 2,YC TO XC + R,YC TO XC + R,YC + R:O = 1: GOTO 10: REM G 87 HPLOT XC - R,YC - R * 2 TO XC - R,YC + R TO XC,YC TO XC + R,YC + R TO XC + R,YC - R * 2: RETURN : REM W 98 HPLOT XC - R,YC - R * 2 TO XC - R,YC + R: GOTO 10: RETURN : REM B
100 HPLOT XC + R,YC - R * 2 TO XC + R,YC + R: GOTO 10: REM D 101 HPLOT XC - R,YC TO XC + R,YC:E = 1: GOTO 10: REM E 108 HPLOT XC - R,YC - R * 2 TO XC - R,YC + R: GOTO 9: REM L 114 HPLOT XC - R,YC - R TO XC - R,YC + R:O = 2: GOTO 10: REM R 121 HPLOT XC - R,YC - R TO XC,YC + R: HPLOT XC + R,YC - R TO XC - R,YC + R * 3: RETURN : REM Y</lang>
AutoHotkey
<lang autohotkey>MsgBox, Goodbye`, World!</lang> <lang autohotkey>ToolTip, Goodbye`, World!</lang> <lang autohotkey>Gui, Add, Text, x4 y4, To be announced: Gui, Add, Edit, xp+90 yp-3, Goodbye, World! Gui, Add, Button, xp+98 yp-1, OK Gui, Show, w226 h22 , Rosetta Code Return</lang> <lang autohotkey>SplashTextOn, 100, 100, Rosetta Code, Goodbye, World!</lang>
AutoIt
<lang autoit>; display a window
- include <GUIConstantsEx.au3>
- include <StaticConstants.au3>
- include <WindowsConstants.au3>
$hMain = GUICreate("", 178, 125, -1, -1) GUICtrlCreateLabel("Goodbye, world", 48, 48, 78, 17) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE GUIDelete($hMain) ExitLoop EndSwitch WEnd
- display a message box
MsgBox(0, "", "Goodbye, world") </lang>
BASIC
<lang freebasic>' Demonstrate a simple Windows application using FreeBasic
- include once "windows.bi"
Declare Function WinMain(ByVal hInst As HINSTANCE, _
ByVal hPrev As HINSTANCE, _ ByVal szCmdLine as String, _ ByVal iCmdShow As Integer) As Integer
End WinMain( GetModuleHandle( null ), null, Command( ), SW_NORMAL )
Function WinMain (ByVal hInst As HINSTANCE, _
ByVal hPrev As HINSTANCE, _ ByVal szCmdLine As String, _ ByVal iCmdShow As Integer) As Integer MessageBox(NULL, "Goodbye World", "Goodbye World", MB_ICONINFORMATION) function = 0
End Function</lang>
BBC BASIC
<lang bbcbasic> SYS "MessageBox", @hwnd%, "Goodbye, World!", "", 0</lang>
C
<lang c>#include <gtk/gtk.h>
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;
}</lang>
Where hWnd is a valid window handle corresponding to a control in the application <lang c>#include "windows.h" void SayGoodbyeWorld(HWND hWnd) {
SetWindowText(hWnd, _T("Goodbye, World!"));
}</lang>
C#
Winforms
<lang csharp>using System; using System.Windows.Forms;
class Program {
static void Main(string[] args) { Application.EnableVisualStyles(); //Optional. MessageBox.Show("Hello World!"); }
}</lang>
Gtk
<lang csharp>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(); }
}</lang>
C++
<lang cpp>#include <gtkmm.h> int main(int argc, char *argv[]) {
Gtk::Main app(argc, argv); Gtk::MessageDialog msg("Goodbye, World!"); msg.run();
}</lang>
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. <lang cpp>#include "afx.h" void ShowGoodbyeWorld(CWnd* pWnd) {
pWnd->SetWindowText(_T("Goodbye, World!"));
}</lang>
<lang cpp>
- include <FL/Fl.H>
- include <FL/Fl_Window.H>
- include <FL/Fl_Box.H>
int main(int argc, char **argv) {
Fl_Window *window = new Fl_Window(300,180); Fl_Box *box = new Fl_Box(20,40,260,100,"Goodby, World!"); box->box(FL_UP_BOX); box->labelsize(36); box->labelfont(FL_BOLD+FL_ITALIC); box->labeltype(FL_SHADOW_LABEL); window->end(); window->show(argc, argv); return Fl::run();
} </lang>
C++/CLI
<lang cpp> using namespace System::Windows::Forms;
int main(array<System::String^> ^args) {
MessageBox::Show("Goodbye, World!", "Rosetta Code");
} </lang>
Clean
<lang 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)]</lang>
Clojure
<lang lisp>(ns experimentation.core
(:import (javax.swing JOptionPane JFrame JTextArea JButton)
(java.awt FlowLayout)))
(JOptionPane/showMessageDialog nil "Goodbye, World!") (let [button (JButton. "Goodbye, World!")
window (JFrame. "Goodbye, World!") text (JTextArea. "Goodbye, World!")] (doto window (.setLayout (FlowLayout.)) (.add button) (.add text) (.pack) (.setDefaultCloseOperation (JFrame/EXIT_ON_CLOSE)) (.setVisible true)))</lang>
COBOL
This is a TUI, not a GUI version, because it
The program gets the lines and columns of the screen and positions the text in the middle. Program waits for a return key.
<lang cobol> program-id. ghello. data division. working-storage section. 01 var pic x(1). 01 lynz pic 9(3). 01 colz pic 9(3). 01 msg pic x(15) value "Goodbye, world!". procedure division. accept lynz from lines end-accept divide lynz by 2 giving lynz. accept colz from columns end-accept divide colz by 2 giving colz. subtract 7 from colz giving colz. display msg at line number lynz column number colz end-display accept var end-accept stop run.</lang>
CoffeeScript
<lang coffeescript>alert "Goodbye, World!"</lang>
Common Lisp
This can be done using the extension package ltk that provides an interface to the Tk library.
<lang lisp>(use-package :ltk)
(defun show-message (text)
"Show message in a label on a Tk window" (with-ltk () (let* ((label (make-instance 'label :text text)) (button (make-instance 'button :text "Done" :command (lambda () (ltk::break-mainloop) (ltk::update))))) (pack label :side :top :expand t :fill :both) (pack button :side :right) (mainloop))))
(show-message "Goodbye World")</lang>
D
<lang D>import gtk.MainWindow; import gtk.Label; import gtk.Main;
class GoodbyeWorld : MainWindow {
this() { super("GtkD"); add(new Label("Goodbye World")); showAll(); }
}
void main(string[] args) {
Main.init(args); new GoodbyeWorld(); Main.run();
}</lang>
Delphi
<lang Delphi>program HelloWorldGraphical;
uses
Dialogs;
begin
ShowMessage('Goodbye, World!');
end.</lang>
Dylan
(This works entered into the interactive shell): <lang dylan>notify-user("hello world!", frame: make(<frame>));</lang>
E
This is a complete application. If it were part of a larger application, the portions related to interp
would be removed.
<lang e>def <widget> := <swt:widgets.*> def SWT := <swt:makeSWT>
def frame := <widget:makeShell>(currentDisplay)
frame.setText("Rosetta Code") frame.setBounds(30, 30, 230, 60) frame.addDisposeListener(def _ { to widgetDisposed(event) { interp.continueAtTop() }})
def label := <widget:makeLabel>(frame, SWT.getLEFT())
label.setText("Goodbye, World!") swtGrid`$frame: $label`
frame.open()
interp.blockAtTop()</lang>
eC
MessageBox:
<lang ec>import "ecere" MessageBox goodBye { contents = "Goodbye, World!" };</lang>
Label:
<lang ec>import "ecere" Label label { text = "Goodbye, World!", hasClose = true, opacity = 1, size = { 320, 200 } };</lang>
Titled Form + Surface Output:
<lang ec>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 {};</lang>
Euphoria
Message box
<lang euphoria>include msgbox.e
integer response response = message_box("Goodbye, World!","Bye",MB_OK)</lang>
F#
Just display the text in a message box. <lang fsharp>#light open System open System.Windows.Forms [<EntryPoint>] let main _ =
MessageBox.Show("Hello World!") |> ignore 0</lang>
Factor
To be pasted in the listener :
USING: ui ui.gadgets.labels [ "Goodbye World" <label> "Rosetta Window" open-window ] with-ui
Fantom
<lang fantom> using fwt
class Hello {
public static Void main () { Dialog.openInfo (null, "Goodbye world") }
} </lang>
Forth
<lang forth>HWND z" Goodbye, World!" z" (title)" MB_OK MessageBox</lang>
Frink
All Frink graphics are automatically scaled and centered in the window, so the exact coordinates used below are rather arbitrary.
<lang frink> g = new graphics g.font["SansSerif", 10] g.text["Hello World!", 0, 0] g.show[]
g.print[] // Optional: render to printer g.write["HelloWorld.png", 400, 300] // Optional: write to graphics file </lang>
Go
Just setting title bar text, <lang go>package main
import "gtk"
func main() {
gtk.Init(nil) window := gtk.Window(gtk.GTK_WINDOW_TOPLEVEL) window.SetTitle("Goodbye, World!") window.SetSizeRequest(300, 200) window.Connect("destroy", func(*gtk.CallbackContext) { gtk.MainQuit() }, "") window.ShowAll() gtk.Main()
}</lang>
Groovy
<lang groovy>import groovy.swing.SwingBuilder import javax.swing.JFrame
new SwingBuilder().edt {
optionPane().showMessageDialog(null, "Goodbye, World!") frame(title:'Goodbye, World!', defaultCloseOperation:JFrame.EXIT_ON_CLOSE, pack:true, show: true) { flowLayout() button(text:'Goodbye, World!') textArea(text:'Goodbye, World!') }
} </lang>
Haskell
Useing
from HackageDB
<lang haskell>import Graphics.UI.Gtk import Control.Monad
messDialog = do
initGUI dialog <- messageDialogNew Nothing [] MessageInfo ButtonsOk "Goodbye, World!" rs <- dialogRun dialog when (rs == ResponseOk || rs == ResponseDeleteEvent) $ widgetDestroy dialog
dialog `onDestroy` mainQuit mainGUI</lang>
Run in GHCi interpreter: <lang haskell>*Main> messDialog</lang>
HicEst
<lang hicest>WRITE(Messagebox='!') 'Goodbye, World!'</lang>
Icon and Unicon
Icon
<lang Icon>procedure main()<lang icon>link graphics procedure main()
WOpen("size=100,20") | stop("No window") WWrites("Goodbye, World!") WDone()
end</lang>
Unicon
<lang unicon> import gui $include "guih.icn"
class WindowApp : Dialog ()
# -- automatically called when the dialog is created method component_setup () # add 'hello world' label label := Label("label=Hello world","pos=0,0") add (label)
# make sure we respond to close event connect(self, "dispose", CLOSE_BUTTON_EVENT) end
end
- create and show the window
procedure main ()
w := WindowApp () w.show_modal ()
end </lang>
Integer BASIC
40×40 isn't great resolution, but it's enough!
<lang basic> 10 REM FONT DERIVED FROM 04B-09 BY YUJI OSHIMOTO 20 GR 30 COLOR = 12 40 REM G 50 HLIN 0,5 AT 0 : HLIN 0,5 AT 1 60 VLIN 2,9 AT 0 : VLIN 2,9 AT 1 70 HLIN 2,5 AT 9 : HLIN 2,5 AT 8 80 VLIN 4,7 AT 5 : VLIN 4,7 AT 4 90 VLIN 4,5 AT 3 100 REM O 110 HLIN 7,12 AT 2 : HLIN 7,12 AT 3 120 HLIN 7,12 AT 8 : HLIN 7,12 AT 9 130 VLIN 4,7 AT 7 : VLIN 4,7 AT 8 140 VLIN 4,7 AT 11 : VLIN 4,7 AT 12 150 REM O 160 HLIN 14,19 AT 2 : HLIN 14,19 AT 3 170 HLIN 14,19 AT 8 : HLIN 14,19 AT 9 180 VLIN 4,7 AT 14 : VLIN 4,7 AT 15 190 VLIN 4,7 AT 18 : VLIN 4,7 AT 19 200 REM D 210 HLIN 21,24 AT 2 : HLIN 21,24 AT 3 220 HLIN 21,26 AT 8 : HLIN 21,26 AT 9 230 VLIN 4,7 AT 21 : VLIN 4,7 AT 22 240 VLIN 0,7 AT 25 : VLIN 0,7 AT 26 250 REM - 260 HLIN 28,33 AT 4 : HLIN 28,33 AT 5 270 REM B 280 VLIN 11,20 AT 0 : VLIN 11,20 AT 1 290 HLIN 2,5 AT 20 : HLIN 2,5 AT 19 300 VLIN 15,18 AT 5 : VLIN 15,18 AT 4 310 HLIN 2,5 AT 14 : HLIN 2,5 AT 13 320 REM Y 330 VLIN 13,20 AT 7 : VLIN 13,20 AT 8 340 VLIN 19,20 AT 9 : VLIN 19,20 AT 10 350 VLIN 13,24 AT 11 : VLIN 13,24 AT 12 360 VLIN 23,24 AT 10 : VLIN 23,24 AT 9 370 REM E 380 VLIN 13,20 AT 14 : VLIN 13,20 AT 15 390 HLIN 16,19 AT 13 : HLIN 16,19 AT 14 400 HLIN 18,19 AT 15 : HLIN 18,19 AT 16 410 HLIN 16,17 AT 17 : HLIN 16,17 AT 18 420 HLIN 16,19 AT 19 : HLIN 16,19 AT 20 430 REM , 440 VLIN 17,22 AT 21 : VLIN 17,22 AT 22 450 REM W 460 VLIN 24,33 AT 0 : VLIN 24,33 AT 1 : VLIN 24,33 AT 3 470 VLIN 24,33 AT 4 : VLIN 24,33 AT 6 : VLIN 24,33 AT 7 480 HLIN 0,7 AT 33 : HLIN 0,7 AT 32 490 REM O 500 HLIN 9,14 AT 26 : HLIN 9,14 AT 27 510 HLIN 9,14 AT 32 : HLIN 9,14 AT 33 520 VLIN 28,31 AT 9 : VLIN 28,31 AT 10 530 VLIN 28,31 AT 13 : VLIN 28,31 AT 14 540 REM R 550 HLIN 16,21 AT 26 : HLIN 16,21 AT 27 560 VLIN 28,33 AT 16 : VLIN 28,33 AT 17 570 REM L 580 VLIN 24,33 AT 23 : VLIN 24,33 AT 24 590 REM D 600 HLIN 26,29 AT 26 : HLIN 26,29 AT 27 610 HLIN 26,29 AT 32 : HLIN 26,29 AT 33 620 VLIN 28,33 AT 26 : VLIN 28,33 AT 27 630 VLIN 24,33 AT 30 : VLIN 24,33 AT 31 640 REM ! 650 VLIN 24,29 AT 33 : VLIN 24,29 AT 34 660 VLIN 32,33 AT 33 : VLIN 32,33 AT 34 670 END </lang>
Ioke
<lang ioke>import(
:javax:swing, :JOptionPane, :JFrame, :JTextArea, :JButton
) import java:awt:FlowLayout
JOptionPane showMessageDialog(nil, "Goodbye, World!") button = JButton new("Goodbye, World!") text = JTextArea new("Goodbye, World!") window = JFrame new("Goodbye, World!") do(
layout = FlowLayout new add(button) add(text) pack setDefaultCloseOperation(JFrame field:EXIT_ON_CLOSE) visible = true
)</lang>
J
<lang j>wdinfo'Goodbye, World!'</lang>
Java
<lang 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); }
}</lang>
JavaScript
<lang javascript> alert("Goodbye, World!");</lang>
KonsolScript
Popping a dialog-box. <lang KonsolScript>function main() {
Konsol:Message("Goodbye, World!", "")
}</lang>
Displaying it in a Window. <lang KonsolScript>function main() {
Screen:PrintString("Goodbye, World!") while (B1 == false) { Screen:Render() }
}</lang>
Liberty BASIC
<lang lb>NOTICE "Goodbye, world!"</lang>
Logo
Among the turtle commands are some commands for drawing text in the graphical area. Details and capabilities differ among Logo implementations. <lang logo>LABEL [Hello, World!] SETLABELHEIGHT 2 * last LABELSIZE LABEL [Goodbye, World!]</lang>
Lua
<lang lua>require "iuplua"
dlg = iup.dialog{iup.label{title="Goodbye, World!"}; title="test"} dlg:show()
if (not iup.MainLoopLevel or iup.MainLoopLevel()==0) then
iup.MainLoop()
end</lang>
MATLAB
<lang matlab>msgbox('Goodbye, World!')</lang>
MAXScript
<lang maxscript>messageBox "Goodbye world"</lang>
Modula-3
<lang modula3>MODULE GUIHello EXPORTS Main;
IMPORT TextVBT, Trestle;
<*FATAL ANY*>
VAR v := TextVBT.New("Goodbye, World!");
BEGIN
Trestle.Install(v); Trestle.AwaitDelete(v);
END GUIHello.</lang> This code requires an m3makefile.
import ("ui") implementation ("GUIHello") program ("Hello")
This tells the compiler to link with the UI library, the file name of the implementation code, and to output a program named "Hello".
Nemerle
Compile with:
ncc -reference:System.Windows.Forms goodbye.n
<lang Nemerle>using System; using System.Windows.Forms;
MessageBox.Show("Goodbye, World!")</lang>
NetRexx
Using Java's Swing Foundation Classes. <lang NetRexx>/* NetRexx */ options replace format comments java crossref savelog symbols binary
import javax.swing.
msgText = 'Goodbye, World!' JOptionPane.showMessageDialog(null, msgText) </lang>
An alternative version using other Swing classes. <lang NetRexx>/* NetRexx */ options replace format comments java crossref savelog symbols binary
import javax.swing.
msgText = 'Goodbye, World!'
window = JFrame(msgText) text = JTextArea() minSize = Dimension(200, 100)
text.setText(msgText)
window.setLayout(FlowLayout()) window.add(text) window.setMinimumSize(minSize) window.pack window.setVisible(isTrue) window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE)
return
method isTrue() public static returns boolean
return 1 == 1
method isFalse() public static returns boolean
return \isTrue
</lang>
An example using Java's Abstract Window Toolkit (AWT)
<lang NetRexx>/* NetRexx */ options replace format comments java crossref savelog symbols binary
class RCHelloWorld_GraphicalAWT_01 extends Dialog implements ActionListener
properties private constant msgText = 'Goodbye, World!'
properties indirect ok = boolean can = boolean okButton = Button canButton = Button buttonPanel = Panel
method RCHelloWorld_GraphicalAWT_01(frame = Frame, msg = String, canaction = boolean) public
super(frame, 'Default', isTrue) setLayout(BorderLayout()) add(BorderLayout.CENTER, Label(msg)) addOKCancelPanel(canaction) createFrame() pack() setVisible(isTrue) return
method RCHelloWorld_GraphicalAWT_01(frame = Frame, msg = String) public
this(frame, msg, isFalse) return
method addOKCancelPanel(canaction = boolean)
setButtonPanel(Panel()) getButtonPanel.setLayout(FlowLayout()) createOKButton() if canaction then do createCancelButton() end add(BorderLayout.SOUTH, getButtonPanel) return
method createOKButton()
setOkButton(Button('OK')) getButtonPanel.add(getOkButton) getOkButton.addActionListener(this) return
method createCancelButton()
setCanButton(Button('Cancel')) getButtonPanel.add(getCanButton) getCanButton.addActionListener(this) return
method createFrame()
dim = getToolkit().getScreenSize setLocation(int(dim.width / 3), int(dim.height / 3)) return
method actionPerformed(ae = ActionEvent) public
if ae.getSource == getOkButton then do setOk(isTrue) setCan(isFalse) setVisible(isFalse) end else if ae.getSource == getCanButton then do setCan(isTrue) setOk(isFalse) setVisible(isFalse) end return
method main(args = String[]) public constant
mainFrame = Frame() mainFrame.setSize(200, 200) mainFrame.setVisible(isTrue) message = RCHelloWorld_GraphicalAWT_01(mainFrame, msgText, isTrue) if message.isOk then say 'OK pressed' if message.isCan then say 'Cancel pressed' message.dispose mainFrame.dispose return
method isTrue() public static returns boolean
return 1 == 1
method isFalse() public static returns boolean
return \isTrue
</lang>
Objective-C
To show a modal alert: <lang objc>NSAlert *alert = [[[NSAlert alloc] init] autorelease]; [alert setMessageText:@"Goodbye, World!"]; [alert runModal];</lang>
Objeck
<lang objeck> use Qt;
bundle Default {
class QtExample { function : Main(args : String[]) ~ Nil { app := QAppliction->New(); win := QWidget->New(); win->Resize(400, 300); win->SetWindowTitle("Goodbye, World!"); win->Show(); app->Exec(); app->Delete(); } }
} </lang>
OCaml
<lang 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 () ;;</lang>
ocaml -I +labltk labltk.cma
Just output as a label in a window: <lang ocaml>let () =
let main_widget = Tk.openTk () in let lbl = Label.create ~text:"Goodbye, World" main_widget in Tk.pack [lbl]; Tk.mainLoop();;</lang>
Output as text on a button that exits the current application: <lang 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();;</lang>
Oz
<lang oz>declare
[QTk] = {Module.link ['x-oz://system/wp/QTk.ozf']} Window = {QTk.build td(label(text:"Goodbye, World!"))}
in
{Window show}</lang>
OpenEdge/Progress
<lang Progress (OpenEdge ABL)>MESSAGE "Goodbye, World!" VIEW-AS ALERT-BOX.</lang>
Perl
Just output as a label in a window:
<lang perl> use strict; use warnings; use Tk;
my $main = MainWindow->new; $main->Label(-text => 'Goodbye, World')->pack; MainLoop();</lang>
Output as text on a button that exits the current application:
<lang perl>use strict; use warnings; use Tk;
my $main = MainWindow->new; $main->Button(
-text => 'Goodbye, World', -command => \&exit,
)->pack; MainLoop();</lang>
<lang perl>use strict; use warnings; use Gtk2 '-init';
my $window = Gtk2::Window->new; $window->set_title('Goodbye world'); $window->signal_connect(
destroy => sub { Gtk2->main_quit; }
);
my $label = Gtk2::Label->new('Goodbye, world'); $window->add($label);
$window->show_all; Gtk2->main;</lang>
<lang perl>use strict; use warnings; use XUL::Gui;
display Label 'Goodbye, World!';</lang> <lang perl>use strict; use warnings; use XUL::Gui;
display Button
label => 'Goodbye, World!', oncommand => sub {quit};</lang>
PHP
<lang 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();</lang>
PicoLisp
<lang PicoLisp>(call 'dialog "--msgbox" "Goodbye, World!" 5 20)</lang>
PostScript
In the general 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:
<lang postscript>%!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</lang>
PowerBASIC
<lang powerbasic>FUNCTION PBMAIN() AS LONG
MSGBOX "Goodbye, World!"
END FUNCTION</lang>
PowerShell
<lang powershell>New-Label "Goodbye, World!" -FontSize 24 -Show</lang>
<lang powershell>$form = New-Object System.Windows.Forms.Form $label = New-Object System.Windows.Forms.Label
$label.Text = "Goodbye, World!" $form.AutoSize = $true $form.AutoSizeMode = [System.Windows.Forms.AutoSizeMode]::GrowAndShrink $form.Controls.Add($label)
$Form.ShowDialog() | Out-Null</lang> Alternatively, simply as a message box:
<lang powershell>[System.Windows.Forms.MessageBox]::Show("Goodbye, World!")</lang>
Prolog
Works with SWI-Prolog and XPCE.
A simple message box :
<lang Prolog>send(@display, inform, 'Goodbye, World !').</lang>
A more sophisticated window :
<lang Prolog>goodbye :-
new(D, window('Goodbye')), send(D, size, size(250, 100)), new(S, string("Goodbye, World !")), new(T, text(S)), get(@display, label_font, F), get(F, width(S), M), XT is (250 - M)/2, get(F, height, H), YT = (100-H)/2, send(D, display, T, point(XT, YT)), send(D, open).
</lang>
PureBasic
<lang PureBasic>MessageRequester("Hello","Goodbye, World!")</lang> Using the Windows API: <lang PureBasic>MessageBox_(#Null,"Goodbye, World!","Hello")</lang>
Python
<lang python>import tkMessageBox
result = tkMessageBox.showinfo("Some Window Label", "Goodbye, World!")</lang>
Note: The result is a string of the button that was pressed.
<lang python>import PyQt4.QtGui app = PyQt4.QtGui.QApplication([]) pb = PyQt4.QtGui.QPushButton('Hello World') pb.connect(pb,PyQt4.QtCore.SIGNAL("clicked()"),pb.close) pb.show() exit(app.exec_())</lang>
<lang python>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()</lang>
<lang python>import wx
app = wx.App(False) frame = wx.Frame(None, wx.ID_ANY, "Hello, World") frame.Show(True) app.MainLoop()</lang>
RapidQ
<lang rapidq>MessageBox("Goodbye, World!", "RapidQ example", 0)</lang>
R
Rather minimalist, but working... <lang R>library(RGtk2) # bindings to Gtk w <- gtkWindowNew() l <- gtkLabelNew("Goodbye, World!") w$add(l)</lang>
REBOL
<lang REBOL>alert "Goodbye, World!"</lang>
Ruby
<lang ruby>require 'gtk2'
window = Gtk::Window.new window.title = 'Goodbye, World' window.signal_connect(:delete-event) { Gtk.main_quit } window.show_all
Gtk.main</lang>
<lang ruby>require 'tk' root = TkRoot.new("title" => "User Output") TkLabel.new(root, "text"=>"goodbye world").pack("side"=>'top') Tk.mainloop</lang>
Scala
<lang scala>import javax.swing.JOptionPane import javax.swing.JFrame import javax.swing.JTextArea import javax.swing.JButton import java.awt.FlowLayout
object OutputSwing {
def main(args: Array[String]) { JOptionPane.showMessageDialog(null, "Goodbye, World!") //alert box val window = new JFrame("Goodbye, World!") //text on title bar val text = new JTextArea() text.setText("Goodbye, World!") //text in editable area val 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) }
}</lang>
Scheme
<lang ruby>
- !r6rs
- PS-TK example
- display frame + label
(import (rnrs)
(lib pstk main) ; change this to refer to your PS/Tk installation )
(define tk (tk-start)) (tk/wm 'title tk "PS-Tk Example: Label")
(let ((label (tk 'create-widget 'label 'text: "Goodbye, world")))
(tk/place label 'height: 20 'width: 50 'x: 10 'y: 20))
(tk-event-loop tk) </lang>
Scratch
Smalltalk
<lang smalltalk>MessageBox show: 'Goodbye, world.'</lang>
Tcl
Just output as a label in a window: <lang tcl>pack [label .l -text "Goodbye, World"]</lang>
Output as text on a button that exits the current application: <lang tcl>pack [button .b -text "Goodbye, World" -command exit]</lang>
Or as a message box: <lang tcl>tk_messageBox -message "Goodbye, World"</lang>
TI-89 BASIC
<lang ti89b>Dialog
Text "Goodbye, World!"
EndDlog</lang>
Vedit macro language
Displaying the message on status line. The message remains visible until the next keystroke, but macro execution continues. <lang vedit>Statline_Message("Goodbye, World!")</lang>
Displaying a dialog box with the message and default OK button: <lang vedit>Dialog_Input_1(1,"`Vedit example`,`Goodbye, World!`")</lang>
UNIX Shell
Using the zenity modal dialogue command (wraps GTK library) available with many distributions of Linux <lang bash> zenity --info --text='Goodbye, World!' </lang>
Visual Basic
<lang vb>Sub Main()
MsgBox "Goodbye, World!"
End Sub</lang>
Visual Basic .NET
<lang vbnet>Module GoodbyeWorld
Sub Main() Messagebox.Show("Goodbye, World!") End Sub
End Module</lang>
X86 Assembly
This example used the Windows MessageBox function to do the work for us. Windows uses the stdcall calling convention where the caller pushes function parameters onto the stack and the stack has been fixed up when the callee returns. <lang assembly>;;; hellowin.asm
- nasm -fwin32 hellowin.asm
- link -subsystem
- console -out:hellowin.exe -nodefaultlib -entry:main \
- hellowin.obj user32.lib kernel32.lib
global _main extern _MessageBoxA@16 extern _ExitProcess@4
MessageBox equ _MessageBoxA@16 ExitProcess equ _ExitProcess@4 section .text
_main:
push 0 ; MB_OK push title ; push message ; push 0 ; call MessageBox ; eax = MessageBox(0,message,title,MB_OK); push eax ; call ExitProcess ; ExitProcess(eax);
message:
db 'Goodbye, World',0
title:
db 'RosettaCode sample',0
</lang>
- Programming Tasks
- GUI
- Basic language learning
- ActionScript
- Ada
- GTK
- GtkAda
- AppleScript
- Applesoft BASIC
- AutoHotkey
- AutoIt
- BASIC
- BBC BASIC
- C
- Win32
- C sharp
- C++
- MFC
- FLTK
- C++/CLI
- Clean
- Object I/O
- Clojure
- COBOL
- CoffeeScript
- Common Lisp
- Tk
- D
- GtkD
- Delphi
- Dylan
- E
- SWT
- EC
- Euphoria
- F Sharp
- Factor
- Fantom
- Forth
- Frink
- Go
- Go-gtk
- Groovy
- Haskell
- Gtk
- HicEst
- Icon
- Icon Programming Library
- Unicon
- Integer BASIC
- Ioke
- J
- Java
- Swing
- JavaScript
- KonsolScript
- Liberty BASIC
- Logo
- Lua
- MATLAB
- MAXScript
- Modula-3
- Trestle
- Nemerle
- NetRexx
- Objective-C
- Objeck
- Qt
- OCaml
- OCaml-Xlib
- Oz
- OpenEdge/Progress
- Perl
- Gtk2
- PHP
- PHP-GTK
- PicoLisp
- PostScript
- PowerBASIC
- PowerShell
- WPK
- Windows Forms
- Prolog
- PureBasic
- Python
- Tkinter
- PyQt
- PyGTK
- WxPython
- RapidQ
- R
- REBOL
- Ruby
- Ruby/Tk
- Scala
- Scheme
- Scheme/PsTk
- Scratch
- Smalltalk
- Tcl
- TI-89 BASIC
- Vedit macro language
- UNIX Shell
- Visual Basic
- Visual Basic .NET
- X86 Assembly
- PARI/GP/Omit
- Unlambda/Omit