Merci de me supprimer de votre liste de diffusion
Cordialement
[EMAIL PROTECTED]
----- Original Message -----
From: "andriamasinoro fenintsoa" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Monday, February 10, 2003 8:06 PM
Subject: Re: Aide sur JLayeredPane
> J'ai trouv� dans le tutorial comment fabriquer les Icon personnalis�s ie
impl�mentant javax.swing.Icon comme tu l'as propos� avant. Et c'est
effectivement ce qui se passe:
> lorsqu'on associe un JLabel � la classe qui impl�mente l'Icon, la m�thode
paintIcon est automatiquement appel�e et l'icone dessin�e. Je l'ai donc
rapproch� de mon cas. Ce qui
> est bizarre, c'est que tout marche jusqu'au moment o� j'int�gre le JLabel
sur un LayeredPane. L�, il ne veut plus afficher l'icone personnalis�. Si
pr�s du but :(
>
> Erik Mazoyer wrote:
>
> > ---------------------------------------------
> >
> > Soit tu travailles directement sur le rendu de ton composant. Le plus
simple, tu dessines le fond puis tu dessines l'icon en appelant toi m�me la
m�thode
> >
> > public void paint(Graphics g) {
> > // Tu dessines ton image de fond
> > myIcon.paintIcon(this,g,x,y);
> > }
> >
> > ---------------------------------------------
> >
> > Soit tu utilises les JComponent :
> >
> > 1) Tu cr�es un JPanel
> > 2) tu lui indiques qu'il n'a pas de Layout (setLayout(null))
> > 3) tu ajoutes � ton panel un label li� � ton icon
> > 4) tu d�places ton label
> >
> > Attention, Swing est mono thread, pour travailler avec lui il faut
utiliser SwingUtilities.invokeLater() pour donner des ordres d'affichages,
sinon tu risque des conflits.
> >
> > A+
> >
> > --------------------------------------------------------------------
> > Erik Mazoyer, Chef de projet
> > HyperOffice
> > 6, rue Jacques Daguerre - 92565 Rueil-Malmaison Cedex
> > T�l. 01 41 96 96 76
> > Fax 01 41 96 96 77
> > M�l [EMAIL PROTECTED]
> >
> >
> > -----Message d'origine-----
> > De : andriamasinoro fenintsoa [mailto:[EMAIL PROTECTED]]
> > Envoy� : lundi 10 f�vrier 2003 15:22
> > � : [EMAIL PROTECTED]
> > Objet : Re: Aide sur JLayeredPane
> >
> > Merci pour la proposition sur l'Icon. J'ai n�anmoins essay� avec tout
d'abord un simple fillRect mais il n'affiche toujours rien, sauf la carte
> > de la premi�re couche �videmment (voir le code ci-dessous). La m�thode
setLocation() de mon JLabel "icLabel" ne devrait-elle pas appeler
> > implicitement le paintIcon() de ma class MyIcon?
> >
> > Merci pour la r�ponse
> >
> > --
> > ANDRIAMASINORO Fenintsoa (Mr)
> > IREMIA-Lab. | University of La R�union (France)
> > tel: 0 262 938 324 | cel: 0 692 811 924 | fax: 0 262 938 260
> > from abroad: 0 -> +262
> > Web page: "http://fenintsoa.net/"
> > -----
> > lift up the wisdom and the wisdom will lift you up [Prov. 4:7-8]
> >
> > ******************
> > public class LayeredPaneDemo extends JFrame {
> > ImageIcon backGroundImg;
> > ImageIcon[] images;
> > JLabel icLabel;
> > private JLayeredPane layeredPane;
> > private JLabel dukeLabel;
> >
> > public LayeredPaneDemo() {
> > super("LayeredPaneDemo");
> >
> > //Create and load the duke icon.
> > int k = 0;
> > backGroundImg = new ImageIcon("images/map.jpg");
> >
> > //Create and set up the layered pane.
> > layeredPane = new JLayeredPane();
> > layeredPane.setPreferredSize(new Dimension(1000, 1000));
> >
> > //Add several overlapping, colored labels to the layered pane
> > //using absolute positioning/sizing.
> > JLabel backGround = new JLabel(backGroundImg);
> > backGround.setBounds(0, 0, 500, 500);
> > layeredPane.add(backGround, new Integer(0));
> >
> > // Add MyIcon
> > MyIcon mi = new MyIcon();
> > icLabel = new JLabel(mi);
> > layeredPane.add(icLabel, new Integer(1));
> >
> > //Add layered pane to frame.
> > getContentPane().add(layeredPane);
> >
> > Thread thread = new Thread(){
> > public void run()
> > {
> > int y = 70;
> > int k = 0;
> > while(true)
> > {
> > icLabel.setLocation(70, y);
> > k %= 8;
> > y += 10;
> > try{Thread.sleep(100);}
> > catch(Exception e)
> > {System.out.println("aaa");}
> > }
> > }
> > };
> > thread.start();
> > }
> >
> > public static void main(String[] args) {
> > JFrame frame = new LayeredPaneDemo();
> >
> > frame.addWindowListener(new WindowAdapter() {
> > public void windowClosing(WindowEvent e) {
> > System.exit(0);
> > }
> > });
> >
> > frame.pack();
> > frame.setVisible(true);
> > }
> > }
> >
> > class MyIcon implements javax.swing.Icon
> > {
> > MyIcon()
> > {System.out.println("constructor");}
> >
> > public void paintIcon(Component c, Graphics g, int x, int y)
> > {
> > System.out.println("OK");
> >
> > g.setColor(Color.RED);
> > g.fillRect(0, 0, 10, 10);
> > }
> >
> > public int getIconWidth()
> > {return 50;}
> >
> > public int getIconHeight()
> > {return 50;}
> >
> > }
> > *************************
> >
> > Erik Mazoyer wrote:
> >
> > > Jpanel est un objet utilisable quand on d�sire placer en son sein
d'autres composant visuels.
> > > Il ne semble pas que cela soit les cas.
> > >
> > > Un cas plus simple est de d�river directement de
javax.swing.JComponent.
> > >
> > > Mais dans ton cas, pour dessiner une voiture tu peux, beaucoup plus
simplement, impl�menter l'interface javax.swing.Icon et utiliser JLabel.
> > >
> > > Icon impose une m�thode :
> > > public void paintIcon(Component c,
> > > Graphics g,
> > > int x,
> > > int y)
> > > Ou tu pourras dessiner ta voiture dans l'orientation d�sir�e.
> > >
> > > Cordialement,
> > >
> > > --------------------------------------------------------------------
> > > Erik Mazoyer, Chef de projet
> > > HyperOffice
> > > 6, rue Jacques Daguerre - 92565 Rueil-Malmaison Cedex
> > > T�l. 01 41 96 96 76
> > > Fax 01 41 96 96 77
> > > M�l [EMAIL PROTECTED]
> > >
> > >
> > > -----Message d'origine-----
> > > De : andriamasinoro fenintsoa [mailto:[EMAIL PROTECTED]]
> > > Envoy� : lundi 10 f�vrier 2003 09:11
> > > � : [EMAIL PROTECTED]
> > > Objet : Aide sur JLayeredPane
> > >
> > > Bonjour,
> > >
> > > Je souhaite utiliser un JLayerdPane pour les objectifs suivants:
> > > couche 0: afficher une carte de ville en background
> > > couche 1: dessiner une voiture via un polygon. Cette voiture sera
> > > redessin�e en permanence en fonction de son orientation mais c'est le
> > > backgournd qui ne change pas.
> > >
> > > Le probl�me est que je dois d'abord avoir le Graphics context (le g
> > > donc) correspondant � la voiture avant de pouvoir la dessiner. Pour
> > > cela, je pensais utiliser un JPanel (cf. le code ci-dessous) mais
...ma
> > > voiture ne s'affiche pas. Pourquoi svp? est-ce que le JPanel est en
> > > conflit avec une couche d'un JLayeredPane? Quelle solution
> > > proposez-vous?
> > >
> > > Merci pour votre aide
> > >
> > > ANDRIAMASINORO Fenintsoa (Mr)
> > >
> > > ps: avec un JLabel et une imageIcon, �a marche bien. Mais comme ma
> > > voiture s'oriente en permanence d'un certain angle (et aussi pour des
> > > raisons de performance), je pr�f�re utiliser g.fillXXX() et les
> > > g.drawXXX() pour afficher ma voiture.
> > >
> > > *************************
> > > backGroundImg = new ImageIcon("images/map.jpg");
> > >
> > > //Create and set up the layered pane.
> > > layeredPane = new JLayeredPane();
> > >
> > > JLabel backGround = new JLabel(backGroundImg);
> > > backGround.setBounds(0, 0, 1000, 1000);
> > > layeredPane.add(backGround, new Integer(0));
> > >
> > > //Create and add the Duke label to the layered pane.
> > > dukeLabel = new JLabel(icon);
> > > dukeLabel.setBounds(70, 70, icon.getIconWidth(),
> > > icon.getIconHeight());
> > > layeredPane.add(dukeLabel, new Integer(0), 0);
> > >
> > > // Create and add Panel
> > > JPanel panel = new JPanel() {
> > > public Dimension getPreferredSize() {
> > > return new Dimension(800,600);
> > > }
> > >
> > > public void paint(Graphics g) {
> > > super.paint(g);
> > > g.fillRect(...);
> > > }
> > > };
> > >
> > > --
> > > IREMIA-Lab. | University of La R�union (France)
> > > tel: 0 262 938 324 | cel: 0 692 811 924 | fax: 0 262 938 260
> > > from abroad: 0 -> +262
> > > Web page: "http://fenintsoa.net/"
> > > -----
> > > lift up the wisdom and the wisdom will lift you up [Prov. 4:7-8]
>
> --
> ANDRIAMASINORO Fenintsoa (Mr)
> IREMIA-Lab. | University of La R�union (France)
> tel: 0 262 938 324 | cel: 0 692 811 924 | fax: 0 262 938 260
> from abroad: 0 -> +262
> Web page: "http://fenintsoa.net/"
> -----
> lift up the wisdom and the wisdom will lift you up [Prov. 4:7-8]
>
>
>