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

avec Java Discussion :

Probleme de débutant avec une class


Sujet :

avec Java

  1. #1
    Membre confirmé Avatar de hugoclo
    Profil pro
    Inscrit en
    Décembre 2007
    Messages
    615
    Détails du profil
    Informations personnelles :
    Âge : 48
    Localisation : France, Var (Provence Alpes Côte d'Azur)

    Informations forums :
    Inscription : Décembre 2007
    Messages : 615
    Points : 480
    Points
    480
    Par défaut Probleme de débutant avec une class
    Bonsoir,
    J'ai une petite appli qui contient plusieurs class dont celle ci
    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
    import java.awt.BasicStroke;
    import java.awt.Color;
    import java.awt.Graphics2D;
    import java.awt.Rectangle;
    import java.awt.RenderingHints;
    import java.awt.geom.Point2D;
    import java.util.ArrayList;
    import java.util.List;
     
    import javax.swing.JFrame;
     
    import org.jdesktop.swingx.JXMapKit;
    import org.jdesktop.swingx.JXMapKit.DefaultProviders;
    import org.jdesktop.swingx.JXMapViewer;
    import org.jdesktop.swingx.mapviewer.GeoPosition;
    import org.jdesktop.swingx.painter.*;
     
    public class Starter {
        public static void main(final String[] args) {    
            final JFrame f = new JFrame();
            f.setSize(500, 300);
            f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
     
            final JXMapKit jXMapKit1 = new JXMapKit();
            jXMapKit1.setDefaultProvider(DefaultProviders.OpenStreetMaps);
            jXMapKit1.setCenterPosition(new GeoPosition(5.41984, 100.33924));
            jXMapKit1.setZoom(3);
     
            final List<GeoPosition> region = new ArrayList<GeoPosition>();
            region.add(new GeoPosition(5.42031, 100.34389));
            region.add(new GeoPosition(5.41984, 100.33924));
            region.add(new GeoPosition(5.42300, 100.33456));
     
            final Painter<JXMapViewer> lineOverlay = new Painter<JXMapViewer>() {
     
                            public void paint(Graphics2D g, final JXMapViewer map, final int w, final int h) {
                    g = (Graphics2D) g.create();
                    // convert from viewport to world bitmap
                    final Rectangle rect = jXMapKit1.getMainMap().getViewportBounds();
                    g.translate(-rect.x, -rect.y);
     
                    // do the drawing
                    g.setColor(Color.RED);
                    g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
                    g.setStroke(new BasicStroke(2));
     
                    int lastX = -1;
                    int lastY = -1;
                    for (final GeoPosition gp : region) {
                        // convert geo to world bitmap pixel
                        final Point2D pt = jXMapKit1.getMainMap().getTileFactory().geoToPixel(gp, jXMapKit1.getMainMap().getZoom());
                        if (lastX != -1 && lastY != -1) {
                            g.drawLine(lastX, lastY, (int) pt.getX(), (int) pt.getY());
                        }
                        lastX = (int) pt.getX();
                        lastY = (int) pt.getY();
                    }
     
                    g.dispose();
     
                }
     
            };
     
            jXMapKit1.getMainMap().setOverlayPainter(lineOverlay);
     
            f.setContentPane(jXMapKit1);
            f.setVisible(true);
     
        }
    }
    Comment faire pour "lancer" cette class en cliquant sur un bouton d'une autre class en lui envoyant le contenu d"un Jtextarea.

  2. #2
    Membre averti
    Homme Profil pro
    Étudiant
    Inscrit en
    Mai 2011
    Messages
    442
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Mai 2011
    Messages : 442
    Points : 417
    Points
    417
    Par défaut
    euh...

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    monBouton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            String T[] = {monTextArea.getText()};
            Starter.main(T);
        }
    }
    Mais je sais pas si c'est ça que tu cherches.

  3. #3
    Membre confirmé Avatar de hugoclo
    Profil pro
    Inscrit en
    Décembre 2007
    Messages
    615
    Détails du profil
    Informations personnelles :
    Âge : 48
    Localisation : France, Var (Provence Alpes Côte d'Azur)

    Informations forums :
    Inscription : Décembre 2007
    Messages : 615
    Points : 480
    Points
    480
    Par défaut
    Oui bien pris mais je me suis mal exprimé.
    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
    import java.awt.BorderLayout;
    import java.util.ArrayList;
    import java.util.HashSet;
    import java.util.List;
    import javax.swing.JComponent;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import javax.swing.SwingUtilities;
    import org.jdesktop.swingx.JXMapKit;
    import org.jdesktop.swingx.JXMapViewer;
    import org.jdesktop.swingx.mapviewer.DefaultTileFactory;
    import org.jdesktop.swingx.mapviewer.DefaultWaypoint;
    import org.jdesktop.swingx.mapviewer.GeoPosition;
    import org.jdesktop.swingx.mapviewer.TileFactoryInfo;
    import org.jdesktop.swingx.mapviewer.Waypoint;
    import org.jdesktop.swingx.mapviewer.WaypointPainter;
     
    public class WSDemo {
        double lat,longi;
        class CustomPainter extends WaypointPainter<JXMapViewer> {
        public void setWaypoints(List<? extends Waypoint> waypoints) {
            super.setWaypoints(new HashSet<Waypoint>(waypoints));
        }
    }
        private JComponent createContent() {
            JComponent content = new JPanel();
            content.setLayout(new BorderLayout());
     
            content.add(createMapKit());
            return content;
        }
     
        protected JComponent createMapKit() {
            final int max = 17;
            TileFactoryInfo info = new TileFactoryInfo(1, max - 2, max, 256, true,
                    true, // tile size is 256 and x/y orientation is normal
                    "file:/D:/Tiles",// 5/15/10.png",
                    "x", "y", "z") {
                public String getTileUrl(int x, int y, int zoom) {
                    zoom = max - zoom;
                    String url = this.baseURL + "/" + zoom + "/" + x + "/" + y
                            + ".png";
                    System.out.print(url + "\n");
                    return url;
                }
     
            };
            DefaultTileFactory tf = new DefaultTileFactory(info);
            tf.setThreadPoolSize(1);
            final JXMapKit kit = new JXMapKit();
            kit.setTileFactory(tf);
            kit.setZoom(12);
            kit.setAddressLocation(new GeoPosition(48, -3));
            kit.getMainMap().setDrawTileBorders(true);
            List<DefaultWaypoint> waypoints = new ArrayList<DefaultWaypoint>();
            waypoints.add(new DefaultWaypoint(51.5, -3));
            waypoints.add(new DefaultWaypoint(48, -5));
            CustomPainter painter = new CustomPainter();
            painter.setWaypoints(waypoints);
            kit.getMainMap().setOverlayPainter(painter);
            return kit;
        }
     
        public static void main(String[] args) {
     
            SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    JFrame frame = new JFrame("");
                    frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
                    frame.add(new WSDemo().createContent());
                    frame.setLocationByPlatform(true);
                    frame.setSize(900, 900);
                    frame.setVisible(true);
                }
            });
        }
     
    }
    mon args est un tableau contenant des coordonnée.
    Et j'ai besoin de ces coordonnées ici
    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
      protected JComponent createMapKit() {
            final int max = 17;
            TileFactoryInfo info = new TileFactoryInfo(1, max - 2, max, 256, true,
                    true, // tile size is 256 and x/y orientation is normal
                    "file:/D:/Tiles",// 5/15/10.png",
                    "x", "y", "z") {
                public String getTileUrl(int x, int y, int zoom) {
                    zoom = max - zoom;
                    String url = this.baseURL + "/" + zoom + "/" + x + "/" + y
                            + ".png";
                    System.out.print(url + "\n");
                    return url;
                }
     
            };
            DefaultTileFactory tf = new DefaultTileFactory(info);
            tf.setThreadPoolSize(1);
            final JXMapKit kit = new JXMapKit();
            kit.setTileFactory(tf);
            kit.setZoom(12);
            kit.setAddressLocation(new GeoPosition(48, -3));
            kit.getMainMap().setDrawTileBorders(true);
            List<DefaultWaypoint> waypoints = new ArrayList<DefaultWaypoint>();
           //boucle ici
            waypoints.add(new DefaultWaypoint(51.5, -3));
            waypoints.add(new DefaultWaypoint(48, -5));
            CustomPainter painter = new CustomPainter();
            painter.setWaypoints(waypoints);
            kit.getMainMap().setOverlayPainter(painter);
            return kit;
        }
    Comme ca je fait une petite boucle sur mon tableau est je crée des Waypoints. Comment faire pour accéder au items de args.

  4. #4
    Modérateur

    Profil pro
    Inscrit en
    Septembre 2004
    Messages
    12 567
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Septembre 2004
    Messages : 12 567
    Points : 21 635
    Points
    21 635
    Par défaut
    Le plus simple est de le garder (sous forme de String[] par exemple) dans un champ de la classe WSDemo, et de le renseigner dans son constructeur.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    public class WSDemo {
        double lat,longi;
        String[] args;
     
        public WSDemo(String[] args) {
          this.args = args;
        }

  5. #5
    Membre confirmé Avatar de hugoclo
    Profil pro
    Inscrit en
    Décembre 2007
    Messages
    615
    Détails du profil
    Informations personnelles :
    Âge : 48
    Localisation : France, Var (Provence Alpes Côte d'Azur)

    Informations forums :
    Inscription : Décembre 2007
    Messages : 615
    Points : 480
    Points
    480
    Par défaut
    Merci pour la rapidité
    J'ai fait comme indiqué
    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
    package modif.posit;
     
    import java.awt.BorderLayout;
    import java.util.ArrayList;
    import java.util.HashSet;
    import java.util.List;
    import javax.swing.JComponent;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import javax.swing.SwingUtilities;
    import org.jdesktop.swingx.JXMapKit;
    import org.jdesktop.swingx.JXMapViewer;
    import org.jdesktop.swingx.mapviewer.DefaultTileFactory;
    import org.jdesktop.swingx.mapviewer.DefaultWaypoint;
    import org.jdesktop.swingx.mapviewer.GeoPosition;
    import org.jdesktop.swingx.mapviewer.TileFactoryInfo;
    import org.jdesktop.swingx.mapviewer.Waypoint;
    import org.jdesktop.swingx.mapviewer.WaypointPainter;
     
    public class WSDemo {
        double lat,longi;
        String[] args;
        class CustomPainter extends WaypointPainter<JXMapViewer> {
        public void setWaypoints(List<? extends Waypoint> waypoints) {
            super.setWaypoints(new HashSet<Waypoint>(waypoints));
        }
    }
        private JComponent createContent() {
            JComponent content = new JPanel();
            content.setLayout(new BorderLayout());
     
            content.add(createMapKit());
            return content;
        }
     
        protected JComponent createMapKit() {
            final int max = 17;
            TileFactoryInfo info = new TileFactoryInfo(1, max - 2, max, 256, true,
                    true, // tile size is 256 and x/y orientation is normal
                    "file:/D:/Tiles",// 5/15/10.png",
                    "x", "y", "z") {
                public String getTileUrl(int x, int y, int zoom) {
                    zoom = max - zoom;
                    String url = this.baseURL + "/" + zoom + "/" + x + "/" + y
                            + ".png";
                    System.out.print(url + "\n");
                    return url;
     
                }
     
            };
            DefaultTileFactory tf = new DefaultTileFactory(info);
            tf.setThreadPoolSize(1);
            final JXMapKit kit = new JXMapKit();
            kit.setTileFactory(tf);
            kit.setZoom(12);
            kit.setAddressLocation(new GeoPosition(48, -3));
            kit.getMainMap().setDrawTileBorders(true);
            List<DefaultWaypoint> waypoints = new ArrayList<DefaultWaypoint>();
            waypoints.add(new DefaultWaypoint(51.5, -3));
            waypoints.add(new DefaultWaypoint(48, -5));
            CustomPainter painter = new CustomPainter();
            painter.setWaypoints(waypoints);
            kit.getMainMap().setOverlayPainter(painter);
            return kit;
        }
     public WSDemo(String[] args) {
          this.args = args;
        }
        public static void main(String[] args) {
     
            SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    JFrame frame = new JFrame("");
                    frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
                    frame.add(new WSDemo().createContent());
                    frame.setLocationByPlatform(true);
                    frame.setSize(900, 900);
                    frame.setVisible(true);
                }
            });
        }
     
    }
    Et cela me crée une erreur sur cette ligne
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    frame.add(new WSDemo().createContent());

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. [Compilation] probleme de linking avec une classe
    Par deubelte dans le forum C++
    Réponses: 6
    Dernier message: 17/02/2015, 23h19
  2. [2.x] probleme de syntaxe avec une classe
    Par adel25 dans le forum Symfony
    Réponses: 1
    Dernier message: 01/09/2013, 22h39
  3. problem de vector avec une classe
    Par potterthekiller dans le forum SL & STL
    Réponses: 7
    Dernier message: 19/03/2007, 11h11
  4. [débutant] probleme avec une classe arbre
    Par go_all_in dans le forum C++
    Réponses: 17
    Dernier message: 08/06/2006, 10h33
  5. Probleme avec une class template
    Par lenectar dans le forum Langage
    Réponses: 2
    Dernier message: 01/03/2006, 10h49

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