III. Exemple de coloration des codes▲
III-A. CSS▲
Sélectionnez
/* définition du style de la police, et largeur du select */
select {
font-family : Courier ;
font-size : 10px ;
width : 200px;
}
/* élément de couleur bleu */
option.bl_eu
{
color : #0000FF ;
background-color :#00CCFF ;
background : blue url(img.png) ;
background-color : blue ;
background-image : url(img.png) ;
}III-B. Delphi et Delphi pour .NET▲
Sélectionnez
// commentaire
{
Un commentaire sur
plusieurs lignes }
{$ une directive }
Var i:Integer;
(*
Et un autre
*)
begin
For i:=Onglet.PageCount-1 DownTo 0 Do
Begin
Onglet.ActivePageIndex:=i;
// En commentaire d ON ' euuuuuu
ShowMessage('Truc muche !'kqjhsd'jhkjh''''''hghg''''hg'); // c'est un comment !
{ et un autre }
FileName:= 'Document.doc'; // ou 'Document.rtf'
URL ='http://toto.com';
End;
end;III-C. JAVA▲
Sélectionnez
// un comment en deb
public class MaClasse{
public static Map uneVariableStatique = new HashMap();
static{
/* uneVariableStatique.put("une clef","une valeur");
uneVariableStatique.put("une autre clef","une autre http:// jshdjshd");*/
//etc un comment et import
uneVariableStatique.put("une clef","une http://valeur");
uneVariableStatique.put("une autre clef","une autr\"e valeur\\\"");
qal.declareImports("import com.unilog.data.Track");
import toto;
}
}III-D. Perl▲
III-E. PHP▲
III-F. XML▲
Sélectionnez
<?xml version="1.0" encoding="ISO-8859-1"?>
<document>
<xiti>
<!-- compteur Dotnet-->
<alias>Dotnet</alias>
<logg_er>logv99</logg_er>
<id>12345</id>
</xiti>
</document>III-G. HTML▲
III-H. PYTHON▲
Sélectionnez
class Personne:
def __init__(self, nom, prenom):
self.nom = nom
self.prenom = prenom
def presenter(self) :
return self.nom + " " + self.prenom
class Etudiant(Personne):
def __init__(self, niveau, nom, prenom):
Personne.__init__(self, nom, prenom)
self.niveau = niveau
def presenter(self):
return self.niveau + " " + Personne.presenter(self)
e = Etudiant("Licence INFO", "Dupontel", "Albert")
assert e.nom == "Dupontel"III-I. DELPHI▲
Sélectionnez
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs;
type
TForm1 = class(TForm)
private
{ Déclarations privées }
public
{ Déclarations publiques }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
end.III-J. PASCAL▲
Sélectionnez
unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, LResources, Forms, Controls, Graphics, Dialogs, StdCtrls;
type
{ TForm1 }
TForm1 = class (TForm)
Label1: TLabel; { le label "Hello world!" posé sur la fenêtre }
private
{ private declarations }
public
{ public declarations }
end;
var
Form1: TForm1;
implementation
initialization
{$I unit1.lrs}
end.III-K. Perl again▲
Perl/Tk
Sélectionnez
#!/usr/bin/perl
use warnings;
use strict;
use Tk;
use Tk::TableMatrix;
use utf8;
my $mw = MainWindow->new(
-title => 'Tableau TableMatrix',
-background => 'snow',
);
$mw->Label(
-text => "Tableau redimensionnable à l'aide de TableMatrix",
-background => 'snow',
-font => '{arial} 12 bold'
)->pack( -pady => 5 );
my $data = {};
# Création du tableau avec une ligne et une colonne
my $table = $mw->Scrolled(
'TableMatrix',
-rows => 1,
-cols => 1,
-width => 500,
-height => 500,
-variable => $data,
-rowtagcommand => \&type_row,
-background => "#454545",
-titlerows => 1,
-titlecols => 1,
-drawmode => 'single',
-selectmode => 'extended',
-scrollbars => 'osoe',
);
# Insertion de données dans le tableau
for my $row ( 0 .. 20 ) {
# Calcul du nombre de lignes dans le tableau
my $number_rows = $table->cget( -rows );
# Insertion d'une ligne si nécessaire
$table->insertRows( 'end', 1 ) if ( $number_rows < $row + 1 );
for my $col ( 0 .. 10 ) {
# Calcul du nombre de lignes dans le tableau
my $number_cols = $table->cget( -cols );
# Insertion d'une colonne si nécessaire
$table->insertCols( 'end', 1 ) if ( $number_cols < $col + 1 );
# Ligne de titre
if ( $row == 0 and $col != 0 ) {
$data->{"$row,$col"} = "Colonne $col";
}
# Colonne de titre
elsif ( $col == 0 and $row != 0 ) {
$data->{"$row,$col"} = "Ligne $row";
}
elsif ( $col == 0 and $row == 0 ) {
# rien ne se passe;
}
# Données
else {
$data->{"$row,$col"} = "($row,$col)";
}
}
}
# Configuration des lignes paires et impaires
$table->tagConfigure(
'pair_row',
-bg => 'white',
-fg => 'black',
-relief => 'sunken',
-state => 'disabled'
);
$table->tagConfigure(
'impair_row',
-bg => '#00C0E0',
-fg => 'black',
-relief => 'sunken',
-state => 'disabled'
);
$table->tagConfigure( 'title', -bg => '#F0E0FF', -fg => 'black', -relief => 'sunken' );
# Fusion des cellules 1,1 à 1,4
$table->spans( '1,1' => '0,3' );
$table->pack(qw/ -fill both -expand 1 -padx 10 -pady 10 /);
MainLoop;
# Permet d'assigner un tag aux lignes paires et impaires
sub type_row {
my $row = shift;
my $tag_row = ( $row > 0 && $row % 2 == 0 ) ? "pair_row" : "impair_row";
return $tag_row;III-L. SQL - code long▲
Création des tables
Sélectionnez
# On supprime les tables si elles existent déjà
DROP TABLE POSITION ;
DROP TABLE FICHIER;
DROP TABLE VERSION;
# On crée les tables en ajoutant des contraintes de colonnes et de tables afin d'être sûr de garder une table valide quoi qu'il se passe.
CREATE TABLE VERSION (id MEDIUMINT PRIMARY KEY AUTO_INCREMENT, Version VARCHAR(20) NOT NULL, Active CHAR(1) NOT NULL CHECK Active IN ('O', 'N'), CHECK(Version <> '0')) ;
CREATE TABLE FICHIER (id MEDIUMINT PRIMARY KEY AUTO_INCREMENT, Version_creation MEDIUMINT NOT NULL REFERENCES VERSION.id, Version_suppression MEDIUMINT REFERENCES VERSION.id, Version_maj MEDIUMINT REFERENCES VERSION.id, Version_futur_maj MEDIUMINT REFERENCES VERSION.id, Source VARCHAR(200), CHECK(Version_suppression IS NULL OR Version_suppression > Version_creation), CHECK((Version_suppression IS NOT NULL AND Version_maj IS NULL) OR Version_suppression IS NULL), CHECK (Version_maj IS NULL OR Version_maj > Version_creation), CHECK((Source IS NULL AND Version_maj IS NULL AND Version_futur_maj IS NULL) OR Source IS NOT NULL)) ;
CREATE TABLE POSITION (id_Fichier MEDIUMINT NOT NULL REFERENCES FICHIER.id, id_Version MEDIUMINT NOT NULL REFERENCES VERSION.id, Nom VARCHAR(100) NOT NULL, id_dossier MEDIUMINT REFERENCES FICHIER.id, Derniere_position CHAR(1) NOT NULL CHECK Derniere_position IN ('O', 'N', 'T', 'P'), PRIMARY KEY(id_Fichier, id_Version), CHECK(id_Fichier <> id_dossier));
# On crée la version 0 (version vide)
INSERT INTO VERSION VALUES('', '0', 'O');III-M. JSON et JavaScript▲
javascript
Sélectionnez
var sum = function() {
var i, x = 0;
for (i = 0; i < arguments.length; ++i) {
x += arguments[i];
}
return x;
}
sum(1, 2, 3); // returns 6json
Sélectionnez
{
"firstName": "John",
"lastName": "Smith",
"isAlive": true,
"age": 25,
"address": {
"streetAddress": "21 2nd Street",
"city": "New York",
"state": "NY",
"postalCode": "10021-3100"
},
"phoneNumbers": [
{
"type": "home",
"number": "212 555-1234"
},
{
"type": "office",
"number": "646 555-4567"
}
],
"children": [],
"spouse": null
}


