Window creation: Difference between revisions

From Rosetta Code
Content added Content deleted
m (→‎[[C]]: Fixed link to point to compiler, not compiler collection, used library template)
(Cleaned up page)
Line 1: Line 1:
{{task}}
{{task}}


==[[C]]==
=={{header|C}}==
[[Category:C]]

'''Standard:''' [[ANSI C]] (AKA [[C89]]):
'''Standard:''' [[ANSI C]] (AKA [[C89]]):


'''Compiler:''' [[Gcc]] 4.0.3
'''Compiler:''' [[gcc]] 4.0.3


{{library|SDL}}
{{library|SDL}}

[[Category:SDL]]


'''Compile Command:''' gcc -lSDL SDL_Window.c -o window
'''Compile Command:''' gcc -lSDL SDL_Window.c -o window
Line 36: Line 32:


=={{header|C++}}==
=={{header|C++}}==
===[[Qt]] 4===
{{library|Qt}} 4

[[Category:Qt]]


'''Compiler command:''' qmake -pro; qmake
'''Compiler command:''' qmake -pro; qmake
Line 53: Line 47:
}
}


{{library|Gtk+}}
===[[Gtk]]===

[[Category:Gtk]]


'''Compiler command:''' g++ filename.cc -o test `pkg-config --cflags --libs gtkmm-2.4`
'''Compiler command:''' g++ filename.cc -o test `pkg-config --cflags --libs gtkmm-2.4`
Line 81: Line 73:
}
}


==[[C sharp|C#]]==
=={{header|C sharp|C#}}==
[[Category:C sharp]]
'''Platform:''' [[.NET]] 1.1 (or higher)

'''Compiler:''' [[Visual C sharp|Visual C#]] 2003
'''Compiler:''' [[Visual C sharp|Visual C#]] 2003


Line 103: Line 92:
}
}


==[[E]]==
=={{header|E}}==
[[Category:E]]

===Java AWT/Swing===
===Java AWT/Swing===


Line 117: Line 104:
}
}


==[[Groovy]]==
=={{header|Groovy}}==
[[Category:Groovy]]
<pre>
<pre>
import groovy.swing.SwingBuilder
import groovy.swing.SwingBuilder
Line 125: Line 111:
</pre>
</pre>


==[[IDL]]==
=={{header|IDL}}==
[[Category:IDL]]

With some example values filled in:
With some example values filled in:


Line 156: Line 140:
}
}


==[[JavaScript]]==
=={{header|JavaScript}}==
[[Category:JavaScript]]
window.open("webpage.html", "windowname", "width=800,height=600");
window.open("webpage.html", "windowname", "width=800,height=600");


==[[mIRC Scripting Language]]==
=={{header|mIRC Scripting Language}}==
[[Category:mIRC Scripting Language]]

'''Interpreter:''' [[mIRC]]
'''Interpreter:''' [[mIRC]]
Line 174: Line 155:
}
}


==[[Perl]]==
=={{header|Perl}}==
[[Category:Perl]]

'''Interpreter:''' [[Perl]] 5.8.8
'''Interpreter:''' [[Perl]] 5.8.8


{{library|Tk}}
Using [[Tk]]:


use Tk;
use Tk;
Line 186: Line 165:
MainLoop;
MainLoop;


==[[Python]]==
=={{header|Python}}==
[[Category:Python]]

'''Interpreter:''' [[Python]] 2.4, 2.5
'''Interpreter:''' [[Python]] 2.4, 2.5


===[[Tkinter]]===
{{library|Tkinter}}

[[Category:Tkinter]]

import Tkinter
import Tkinter
Line 200: Line 174:
w.mainloop()
w.mainloop()


===[[wxPython]]===
{{library|wxPython}}

[[Category:wxPython]]


from wxPython.wx import *
from wxPython.wx import *
Line 216: Line 188:
app.MainLoop()
app.MainLoop()


===[[Pythonwin]]===
{{library|Pythonwin}}

[[Category:Pythonwin]]


import win32ui
import win32ui
Line 226: Line 196:
d.CreateWindow()
d.CreateWindow()


===[[PyGTK]]===
{{library|PyGTK}}

[[Category:PyGTK]]


