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 :

Comment fermer un Jpanel


Sujet :

AWT/Swing Java

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre du Club
    Profil pro
    Inscrit en
    Mai 2008
    Messages
    6
    Détails du profil
    Informations personnelles :
    Localisation : Tunisie

    Informations forums :
    Inscription : Mai 2008
    Messages : 6
    Par défaut Comment fermer un Jpanel
    salut

    j'ai une palette de bouton et chaque appuie renvoye a une scene 3d(affiché avec setVisible) mais quand j'appuye sur un autre bouton la scene d'avant n'est pas fermé( j'ai 2frame ouvert) comment je pourrai fermer la 1ere

    merci d'avance

  2. #2
    Membre Expert
    Avatar de supersnail
    Homme Profil pro
    Inscrit en
    Novembre 2006
    Messages
    1 719
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Novembre 2006
    Messages : 1 719
    Par défaut
    Un bout de code nous éclairerait...

  3. #3
    Membre du Club
    Profil pro
    Inscrit en
    Mai 2008
    Messages
    6
    Détails du profil
    Informations personnelles :
    Localisation : Tunisie

    Informations forums :
    Inscription : Mai 2008
    Messages : 6
    Par défaut code
    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
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
    353
    354
    355
    356
    357
    358
    359
    360
    361
    362
    363
    364
    365
    366
    367
    368
    369
    370
    371
    372
    373
    374
    375
    376
    377
    378
    379
    380
    381
    382
    383
    384
    385
    386
    387
    388
    389
    390
    391
    392
    393
    394
    395
    396
    397
    398
    399
    400
    401
    402
    403
    404
    405
     
    package org.jdesktop.j3d.examples.print_canvas3d;
    import com.sun.j3d.utils.universe.*;
    import java.net.MalformedURLException;
    import javax.imageio.ImageIO;
    import javax.media.j3d.*;
    import javax.vecmath.*;
     
    import java.awt.*;
     
    import javax.swing.*;
     
    import javax.swing.JPopupMenu;
    import com.sun.j3d.loaders.objectfile.ObjectFile;
    import com.sun.j3d.loaders.ParsingErrorException;
    import com.sun.j3d.loaders.IncorrectFormatException;
    import com.sun.j3d.loaders.Scene;
     
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.awt.event.MouseEvent;
    import java.awt.event.MouseListener;
    import java.awt.image.BufferedImage;
    import java.io.*;
     
    import com.sun.j3d.utils.behaviors.mouse.*;
    import com.sun.j3d.utils.geometry.Box;
    import com.sun.j3d.utils.geometry.ColorCube;
    import com.sun.j3d.utils.geometry.Text2D;
    import com.sun.j3d.utils.image.TextureLoader;
     
    import java.net.URL;
    import java.sql.ResultSet;
    import java.sql.SQLException;
    import java.util.Vector;
     
     
    import org.jdesktop.j3d.examples.Resources;
     
     
    public class PrintCanvas3D extends javax.swing.JFrame implements ActionListener  {
     
        private Canvas3D onScreenCanvas3D;
     
        private java.net.URL bgImage = null;
     
        private SimpleUniverse univ = null;
     
        String[] args=null;
     
    	private ResultSet res;
     
    	private ResultSet ress;
    	JFrame fu;
    	JButton x=null;
    	static int etage;
    JPanel pu=new JPanel();
    int countb=0;
    JButton vv;
    JButton va;
    	 Vector <String>bouton ;
    	 Vector<Integer> nume; 
    	  JPanel drawingPanel;
     
    	static int view;
    	static String path;
    	static int change;
     
        public BranchGroup createSceneGraph(String args[]) {
     
    			BranchGroup objRoot=new BranchGroup();	 
     
    	objRoot.addChild(new obj(path,args).insert(18,new Vector3f(0,0,0),0.00001f));
    	//objRoot.addChild(new obj("resources/geometry/cv.obj",args).insert(0.05f,new Vector3f(15,0,0),4));
    	//objRoot.addChild(new obj("resources/geometry/extincteur.obj",args).insert(0.05f,new Vector3f(15,0,0),4));
     
     
     
     
     
    	BoundingSphere bounds =
    	    new BoundingSphere(new Point3d(0.0,0.0,0.0), 100.0);
     
     
     
     
    	// Set up the background
    	//Color3f bgColor = new Color3f(0.9f,1,0.9f);
    	//Background bgNode = new Background(bgColor);
    	//bgNode.setApplicationBounds(bounds);
    	//objRoot.addChild(bgNode);
     
     
     
     
     
    	// Set up the ambient light
    	Color3f ambientColor = new Color3f(0.1f, 0.1f, 0.1f);
    	AmbientLight ambientLightNode = new AmbientLight(ambientColor);
    	ambientLightNode.setInfluencingBounds(bounds);
    	objRoot.addChild(ambientLightNode);
     
     
     
     
     
    	// Set up the directional lights
    	Color3f light1Color = new Color3f(1.0f, 1.0f, 0.9f);
    	Vector3f light1Direction  = new Vector3f(4.0f, -7.0f, -12.0f);
    	Color3f light2Color = new Color3f(0.3f, 0.3f, 0.4f);
    	Vector3f light2Direction  = new Vector3f(-6.0f, -2.0f, -1.0f);
     
    	DirectionalLight light1
    	    = new DirectionalLight(light1Color, light1Direction);
    	light1.setInfluencingBounds(bounds);
    	objRoot.addChild(light1);
     
    	DirectionalLight light2
    	    = new DirectionalLight(light2Color, light2Direction);
    	light2.setInfluencingBounds(bounds);
    	objRoot.addChild(light2);
     
     
     
    	return objRoot;
        }
     
        private void usage() {
    	System.out.println("Usage: java PrintCanvas3D <.obj file>");
    	System.exit(0);
        }
     
     
        private Canvas3D createUniverse() {
    	GraphicsConfiguration config =
    	    SimpleUniverse.getPreferredConfiguration();
     
    	Canvas3D c = new Canvas3D(config);
     
    	univ = new SimpleUniverse(c);
    	if(view==0){
    		TransformGroup vpt=univ.getViewingPlatform().getViewPlatformTransform();
     
    	    Transform3D  t=new Transform3D();
    	    Transform3D  r=new Transform3D();
    	   r.rotX(Math.PI/-2.7d);
    	    t.set(new Vector3f(0,42,19));
    	    t.mul(r);
    	    ViewPlatform x=new ViewPlatform();
    	    vpt.setTransform(t);
    	}
    	else{
        TransformGroup vpt=univ.getViewingPlatform().getViewPlatformTransform();
     
        Transform3D  t=new Transform3D();
        Transform3D  r=new Transform3D();
        r.rotY(Math.PI/2.0d);
        t.set(new Vector3f(37,-3.5f,0.2f));
        t.mul(r);
        ViewPlatform x=new ViewPlatform();
        vpt.setTransform(t);
    	}
     
     
     
     
    	univ.getViewer().getView().setMinimumFrameCycleTime(5);
    	return c;
     
        }
     
     
     
     
     
        public PrintCanvas3D(String args[],String path,int view,int change,int etage) {
     
     
     
            // Initialize the GUI components
            JPopupMenu.setDefaultLightWeightPopupEnabled(false);
            initComponents();        
            this.view=view;
            this.change=change;
            this.path=path;
            this.args=args;
            // Create Canvas3D and SimpleUniverse; add canvas to drawing panel
            onScreenCanvas3D = createUniverse();
            drawingPanel.add(onScreenCanvas3D, java.awt.BorderLayout.CENTER);
            BranchGroup scene = createSceneGraph(args);
            Background background = new Background();
     
     
    //      acces base   
     
    DBase.open();
    int countp=0;
    ResultSet rescp=DBase.execute("SELECT distinct(id_p) from produit  ");
    try {
    	while(rescp.next()){
    		countp++;
    	}
    } catch (SQLException e1) {
    	// TODO Auto-generated catch block
    	e1.printStackTrace();
    }
     
    int countt=0;
    ResultSet resct=DBase.execute("SELECT distinct(num_r) from rayon where num_e="+etage+" ");
    try {
    	while(resct.next()){
    		countt++;
    	}
    } catch (SQLException e1) {
    	// TODO Auto-generated catch block
    	e1.printStackTrace();
    }
    System.out.println(etage);
     
    ResultSet rest=DBase.execute("SELECT distinct(num_r),type_p from rayon where num_e="+etage+" ");
    ResultSet resp=null;
    int rayon=0;
    float x=-15;
    float y=-3.2f;
    float z=-8f;
    	try {
    		while(rest.next()){
    			rayon=rest.getInt("num_r");
    			x=-15;
    			z=z+7f/(countt);
     
    	scene.addChild(new texte(rest.getString("type_p")).insert(x,y+3,z));
    resp=DBase.execute("SELECT libel_p,image_p from produit WHERE num_r="+rayon+"");
    while(resp.next()){
    	x=x+2;
        scene.addChild(new rayon().r(resp.getString("image_p"),x,y,z));
     
     
     
     
    }
    }
    	} catch (SQLException e) {
    		// TODO Auto-generated catch block
    		e.printStackTrace();
    	}
     
     
     
     
     
            //clavier
                   TransformGroup tg = univ.getViewingPlatform().getViewPlatformTransform();
            	   CustomKeyNavigatorBehavior keyNavigatorBehavior = new CustomKeyNavigatorBehavior(tg);
                   keyNavigatorBehavior.setSchedulingBounds(
                   new BoundingSphere(new Point3d(), 1000));
                   keyNavigatorBehavior.setSpeedFactor(0.1f);
                   scene.addChild(keyNavigatorBehavior);
     
     
             univ.addBranchGraph(scene);
        }
     
     
     
        private void initComponents() {
        	JLabel info;
        	JCheckBox niveau;
      drawingPanel = new javax.swing.JPanel();
    fu=new JFrame();
    fu.setVisible(true);
    fu.setSize( 800,100);
    fu.add(pu);
    fu.setResizable(false);
    fu.setAlwaysOnTop(true);
     
    nume=new Vector <Integer>() ;
    bouton=new Vector <String>() ;
    DBase.open();
    ResultSet res=DBase.execute("SELECT num_e,libel_e,path_e from etage ");
    try {
    	while(res.next()){
    		bouton.add(res.getString("path_e"));
    		nume.add(res.getInt("num_e"));
    		x=new JButton(res.getString("libel_e"));
    		x.setName(res.getString("path_e"));
    		x.addActionListener(this);
    		niveau=new JCheckBox();
    		pu.add(x);
    		pu.add(niveau);
    		countb++;
     
     
     
    	}
    } catch (SQLException e) {
    	// TODO Auto-generated catch block
    	e.printStackTrace();
    }
    vv=new JButton("visite virtuelle");
    va=new JButton("vue aérienne");
    va.addActionListener(this);
    vv.addActionListener(this);
    pu.add(vv);
    pu.add(va);
     
     
            setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
            setTitle("Mini Projet");
            drawingPanel.setLayout(new java.awt.BorderLayout());
     
            drawingPanel.setPreferredSize(new java.awt.Dimension(1280, 740));
            getContentPane().add(drawingPanel, java.awt.BorderLayout.CENTER);
            pack();
     
            }
     
        public  static void main(final String args[]) {
            java.awt.EventQueue.invokeLater(new Runnable() {
                public void run() {
                	DBase.open();
                	ResultSet res=DBase.execute("SELECT * from etage ");
                	int c=0;
                	try {
                		while(res.next()){
                		c++;
                		}
                	} catch (SQLException e) {
                		// TODO Auto-generated catch block
                		e.printStackTrace();
                	}
                	if(change==0){
             if(c==1){
                	PrintCanvas3D ppp=new PrintCanvas3D(args,"resources/geometry/centre.obj",view,0,0);
                	ppp.setVisible(true);
                	path="resources/geometry/centre.obj";
                	         }
             else{
            	 PrintCanvas3D ppp=new PrintCanvas3D(args,"resources/geometry/rdcniv.obj",view,0,0);
             	ppp.setVisible(true);
             	path="resources/geometry/rdcniv.obj";
                      }
                	}
     
     
     
     
                }
            });
        }
     
     
    	public void actionPerformed(ActionEvent arg0) {
    		int i=0;
    int x=0;
    			if ((arg0.getSource()!=null)){
     
    				if ((arg0.getSource().equals(vv))&&(view!=5)){
    					view=5;
    					change=1;
    					 drawingPanel.removeAll();
    					 PrintCanvas3D ppp=new PrintCanvas3D(args,path,view,1,etage);
    			         ppp.setVisible(true);
     
    							}
    				if ((arg0.getSource().equals(va))&&view!=0){
    					view=0;
    					change=1;
     
     
    					 PrintCanvas3D ppp=new PrintCanvas3D(args,path,view,1,etage);
     
    					    	ppp.setVisible(true);
    				}
    				else{
    				while(x==0){
     
     
    					if((arg0.getSource().toString()).equals(pu.getComponent(i).toString())&&(nume.elementAt(i/2)!=etage)){
    						x=1;
    						System.out.println(i/2);
    						i=i/2;
    						}
    					else{i++;}
    								}
    				if(x!=0){
    				etage=i;
    				change=1;
    				path=bouton.elementAt(etage);
    				System.out.println(path);
    				PrintCanvas3D ppp=new PrintCanvas3D(args,path,view,1,etage);
    				fu.dispose();
    				pu.remove(this);
    	         	ppp.setVisible(true);
    				}
     
     
     
     
     
    				}
    			}
     
    		}
    }

    mille merci

Discussions similaires

  1. Réponses: 11
    Dernier message: 20/09/2007, 14h51
  2. Comment fermer une fenêtre quand la souris et clavier sont inactifs ?
    Par Goldenkiller dans le forum Composants VCL
    Réponses: 7
    Dernier message: 06/12/2004, 22h09
  3. [WNetAddConnection2] Comment fermer une connection ?
    Par souch dans le forum Web & réseau
    Réponses: 3
    Dernier message: 21/10/2004, 14h41
  4. Comment fermer l'application en même temps que Windows ?
    Par semaj_james dans le forum Langage
    Réponses: 4
    Dernier message: 23/06/2004, 22h17
  5. [MDI] comment fermer la bonne fenêtre enfant ?
    Par KThrax dans le forum Langage
    Réponses: 5
    Dernier message: 01/09/2002, 09h42

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