Jean-Louis
PATANÉ

jlp photo

[ CV ]

trefle
Fondation de la Vocation

Les Pages Web
Les Pages Web

Mailto
m'écrire

NETSCAPE 2
il y a longtemps...

worldnet
mon ISP 1996-2002 Worldnet
 
maintenant chez
free
mon ISP 2002 FREE



accueil sites java faq vocation jeux musique bouquins photos

Quelques FAQ

embauchez moi... (CV)

dernière mise à jour de ce trop vieux site : le 27 Octobre 2005

Internet permet à tous de poser des questions via newsgroup ou mailinglist et je tente parfois d'apporter ma modeste contribution, car il ne faut pas se contenter de toujours recevoir...
Voici quelques-unes de mes réponses :


Newsgroups : comp.lang.java.programmer
Subject : Binary Trees: Possible in Java ?

Hi, I'm a new Java programmer, and I need to know how to implement binary trees in java, if it is possible. Since java doesn't use pointers, I don't know how to go about accomplishing this. It would make things alot easier than having to do it in C++, and then running that code through the java applet. Any information would be greatly appreciated.

ma réponse :

Hi

Here's such an example : think about references just as pointers ;-)

import java.awt.*;
import java.io.IOException ;

public class TEST
   {
   public static void main(String args[])
      {
      TREE tree = new TREE
         (
         "delta",
         new TREE
            (
            "bravo",
            new TREE("alpha"),
            new TREE("charlie")
            ),
         new TREE
            (
            "foxtrot",
            new TREE("echo"),
            new TREE("golf")
            )
         ) ;
      System.out.println("simple test about binary tree");
      tree.print() ;
      wait_for_enter() ;
      }
   static void wait_for_enter()
      {
      System.out.println("(press Enter to exit)");
      try
         {
         System.in.read() ;
         }
      catch (IOException e)
         {
         return;
         }
      }
   }

class TREE
   {
   TREE left ;
   TREE right ;
   String data ;
   TREE(String _data, TREE _left, TREE _right)
      {
      left = _left ;
      right = _right ;
      data = _data ;
      }
   TREE(String _data)
      {
      left = null ;
      right = null ;
      data = _data ;
      }
   private void _print(String margin)
      {
      if (left != null)
         {
         left._print(margin + ".  ") ;
         }
      System.out.println(margin + data) ;
      if (right != null)
         {
         right._print(margin + ".  ") ;
         }
      }
   void print()
      {
      _print(".  ") ;
      }
   } ;

The result of running this program :

simple test about binary tree
.  .  .  alpha
.  .  bravo
.  .  .  charlie
.  delta
.  .  .  echo
.  .  foxtrot
.  .  .  golf
(press Enter to exit)

Hope it helps...

regards

retour aux choix


Newsgroups : comp.lang.java.programmer
Subject : Color Filter for changing the tint of pictures ?

Hello,

I am new to Java programming and was wondering if Java contains the capabilities to change the tint of a picture that is being displayed.

For instance if there is a picture of the sky and some trees and the sky appears blue. Is there a way for me to make the sky (and tree if need be) red without loading an edited graphic?

Any help would be greatly appreciated.

ma réponse :

Hi

Instead of load directly the image :

Image myImage = getImage(getCodeBase(),"myimage.jpg") ;

use a FilteredImageSource :

ImageFilter filter = new MyImageFilter() ;
Image myImage = createImage(new FilteredImageSource(
   getImage(getCodeBase(),"myimage.jpg").getSource(),filter));

with such a FilteredImageSource class :

class MyImageFilter extends RGBImageFilter
   {
   public MyImageFilter()
      {
      // true if you are pixel independant
      canFilterIndexColorModel = true ;
      }

   public int filterRGB(int x, int y, int rgb)
      {
      int transparent = (rgb & 0xff000000) >>> 24 ;
      int red = (rgb & 0x00ff0000) >>> 16 ;
      int green = (rgb & 0x0000ff00) >>> 8 ;
      int blue = (rgb & 0x000000ff) ;

      // do what you want with the values...

      return (transparent << 24) | (red << 16 ) | (green << 8) | blue ;
      }
   } ;

Of course, don't forget to draw your image ;-)

class MyApplet...

   public void paint(Graphics g)
      {
      g.drawImage(myImage,0,0,this) ;
      }

I use it and it works well.

regards.

retour aux choix


Mailinglist : java@u-strasbg.fr
Subject : Lire dans un fichier ?

Salut,

j'ai une applet qui doit lire un fichier et quand j'accède au fichier, il me fait une read violation error.

Je suis sur Mac et l'applet se trouve en local sur le disque.

Une idée ?

Merci d'avance

ma réponse :

(remarque : dans les exemples suivants, j'ai viré la gestion d'exception pour la lisibilité)

- sous AppletViewer, ou avec un navigateur, en mode local :

   String path ;

   flux = new DataInputStream
      (
      new BufferedInputStream
         (
         new FileInputStream(path)
         )
      ) ;

- si l'Applet est lancée par un navigateur, et le fichier est sur le serveur :

   String path ;

   flux = new DataInputStream
      (
      new BufferedInputStream
         (
         (new URL(getCodeBase(),path)).openStream()
         )
      ) ;

(cette seconde méthode fonctionne aussi en local)

Bonne chance
A++

retour aux choix


Mailinglist : java@u-strasbg.fr
Subject : Charger une page html dans le browser ?

Bonjour,

Je cherche comment on peut, dans une applet, ouvrir une connection avec un URL et rediriger le flux reçu sur la fenêtre du browser (et non dans l'applet).

Merci.

ma réponse :

Bonjour

Je ne sais pas si c'est ainsi qu'il faut faire, mais c'est ainsi que je fais... ;-)

public class MY_APPLET extends java.applet.Applet
   {
   ...

   private void goto_document(String txt)
      {
      URL url = null ;
      try
         {
         url = new URL(txt) ;
         getAppletContext().showDocument(url,"_top") ;
         }
      catch (MalformedURLException e)
         {
         getAppletContext().showStatus("URL == " + txt + " ???") ;
         }
      }

   ...
   }

Bon courage
A++

retour aux choix


Mailinglist : java@u-strasbg.fr
Subject : Comment fermer la fenêtre de l'application ?

Bonjour à tous,

Etant nouveau au langage JAVA, j'ai créé ma première application (avec un void main), mais malheureusement je n'arrive pas à fermer ma fenêtre lorsque je clique sur le signe en croix (dans les icônes de Windows en haut à droite)

Pourriez-vous me fournir le code qui permet cette fermeture de fenêtre ?

ma réponse :

Bonjour.

Il faut juste ne pas oublier de traiter l'événement Event.WINDOW_DESTROY :

import java.awt.*;

public class MyFrame extends Frame
   {

   public MyFrame()
      {
      super("mon programme") ;
      resize(200,200) ;
      show();
      }

   public boolean handleEvent(Event event)
      {
      if (event.id == Event.WINDOW_DESTROY)
         {
         System.exit(0) ;
         }
      return super.handleEvent(event) ;
      }

   public static void main(String args[])
      {
      new MyFrame() ;
      }

   }

C'est tout...
A++

retour aux choix


accueil sites java faq vocation jeux musique bouquins photos

...