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

NetBeans Java Discussion :

NetBeans et Swing Application framework


Sujet :

NetBeans Java

  1. #1
    Membre averti
    Inscrit en
    Juin 2003
    Messages
    292
    Détails du profil
    Informations forums :
    Inscription : Juin 2003
    Messages : 292
    Points : 317
    Points
    317
    Par défaut NetBeans et Swing Application framework
    Bonjour,
    J ai une question assez simple.
    Lorsqu on fait une application Graphique sous NetBeans utilisant the Swing Application framework 1.0.3.
    Ton application :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
     
    public class MyApplication extends SingleFrameApplication {
    .....
        public static void main(String[] args) {
            launch(MyApplication.class, args);
        }
    ....
    }
    et Apres il y a la vue
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
     
     */
    public class MyApplicationView extends FrameView {
        .....
        public MyApplicationView(SingleFrameApplication app) {
        }
    ......
    }
    Ma question est simple comment je recupere les args passe a mon main dans mon View.
    Je crois qu il y a un moyen simple des les recuperer depuis le context de l SingleFrameApplication mais je ne trouve pas.

    N hesitez pas si vous avez des suggestions,

    Merci

  2. #2
    Membre éprouvé

    Profil pro
    Inscrit en
    Janvier 2005
    Messages
    733
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2005
    Messages : 733
    Points : 1 119
    Points
    1 119
    Par défaut
    L'une des suggestions serait de faire des arguments un attribut accessible de la classe application.

    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
     
     
     
    public class MyApplication extends SingleFrameApplication {
     
        String[] arguments;
        public String[] getArgs(){
          return arguments;
    }
             @Override protected void initialize(java.lang.String[] args){
            arguments=args;
    }
    .....
        public static void main(String[] args) {
            launch(MyApplication.class, args);
        }
    ....
    }
    public class MyApplicationView extends FrameView {
        .....
        public MyApplicationView(SingleFrameApplication app) {
            app.getArgs();
        }
    ......
    }

  3. #3
    Membre averti
    Inscrit en
    Juin 2003
    Messages
    292
    Détails du profil
    Informations forums :
    Inscription : Juin 2003
    Messages : 292
    Points : 317
    Points
    317
    Par défaut
    Citation Envoyé par Tarul Voir le message
    L'une des suggestions serait de faire des arguments un attribut accessible de la classe application.

    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
     
     
     
    public class MyApplication extends SingleFrameApplication {
     
        String[] arguments;
        public String[] getArgs(){
          return arguments;
    }
             @Override protected void initialize(java.lang.String[] args){
            arguments=args;
    }
    .....
        public static void main(String[] args) {
            launch(MyApplication.class, args);
        }
    ....
    }
    public class MyApplicationView extends FrameView {
        .....
        public MyApplicationView(SingleFrameApplication app) {
            app.getArgs();
        }
    ......
    }
    Merci pour la suggestion, mais je suis certain qu il y a un moyen beaucoup plus simple. Ou bien ils n ont pas pense a la possibilite de passer des args dans une UI application.
    Je vais faire plus de recherche, je vous tiens au courant.

  4. #4
    Membre averti
    Inscrit en
    Juin 2003
    Messages
    292
    Détails du profil
    Informations forums :
    Inscription : Juin 2003
    Messages : 292
    Points : 317
    Points
    317
    Par défaut
    @Tarul
    tu as raison il n y a pas moyen de faire sans override initialize(String[] args) function.
    Voila le code source de protected void initialize(String[] args)

    org.jdesktop.application.Application
    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
     
    /**
         * Responsible for initializations that must occur before the
         * GUI is constructed by {@code startup}.
         * <p/>
         * This method is called by the static {@code launch} method,
         * before {@code startup} is called. Subclasses that want
         * to do any initialization work before {@code startup} must
         * override it.  The {@code initialize} method
         * runs on the event dispatching thread.
         * <p/>
         * By default initialize() does nothing.
         *
         * @param args the main method's arguments.
         * @see #launch
         * @see #startup
         * @see #shutdown
         */
        protected void initialize(String[] args) {
            if (!Beans.isDesignTime()) {
                /* Initialize the UIManager lookAndFeel property with the
                 * Application.lookAndFeel resource.  If the the resource
                 * isn't defined we default to "system".
                 */
                String key = "Application.lookAndFeel";
                String lnfResource = getContext().getResourceMap().getString(key);
                String lnf = (lnfResource == null) ? "system" : lnfResource;
                try {
                    if (lnf.equalsIgnoreCase("system")) {
                        String name = UIManager.getSystemLookAndFeelClassName();
                        UIManager.setLookAndFeel(name);
                    } else if (!lnf.equalsIgnoreCase("default")) {
                        UIManager.setLookAndFeel(lnf);
                    }
                }
                catch (Exception e) {
                    String s = "Couldn't set LookandFeel " + key + " = \"" + lnfResource + "\"";
                    logger.log(Level.WARNING, s, e);
                }
            }
        }

Discussions similaires

  1. Réponses: 1
    Dernier message: 29/07/2008, 08h46
  2. Swing Application Framework API (JSR-296)
    Par Mister-Joker dans le forum AWT/Swing
    Réponses: 2
    Dernier message: 06/11/2007, 02h05
  3. Réponses: 1
    Dernier message: 17/10/2007, 18h00
  4. Conseils pour le Swing Application Framework
    Par gifffftane dans le forum AWT/Swing
    Réponses: 12
    Dernier message: 17/09/2007, 16h52

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