import gtk
import gtk
Line 236: Line 204:
gtk.main()
gtk.main()


==[[Ruby]]==
=={{header|Ruby}}==
[[Category:Ruby]]

'''Interpreter:''' [[Ruby]] 1.8.5
'''Interpreter:''' [[Ruby]] 1.8.5


{{library|Tk}}
===[[Tk]]===

[[Category:Tk]]

require 'tk'
require 'tk'
Line 250: Line 213:
window::mainloop()
window::mainloop()


{{library|GTK+}}
===[[GTK]]===
require 'gtk2'
require 'gtk2'
Line 256: Line 219:
Gtk.main
Gtk.main


==[[RapidQ]]==
=={{header|RapidQ}}==
[[Category:RapidQ]]

create form as qform
create form as qform
center
center
Line 266: Line 227:
form.showModal
form.showModal


==[[Tcl]]==
=={{header|Tcl}}==
[[Category:Tk]]

Loading the "Tk" package is all that is required to get an initial window:
Loading the "Tk" package is all that is required to get an initial window:


Line 279: Line 238:
If you are using the increasingly popular [http://www.equi4.com/tclkit.html tclkit] under MS Windows, all you have to do is associate the tcklkit with the extension ".tcl" and then create an <i>empty</i> file with the name (e.g.) <tt>nothing.tcl</tt>. Douple-clicking that will "open a window" (an empty one).
If you are using the increasingly popular [http://www.equi4.com/tclkit.html tclkit] under MS Windows, all you have to do is associate the tcklkit with the extension ".tcl" and then create an <i>empty</i> file with the name (e.g.) <tt>nothing.tcl</tt>. Douple-clicking that will "open a window" (an empty one).


==[[Toka]]==
=={{header|Toka}}==
{{library|SDL}}
[[Category:Toka]]

'''Library:''' [[SDL]]
[[Category:SDL]]


Toka does not inherently know about graphical environments, but can interact with
Toka does not inherently know about graphical environments, but can interact with
Line 292: Line 248:
800 600 sdl_setup
800 600 sdl_setup


==[[Visual Basic .NET]]==
=={{header|Visual Basic .NET}}==
[[Category:Visual Basic .NET]]

Framework: [[.NET]]
Dim newForm as new Form
Dim newForm as new Form

Revision as of 01:44, 26 November 2007

Task
Window creation
You are encouraged to solve this task according to the task description, using any language you may know.

C

Standard: ANSI C (AKA C89):

Compiler: gcc 4.0.3

Library
This is an example of a library. You may see a list of other libraries used on Rosetta Code at Category:Solutions by Library.

Compile Command: gcc -lSDL SDL_Window.c -o window

/*
 *   Opens an 800x600 16bit color window. 
 *   Done here with ANSI C.
 */

#include <stdio.h>
#include <stdlib.h>
#include "SDL/SDL.h"

main(){

SDL_Surface *screen;

if (SDL_Init(SDL_INIT_VIDEO) != 0) {
  fprintf(stderr, "Unable to initialize SDL: %s\n", SDL_GetError());
  return(1);
}
atexit(SDL_Quit);
screen = SDL_SetVideoMode( 800, 600, 16, SDL_SWSURFACE | SDL_HWPALETTE );
}

C++

Library
This is an example of a library. You may see a list of other libraries used on Rosetta Code at Category:Solutions by Library.

4

Compiler command: qmake -pro; qmake

#include <QApplication>
#include <QMainWindow>

int main(int argc, char *argv[])
{
 QApplication app(argc, argv);
 QMainWindow window;
 window.show();
 return app.exec();
}
Library
This is an example of a library. You may see a list of other libraries used on Rosetta Code at Category:Solutions by Library.

Compiler command: g++ filename.cc -o test `pkg-config --cflags --libs gtkmm-2.4`

#include <iostream>
#include <gtkmm.h>

int
main( int argc, char* argv[] )
{
 try
 {
  Gtk::Main m( argc, argv ) ;
  Gtk::Window win ;
  m.run( win ) ;
 }
 
 catch( std::exception const & exc )
 {
  std::cout << exc.what() << std::endl ;
  exit( -1 ) ;
 }
 
 exit( 0 ) ;
}

C#

Compiler: Visual C# 2003

Using: System.Windows.Forms.dll

 using System;
 using System.Windows.Forms;
 
 public class Window
 {
   [STAThread]
   static void Main()
   {
     Form newForm = new Form();
     newForm.Text = "It's a new Window!";
     newForm.Show();
   }
 }

E

Java AWT/Swing

Implementation: E-on-Java

when (currentVat.morphInto("awt")) -> {
    def w := <swing:makeJFrame>("Window")
    w.setContentPane(<swing:makeJLabel>("Contents"))
    w.pack()
    w.show()
}

Groovy

 import groovy.swing.SwingBuilder

 new SwingBuilder().frame(title:'My Window', size:[200,100]).show()

IDL

With some example values filled in:

Id = WIDGET_BASE(TITLE='Window Title',xsize=200,ysize=100)
WIDGET_CONTROL, /REALIZE, id


Java

Library: Swing

   import javax.swing.JFrame;
   import javax.swing.WindowConstants;
   
   public class SimpleWindow {
   
   	public static void main(String[] args) {
   
   		JFrame window = new JFrame("This is a title!");
   		
   		window.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
   		window.setSize(800, 600);
   		window.setVisible(true);
   	}
   
   }

JavaScript

   window.open("webpage.html", "windowname", "width=800,height=600");

mIRC Scripting Language

Interpreter: mIRC

Switches: C = Center Window p = Picture Window d = Desktop Window

alias CreateMyWindow {
 .window -Cp +d @WindowName 600 480
}

Perl

Interpreter: Perl 5.8.8

Library
This is an example of a library. You may see a list of other libraries used on Rosetta Code at Category:Solutions by Library.
 use Tk;
 
 $mw = MainWindow->new();
 MainLoop;

Python

Interpreter: Python 2.4, 2.5

Library
This is an example of a library. You may see a list of other libraries used on Rosetta Code at Category:Solutions by Library.
 import Tkinter
 
 w = Tkinter.Tk()
 w.mainloop()
Library
This is an example of a library. You may see a list of other libraries used on Rosetta Code at Category:Solutions by Library.
 from wxPython.wx import *
 
 class MyApp(wxApp):
   def OnInit(self):
     frame = wxFrame(NULL, -1, "Hello from wxPython")
     frame.Show(true)
     self.SetTopWindow(frame)
     return true
 
 app = MyApp(0)
 app.MainLoop()
Library
This is an example of a library. You may see a list of other libraries used on Rosetta Code at Category:Solutions by Library.
 import win32ui
 from pywin.mfc.dialog import Dialog
 
 d = Dialog(win32ui.IDD_SIMPLE_INPUT)
 d.CreateWindow()
Library
This is an example of a library. You may see a list of other libraries used on Rosetta Code at Category:Solutions by Library.
 import gtk
 
 window = gtk.Window()
 window.show()
 gtk.main()

Ruby

Interpreter: Ruby 1.8.5

Library
This is an example of a library. You may see a list of other libraries used on Rosetta Code at Category:Solutions by Library.
require 'tk'

window = TkRoot::new()
window::mainloop()
Library
This is an example of a library. You may see a list of other libraries used on Rosetta Code at Category:Solutions by Library.
require 'gtk2'

window = Gtk::Window.new.show
Gtk.main

RapidQ

  create form as qform
     center
     width=500
     height=400
  end create
  form.showModal

Tcl

Loading the "Tk" package is all that is required to get an initial window:

  package require Tk

If you need an additional window:

  toplevel .top

If you are using the increasingly popular tclkit under MS Windows, all you have to do is associate the tcklkit with the extension ".tcl" and then create an empty file with the name (e.g.) nothing.tcl. Douple-clicking that will "open a window" (an empty one).

Toka

Library
This is an example of a library. You may see a list of other libraries used on Rosetta Code at Category:Solutions by Library.

Toka does not inherently know about graphical environments, but can interact with them using external libraries. This example makes use of the SDL library bindings included with Toka.

needs sdl
800 600 sdl_setup

Visual Basic .NET

   Dim newForm as new Form
   newForm.Text = "It's a new window"
  
       newForm.Show()