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 utiliser JSplitPane


Sujet :

AWT/Swing Java

  1. #1
    Membre averti
    Inscrit en
    Mars 2008
    Messages
    21
    Détails du profil
    Informations forums :
    Inscription : Mars 2008
    Messages : 21
    Par défaut comment utiliser JSplitPane
    bonjour tous ,

    encore j'ai un problème au niveau de class ecouteur je vous explique , j'ai utiliser un JSplitPane qui me permet de couper la zone du travail en deux j'ai mis un bouton dans la partis gauche et j'ai lui associé une class ecouteur qui me permet d'afficher une image dans la partis droite de JSplitPane mais sa marche pas je ne comprend rien

    voila la classe principale


    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
     
    import java.awt.*;
    import javax.swing.*;
    import java.io.*;
    import java.text.*;
    import java.util.*;
    import java.awt.event.ActionListener;
    import java.awt.event.ActionEvent;
     
    import java.awt.*;
    import java.awt.geom.Rectangle2D;
     
    import javax.swing.*;
     
     
     
     
     
     
    public class Interface extends JFrame  {
     
    	private static final long serialVersionUID = 1L;
     
    	private JPanel jContentPane = null;
     
     
     
    	private JSplitPane jSplitPane = null;
     
     
     
    	private JCheckBox jCheckBox = null;
     
    	private JCheckBox jCheckBox1 = null;
     
    	private JButton jButton = null;
     
     
     
     
    	private JPanel jPanel = null;
     
    	private JPanel jPanel1 = null;
     
    	private JPanel jPanel2 = null;
     
    	private JPanel jPanel3 = null;
     
    	private JPanel jPanel4 = null;
     
    	private JPanel jPanel5 = null;
     
    	private JPanel jPanel6 = null;
     
    	private JPanel jPanel7 = null;
     
    	private JPanel jPanel8 = null;
     
    	private JPanel jPanel9 = null;
     
    	private JPanel jPanelModele = null;
     
    	private JScrollPane dd = null;
     
     
     
     
     
     
    /**
             * This method initializes jButton      
             *      
             * @return javax.swing.JButton  
             */
    	 private JPanel getJPanel7() {
    		if (jPanel7 == null) {
    			jPanel7 = new JPanel();
    			jPanel7.setLayout(new BorderLayout());
     
     
    			jPanel7.setBorder(javax.swing.BorderFactory.createTitledBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.SoftBevelBorder.LOWERED), "le graphe ", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("DialogInput", java.awt.Font.PLAIN, 12), java.awt.SystemColor.activeCaption));
     
    		}
    		return jPanel7;
    	}
     
     
     
    	/**
             * This method initializes jPanel       
             *      
             * @return javax.swing.JPanel   
             */
    	private JPanel getJPanel1() {
    		if (jPanel1 == null) {
    			GridLayout gridLayout = new GridLayout();
    			gridLayout.setRows(2);
    			gridLayout.setColumns(1);
    			jPanel1 = new JPanel();
    			jPanel1.setPreferredSize(new Dimension(400, 600));
    			jPanel1.setLayout(gridLayout);
    			jPanel1.add(getJPanelModele(), null);
    			jPanel1.add(getJPanel2(), null);
    		}
    		return jPanel1;
    	}
     
    	private JPanel getJPanelModele() {
    		if (jPanelModele == null) {
    			jPanelModele = new JPanel();
    			jPanelModele.setLayout(null);
    			jPanelModele.setBorder(javax.swing.BorderFactory.createTitledBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.SoftBevelBorder.LOWERED), "Modele  ", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("DialogInput", java.awt.Font.ITALIC, 12), java.awt.SystemColor.activeCaption));
    			/*jPanelModele.add(getJScrollPane());*/
    			jPanelModele.setVisible(true);
    		}
    		return jPanelModele;
    	}
     
     
     
     
     
    	/**
             * This method initializes jPanel2      
             *      
             * @return javax.swing.JPanel   
             */
    	private JPanel getJPanel2() {
    		if (jPanel2 == null) {
    			GridLayout gridLayout1 = new GridLayout();
    			gridLayout1.setRows(2);
    			gridLayout1.setColumns(1);
    			jPanel2 = new JPanel();
    			jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.SoftBevelBorder.LOWERED), "génerer le graphe", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("DialogInput", java.awt.Font.PLAIN, 12), java.awt.SystemColor.activeCaption));
    			jPanel2.setVisible(true);
    			jPanel2.setLayout(gridLayout1);
    			jPanel2.add(getJPanel3(), null);
    			/*jPanel2.add(getJPanel4(), null);*/
    			/*jPanel2.add(getJPanel5(), null);*/
     
    		}
    		return jPanel2;
    	}
     
     
    	private JPanel getJPanel3() {
    		if (jPanel3 == null) {
     
    			jPanel3 = new JPanel();
    			jPanel3.setLayout(null);
    			jPanel3.add(getJButton(), null);
     
    			}
    	return jPanel3;
    }
     
    	private JButton getJButton() {
    		if (jButton == null) {
    			jButton = new JButton();
    			jButton.setBounds(new Rectangle(80, 40, 221, 36));
    			jButton.setText("génerer le graphe");
    			jButton.addActionListener(new EcoutBotton(this,jPanel7));
     
    		}
    		return jButton;
    	}
     
    	/**
             * This method initializes jSplitPane   
             *      
             * @return javax.swing.JSplitPane       
             */
    	private JSplitPane getJSplitPane() {
    		if (jSplitPane == null) {
    			jSplitPane = new JSplitPane();
    			jSplitPane.setLeftComponent(getJPanel1());
    			jSplitPane.setRightComponent(getJPanel7());
    		}
    		return jSplitPane;
    	}
     
     
    										/*******************la classe ***********************/
    										/**********************main*************************/
     
     
     
    	/**
             * @param args
             */
    	public static void main(String[] args) {
    		// TODO Raccord de méthode auto-généré
    		SwingUtilities.invokeLater(new Runnable() {
    			public void run() {
    				Interface thisClass = new Interface();
    				thisClass.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    				thisClass.setVisible(true);
    			}
    		});
    	}
     
    	/**
             * This is the default constructor
             */
    	public Interface() {
    		super();
    		initialize();
    	}
     
    	/**
             * This method initializes this
             * 
             * @return void
             */
    	private void initialize() {
    		this.setSize(780, 700);
    		this.setContentPane(getJContentPane());
    		this.setTitle("Géneration des scénarios d'attaque");
    	}
     
     
     
     
     
    	/**
             * This method initializes jContentPane
             * 
             * @return javax.swing.JPanel
             */
    	private JPanel getJContentPane() {
    		if (jContentPane == null) {
    			jContentPane = new JPanel();
    			jContentPane.setLayout(new BorderLayout());			 		 			
     
    			jContentPane.add( getJSplitPane(), BorderLayout.CENTER);
     
    		}
     
    		return jContentPane;
    	}
     
    }


    voila la class ecouteur


    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
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.border.*;
     
    class EcoutBotton implements ActionListener
    {
    	JButton invite;
    	JPanel contenu;
    	JScrollPane dd;
    	Interface ve;
     
    	public EcoutBotton(Interface ve,JPanel contenu)
    	{ 
    		this.contenu =contenu;
    		this.ve = ve;
    	}
     
    	public void actionPerformed(ActionEvent e)
    	{ 		
    		ImageIcon ii = new ImageIcon("images.jpg");
     
    		dd = new JScrollPane(new JLabel(ii));
     
    		dd.setBounds(20,20,350,250);
    		contenu.add(dd);
    		dd.revalidate();
     
    }
     
    }

  2. #2
    Membre émérite Avatar de jojodu31
    Profil pro
    Inscrit en
    Mars 2008
    Messages
    875
    Détails du profil
    Informations personnelles :
    Localisation : France, Haute Garonne (Midi Pyrénées)

    Informations forums :
    Inscription : Mars 2008
    Messages : 875
    Par défaut
    bonjour,
    pourquoi ne pas implémenter l' actionPerformed() dans ta classe principale ?
    as-tu essayé ?

  3. #3
    Membre expérimenté
    Profil pro
    Inscrit en
    Mai 2005
    Messages
    155
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2005
    Messages : 155
    Par défaut
    D'apres ce que j'ai vu, c'est parceque que tu initialise ton bouton avec jpanel7 alors que celui-ci ne s'initialise qu'apres.
    Donc tu initialise ton bouton avec null comme contenu.
    D'ou une NullPointerException (j'ai bon?).

  4. #4
    Membre averti
    Inscrit en
    Mars 2008
    Messages
    21
    Détails du profil
    Informations forums :
    Inscription : Mars 2008
    Messages : 21
    Par défaut
    bonjour
    merci vous avez raison ,enfin j'ai juste inverser deux ligne de code(la ou j'ai crée mon JSplitPane) et sa marche
    merci bien

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

Discussions similaires

  1. Réponses: 4
    Dernier message: 24/02/2009, 12h06
  2. Comment utiliser un cache ?
    Par TOM-Z dans le forum XMLRAD
    Réponses: 4
    Dernier message: 14/03/2003, 09h55
  3. comment utiliser actionscript ?
    Par webs dans le forum Flash
    Réponses: 3
    Dernier message: 09/02/2003, 23h11
  4. Comment utiliser OUT ?
    Par Bouziane Abderraouf dans le forum CORBA
    Réponses: 3
    Dernier message: 20/07/2002, 09h35
  5. Réponses: 5
    Dernier message: 11/06/2002, 15h21

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