Hello world/Graphical: Difference between revisions

From Rosetta Code
Content added Content deleted
No edit summary
m (Remove white space/etc.)
Line 8: Line 8:
=={{header|C}}==
=={{header|C}}==
{{libheader|GTK}}
{{libheader|GTK}}

<pre>#include
<pre>#include


Line 43: Line 42:


{{libheader|GTK}}
{{libheader|GTK}}

#include <gtkmm.h>
#include <gtkmm.h>
int main(int argc, char *argv[])
int main(int argc, char *argv[])
Line 53: Line 51:
=={{header|Clean}}==
=={{header|Clean}}==
{{libheader|Object I/O}}
{{libheader|Object I/O}}

import StdEnv, StdIO
import StdEnv, StdIO


Line 63: Line 60:
=={{header|Java}}==
=={{header|Java}}==
{{libheader|Swing}}
{{libheader|Swing}}

import javax.swing.*;
import javax.swing.*;
public class OutputSwing {
public class OutputSwing {
Line 70: Line 66:
}
}
}
}

=={{header|JavaScript}}==
=={{header|JavaScript}}==
'''Interpreter:''' Firefox 2.0
'''Interpreter:''' Firefox 2.0
Line 89: Line 86:
=={{header|OCaml}}==
=={{header|OCaml}}==
{{libheader|GTK}}
{{libheader|GTK}}

let delete_event evt = false
let delete_event evt = false


Line 143: Line 139:


=={{header|PHP}}==
=={{header|PHP}}==

{{libheader|PHP-GTK}}
{{libheader|PHP-GTK}}

if (!class_exists('gtk'))
if (!class_exists('gtk'))
{
{
Line 160: Line 154:
$wnd->show_all();
$wnd->show_all();
Gtk::main();
Gtk::main();

=={{header|PostScript}}==
=={{header|PostScript}}==
In the geenral Postscript context, the <tt>show</tt> command will render the string that is topmost on the stack at the <tt>currentpoint</tt> in the previously <tt>setfont</tt>. Thus a minimal PostScript file that will print on a PostScript printer or previewer might look like this:
In the geenral Postscript context, the <tt>show</tt> command will render the string that is topmost on the stack at the <tt>currentpoint</tt> in the previously <tt>setfont</tt>. Thus a minimal PostScript file that will print on a PostScript printer or previewer might look like this:
Line 172: Line 167:
% wrap up page display:
% wrap up page display:
showpage
showpage

=={{header|Python}}==
=={{header|Python}}==
'''Interpreter:''' Python 2.5
'''Interpreter:''' Python 2.5


{{libheader|Tkinter}}
{{libheader|Tkinter}}

import tkMessageBox
import tkMessageBox
Line 182: Line 177:


'''Note:''' The result is a string of the button that was pressed.
'''Note:''' The result is a string of the button that was pressed.
{{libheader|GTK}}


{{libheader|GTK}}
<pre>import pygtk
<pre>import pygtk
pygtk.require('2.0')
pygtk.require('2.0')
Line 193: Line 188:
window.show_all()
window.show_all()
gtk.main()</pre>
gtk.main()</pre>

=={{header|Ruby}}==
=={{header|Ruby}}==
{{libheader|GTK}}
{{libheader|GTK}}

<pre>require 'gtk2'
<pre>require 'gtk2'



Revision as of 11:35, 13 February 2008

Task
Hello world/Graphical
You are encouraged to solve this task according to the task description, using any language you may know.

In the User Output task, the goal is to display the string "Goodbye, World!" on a graphical console.

ActionScript

trace("Goodbye, World!");

AppleScript

display dialog "Goodbye, World!" buttons {"Bye"}

C

Library: GTK
#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;
}

C#

Library: GTK

Compiler: Mono

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++

Compiler: GCC 3.3.5

Library: GTK
#include <gtkmm.h>
int main(int argc, char *argv[])
{
   Gtk::Main app(argc, argv);
   Gtk::MessageDialog msg("Goodbye, World!");
   msg.run();
}

Clean

Library: Object I/O
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)]

Java

Library: Swing
import javax.swing.*;
public class OutputSwing {
    public static void main(String[] args) throws Exception {
        JOptionPane.showMessageDialog (null, "Goodbye, World!");
    }
}

JavaScript

Interpreter: Firefox 2.0

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

Library: GTK

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 () ;;

Perl

Interpreter: Perl 5.8.8

Library: Tk

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();
Library: Gtk2
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

Library: PHP-GTK
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

Interpreter: Python 2.5

Library: Tkinter
 import tkMessageBox
 
 result = tkMessageBox.showinfo("Some Window Label", "Goodbye, World!")

Note: The result is a string of the button that was pressed.

Library: GTK
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()

Ruby

Library: GTK
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

Library: Tk

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]

Visual Basic .NET

Compiler: Visual Basic 2005

Module GoodbyeWorld
    Sub Main()
        Messagebox.Show("Goodbye, World!")
    End Sub
End Module