Faire un don ! | | style | statistiques | contactez-nous | plan | lettre d'information

Programmation.java : GCJ/GIJ + AWT

Posté par j (page perso, ) le 27 septembre 2005
C'est la première fois que j'essaye d'utiliser gcj/gij et je connais très peu java.



Voici un petit code source tiré de LinuxJournal :



import java.awt.*;

import java.awt.event.*;



public class ExampleAWT extends Frame {

ExampleAWT() {

super("AWT");



Label msgLabel = new Label("Quit?");

Button yesButton = new Button("Yes");

Button noButton = new Button("No");



Panel buttonbox = new Panel();

buttonbox.setLayout(new FlowLayout());

buttonbox.add(yesButton);

buttonbox.add(noButton);



Panel msgbox = new Panel();

msgbox.setLayout(new FlowLayout());

msgbox.add(msgLabel);



add(msgbox, BorderLayout.NORTH);

add(buttonbox, BorderLayout.SOUTH);



yesButton.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) { System.exit(0); }

});



noButton.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) { System.exit(1); }

});



addWindowListener(new WindowAdapter() {

public void windowClosing(WindowEvent e) {

System.exit(0);

}

});

}



public static void main(String[] args) {

ExampleAWT frame = new ExampleAWT();

frame.pack();

frame.setVisible(true);

}

}




Le programme se compile bien à priori :



gcj -C ExampleAWT.java me fabrique un ExampleAWT.class mais quand je le passe à GIJ, ce dernier apprécie peu :



jerome@glop:~/prog$ gij ExampleAWT

Exception in thread "main" java.awt.AWTError: Cannot load AWT toolkit: gnu.awt.gtk.GtkToolkit not found in [file:./, core:/]

at java.awt.Toolkit.getDefaultToolkit() (/usr/lib/libgcj.so.4.0.0)

at java.awt.Component.getToolkit() (/usr/lib/libgcj.so.4.0.0)

at java.awt.Container.addImpl(java.awt.Component, java.lang.Object, int) (/usr/lib/libgcj.so.4.0.0)

at java.awt.Container.add(java.awt.Component) (/usr/lib/libgcj.so.4.0.0)

at ExampleAWT.ExampleAWT() (Unknown Source)

at ExampleAWT.main(java.lang.String[]) (Unknown Source)



Idem pour la compilation en natif :



jerome@glop:~/prog$ gcj --main=ExampleAWT -o ExampleAWT ExampleAWT.java

jerome@glop:~/prog$ ./ExampleAWT

Exception in thread "main" java.awt.AWTError: Cannot load AWT toolkit: gnu.awt.gtk.GtkToolkit not found in [file:./, core:/]

at java.awt.Toolkit.getDefaultToolkit() (/usr/lib/libgcj.so.4.0.0)

at java.awt.Component.getToolkit() (/usr/lib/libgcj.so.4.0.0)

at java.awt.Container.addImpl(java.awt.Component, java.lang.Object, int) (/usr/lib/libgcj.so.4.0.0)

at java.awt.Container.add(java.awt.Component) (/usr/lib/libgcj.so.4.0.0)

at ExampleAWT.ExampleAWT() (Unknown Source)

at ExampleAWT.main(java.lang.String[]) (Unknown Source)



libgcj4-awt est installé. Manque t il quelque chose ? GIJ se définit comme un interpréteur ; peut on le considérer comme l'équivalent de la machine virtuelle java ? GIJ peut il executer certaines applets que l'on rencontre sur le web ?



jerome@glop:~/prog$ java -version

gij (GNU libgcj) version 3.3.5 (Debian 1:3.3.5-13)



Copyright (C) 2002 Free Software Foundation, Inc.

This is free software; see the source for copying conditions. There is NO

warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.



Et, spécial Debian :



jerome@glop:~/prog$ dpkg -S /usr/bin/java

dpkg : /usr/bin/java introuvable.



Merci pour vos réponses.

> Lire le message (2 commentaires, moyenne: 1,5).  

Vous avez demandé le commentaire #630235.

/usr/bin/java

Posté par Mickaël L () le 27/09/2005 à 22:35. (lien). Évalué à 2.

Je peuxpas t'aider pour le reste, mais

> jerome@glop:~/prog$ dpkg -S /usr/bin/java
> dpkg : /usr/bin/java introuvable.

c'est parce que /usr/bin/java est un lien vers /etc/alternative, créé par un script de post-install, et n'appartient à aucun fichier.

Pour savoir ce qui est utilisé par la commande "java", il faut regarder ou pointe /etc/alternative/java