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
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 associer au bouton
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();
}
}
merci