Forum |  HardWare.fr | News | Articles | PC | S'identifier | S'inscrire | Shop Recherche
1648 connectés 

  FORUM HardWare.fr
  Programmation
  Java

  Probleme IHM, JPanel

 


 Mot :   Pseudo :  
 
Bas de page
Auteur Sujet :

Probleme IHM, JPanel

n°2049767
Eth4nPierr​e
Posté le 17-01-2011 à 23:23:54  profilanswer
 

Salut tout le monde,
 
Je me perds un peu dans le placement de mes composants dans mes JPanel. En effet, les lignes 75 à 77 ne prennent effet que si j'initialise leur JPanels respectifs en tant que JPanel d'accueil ligne 105.
 
Voici les sources :  
 

Code :
  1. import java.awt.Color;
  2. import java.awt.event.ActionEvent;
  3. import java.awt.event.ActionListener;
  4. import javax.swing.JButton;
  5. import javax.swing.JFrame;
  6. import javax.swing.JLabel;
  7. import javax.swing.JPanel;
  8. import javax.swing.*;
  9. public class Fenetre extends JFrame{
  10. /**
  11.  *  
  12.  */
  13. private static final long serialVersionUID = 1L;
  14. public JPanel panAccueil = new JPanel();
  15. public JPanel panInstal = new JPanel();
  16. public JPanel panPreferences = new JPanel();
  17. public JPanel panConfig = new JPanel();
  18. public JButton installation = new JButton("Installation" );
  19. public JButton preferences = new JButton("Préférences" );
  20. public JButton configuration = new JButton("Configuration" );
  21. public JButton precedentInstal = new JButton("Précédent" );
  22. public JButton precedentPref = new JButton("Précédent" );
  23. public JButton precedentConf = new JButton("Précédent" );
  24. public JLabel enteteAccueil = new JLabel("Entete ici" );
  25. public JLabel enteteInstal = new JLabel("Entete Installation" );
  26. public JLabel entetePref = new JLabel("Entete Préférences" );
  27. public JLabel enteteConf = new JLabel("Entete Configuration" );
  28. public JLabel texteInstallation = new JLabel("Installation de votre logiciel" );
  29. public JLabel textePref = new JLabel("Choisissez vos préférences" );
  30. public JLabel texteConfig = new JLabel("Configurer votre logiciel" );
  31. // public JLabel imageInst = new JLabel(new ImageIcon("C:\\Users\\Pierre\\workspace\\Menu\\Installation.jpg" ));
  32. // public JLabel imagePref = new JLabel(new ImageIcon("C:\\Users\\Pierre\\workspace\\Menu\\Préférences.jpg" ));
  33. // public JLabel imageConf = new JLabel(new ImageIcon("C:\\Users\\Pierre\\workspace\\Menu\\Installation.png" ));
  34. public Fenetre(){
  35.  init_param_fenetre();
  36.  setLayout(null);
  37.  panAccueil.setBackground(Color.WHITE);
  38.  panInstal.setBackground(Color.WHITE);
  39.  panPreferences.setBackground(Color.WHITE);
  40.  panConfig.setBackground(Color.WHITE);
  41.  panAccueil.add(installation);
  42.  panAccueil.add(preferences);
  43.  panAccueil.add(configuration);
  44.  panAccueil.add(enteteAccueil);
  45.  panAccueil.add(texteInstallation);
  46.  panAccueil.add(textePref);
  47.  panAccueil.add(texteConfig);
  48. //  panAccueil.add(imageInst);
  49. //  panAccueil.add(imagePref);
  50. //  panAccueil.add(imageConf);
  51.  panInstal.add(precedentInstal);
  52.  panInstal.add(enteteInstal);
  53.  panPreferences.add(precedentPref);
  54.  panPreferences.add(entetePref);
  55.  panConfig.add(precedentConf);
  56.  panConfig.add(enteteConf);
  57.  installation.setBounds(100, 100, 150, 40);
  58.  preferences.setBounds(100, 180, 150, 40);
  59.  configuration.setBounds(100, 260, 150, 40);
  60. /*ligne75*/  precedentInstal.setBounds(10, 270, 150, 40);
  61. /*ligne76*/  precedentConf.setBounds(10, 270, 150, 40);
  62. /*ligne77*/  precedentPref.setBounds(10, 270, 150, 40);
  63.  enteteAccueil.setBounds(250, 10, 100, 10);
  64.  enteteInstal.setBounds(250, 10, 200, 10);
  65.  entetePref.setBounds(250, 10, 200, 10);
  66.  texteInstallation.setBounds(270, 100, 200, 40);
  67.  textePref.setBounds(270, 180, 200, 40);
  68.  texteConfig.setBounds(270, 260, 200, 40);
  69. //  imageInst.setBounds(10, 90, 63, 65);
  70. //  imagePref.setBounds(10, 165, 63, 63);
  71. //  imageConf.setBounds(10, 250, 61, 60);
  72.  installation.addActionListener(new BlistenInstal(this));
  73.  preferences.addActionListener(new BlistenPref(this));
  74.  configuration.addActionListener(new BlistenConf(this));
  75.  precedentInstal.addActionListener(new BlistenPrecedentInst(this));
  76.  precedentPref.addActionListener(new BlistenPrecedentPref(this));
  77.  precedentConf.addActionListener(new BlistenPrecedentConf(this));
  78.  this.setVisible(true);
  79. }
  80. void init_param_fenetre(){
  81.  this.setTitle("Configuration" );
  82.  this.setSize(600, 400);
  83.  this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  84.  this.setLocationRelativeTo(null);
  85.  this.setResizable(false);
  86. /*ligne105*/  this.setContentPane(panAccueil);
  87. }
  88. //Boutons du JPanel d'accueil
  89. public class BlistenInstal implements ActionListener{
  90.  Fenetre fen;
  91.  public BlistenInstal(Fenetre fen){
  92.   this.fen = fen;
  93.  }
  94.  public void actionPerformed(final ActionEvent arg0){
  95.   fen.setContentPane(panInstal);
  96.   fen.validate();
  97.  }
  98. }
  99. public class BlistenPref implements ActionListener{
  100.  Fenetre fen;
  101.  public BlistenPref(Fenetre fen){
  102.   this.fen = fen;
  103.  }
  104.  public void actionPerformed(final ActionEvent arg0){
  105.   fen.setContentPane(panPreferences);
  106.   fen.validate();
  107.  }
  108. }
  109. public class BlistenConf implements ActionListener{
  110.  Fenetre fen;
  111.  public BlistenConf(Fenetre fen){
  112.   this.fen = fen;
  113.  }
  114.  public void actionPerformed(final ActionEvent arg0){
  115.   fen.setContentPane(panConfig);
  116.   fen.validate();
  117.  }
  118. }
  119. //Boutons "précédent" pour chaque JPanel choisi
  120. public class BlistenPrecedentInst implements ActionListener{
  121.  Fenetre fen;
  122.  public BlistenPrecedentInst(Fenetre fen){
  123.   this.fen = fen;
  124.  }
  125.  public void actionPerformed(final ActionEvent arg0){
  126.   fen.setContentPane(panAccueil);
  127.   fen.validate();
  128.  }
  129. }
  130. public class BlistenPrecedentPref implements ActionListener{
  131.  Fenetre fen;
  132.  public BlistenPrecedentPref(Fenetre fen){
  133.   this.fen = fen;
  134.  }
  135.  public void actionPerformed(final ActionEvent arg0){
  136.   fen.setContentPane(panAccueil);
  137.   fen.validate();
  138.  }
  139. }
  140. public class BlistenPrecedentConf implements ActionListener{
  141.  Fenetre fen;
  142.  public BlistenPrecedentConf(Fenetre fen){
  143.   this.fen = fen;
  144.  }
  145.  public void actionPerformed(final ActionEvent arg0){
  146.   fen.setContentPane(panAccueil);
  147.   fen.validate();
  148.  }
  149. }
  150. }


 
et le main :
 

Code :
  1. public class Test {
  2. /**
  3.  * @param args
  4.  */
  5. public static void main(String[] args) {
  6.  // TODO Auto-generated method stub
  7.  Fenetre fen = new Fenetre();
  8. }
  9. }


 
Merci de votre réponse

mood
Publicité
Posté le 17-01-2011 à 23:23:54  profilanswer
 


Aller à :
Ajouter une réponse
  FORUM HardWare.fr
  Programmation
  Java

  Probleme IHM, JPanel

 

Sujets relatifs
Problème formulaire de contactProblème de la Socket en C sous linux
[mySql] Probleme cle etrangere sur deux primary key[XML] Problème de dimension d'images
Probleme jeu schemeProblème avec do while
Problème array en php[Python] Problème position bouton
Petit problème d'affichage sous Firefoxproblème signaux en shell
Plus de sujets relatifs à : Probleme IHM, JPanel


Copyright © 1997-2022 Hardware.fr SARL (Signaler un contenu illicite / Données personnelles) / Groupe LDLC / Shop HFR