IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

AWT/Swing Java Discussion :

Lancer un browser après un clic bouton


Sujet :

AWT/Swing Java

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre confirmé
    Inscrit en
    Décembre 2008
    Messages
    108
    Détails du profil
    Informations forums :
    Inscription : Décembre 2008
    Messages : 108
    Par défaut Lancer un browser après un clic bouton
    Bonjour,

    Je souhaiterais savoir comment lançer simplement un browser en java en lui passant en paramètre de la méthode l'url que je souhaite.

    Dans l'exemple ci-dessous, le but est d'afficher une page google image pour chaque média:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    for (Media a : ListeMedia){
              String link="http://www.google.fr/images?hl=fr&source=imghp&q="+a.getTitre()+"&gbv=2&aq=f&aqi=g1&aql=&oq=&gs_rfai=";
              out.println("<tr><td><center>" + a.getTitre() + "</center></td><td><center>" + a.getResume() + "</center></td><td><center>" + a.getGenre() + "</center></td><td><center><input type=\"submit\" value=\"Voir\" onclick=" + Desktop.browse(link) +"></center></td></tr>");
          }


    Je ne sais pas comment combiner l'action de clic du bouton, et d'ouverture de la page que je souhaite.

    Pour info, le code est le code d'une servlet.

    Merci pour votre aide !

  2. #2
    Expert confirmé
    Avatar de sinok
    Profil pro
    Inscrit en
    Août 2004
    Messages
    8 765
    Détails du profil
    Informations personnelles :
    Âge : 45
    Localisation : France, Paris (Île de France)

    Informations forums :
    Inscription : Août 2004
    Messages : 8 765
    Par défaut
    Merci de chercher dans la FAQ

  3. #3
    Membre confirmé Avatar de bankette
    Homme Profil pro
    Chef de Projet Web
    Inscrit en
    Mars 2007
    Messages
    135
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 39
    Localisation : France, Nord (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Chef de Projet Web
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Mars 2007
    Messages : 135
    Par défaut
    Voici une classe qui te le fait, elle ne fonctionne que pour Mac et Windows mais il ne manque plus gd chose pour Linux.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
     
    package application;
     
    import java.io.IOException;
     
    /**
     *
     * @author
     */
    public class BrowserControl
    {
        /**
         * Display a file in the system browser.  If you want to display a
         * file, you must include the absolute path name.
         *
         * @param url the file's url (the url must start with either "http://"
    or
         * "file://").
         */
     
        // Used to identify the Mac platform.
        private static final String MAC_ID = "Mac";
        // Used to identify the windows platform.
        private static final String WIN_ID = "Windows";
        // The default system browser under windows.
        private static final String WIN_PATH = "rundll32";
        // The flag to display a url.
        private static final String WIN_FLAG = "url.dll,FileProtocolHandler";
        // The default browser under unix.
        private static final String UNIX_PATH = "netscape";
        // The flag to display a url.
        private static final String UNIX_FLAG = "-remote openURL";
     
     
        public static void displayURL(String url)
        {
            boolean windows = isWindowsPlatform();
            boolean mac = isMacPlatform();
            String cmd = null;
            System.out.println("Ouverture de la page "+url);
            try
            {
                if (windows)
                {
                    // cmd = 'rundll32 url.dll,FileProtocolHandler http://...'
                    cmd = WIN_PATH + " " + WIN_FLAG + " " + url;
                    Runtime.getRuntime().exec(cmd);
                }
                else { // Pour Mac
                    cmd = "open " + url;
                    Runtime.getRuntime().exec(cmd);
                }
     
            }
            catch(IOException x)
            {
                // couldn't exec browser
                System.err.println("Could not invoke browser, command=" + cmd);
                System.err.println("Caught: " + x);
            }
        }
        /**
         * Try to determine whether this application is running under Windows
         * or some other platform by examing the "os.name" property.
         *
         * @return true if this application is running under a Windows OS
         */
        public static boolean isWindowsPlatform()
        {
            String os = System.getProperty("os.name");
            if ( os != null && os.startsWith(WIN_ID))
                return true;
            else
                return false;
     
        }
     
        public static boolean isMacPlatform()
        {
            String os = System.getProperty("os.name");
            if ( os != null && os.startsWith(MAC_ID))
                return true;
            else
                return false;
     
        }
     
     
    }

Discussions similaires

  1. Réponses: 3
    Dernier message: 12/07/2010, 22h02
  2. Afficher une élément dans un Canvas après un clic sur un bouton
    Par D-Day dans le forum Windows Presentation Foundation
    Réponses: 3
    Dernier message: 28/02/2010, 19h39
  3. [JList] Colorer lignes selectionnées après clic bouton
    Par M€lK!oR dans le forum Composants
    Réponses: 15
    Dernier message: 27/01/2009, 19h50
  4. Formulaire : Bloquer un bouton après un clic
    Par FRMIP dans le forum IHM
    Réponses: 3
    Dernier message: 22/01/2008, 19h42
  5. afficher une autre page apres le clic d1 bouton submit
    Par tramacere dans le forum Langage
    Réponses: 7
    Dernier message: 25/01/2006, 16h00

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo