Programme java recette cuisine

bibi89290 Messages postés 1 Date d'inscription samedi 30 avril 2011 Statut Membre Dernière intervention 4 mai 2011 - 4 mai 2011 à 11:07
 Utilisateur anonyme - 4 mai 2011 à 21:13
Bonjour,

J'ai fait un prgramme avec une jcombobox qui recupere les fichiers dans un dossier joint au projet en fichier texte dans un dossier.
Le probleme c'est que la jcombobox ne recupere pas les fichiers du dossier et qu'elle n'envoie pas à ma 2eme classe "reponse" les données de cette liste.
Autre problème, la classe réponse ne récupère pas les données de la 2eme liste qui est le nombre de personne.
Je n'ai encore rien fait dans ma 2eme classe pcq je ne sais pas trop comment faire.
Merci d'avance pour votre aide, je suis vraiment débutant dans les programmes java donc ca serait sympa d'etre tres clair dans vos reponses.

import java.applet.Applet;
import java.awt.Choice;
import java.awt.Color;
import java.awt.Component;
import java.awt.Panel;
import java.awt.GridBagLayout;
import java.awt.Dimension;
import java.awt.Rectangle;
import java.awt.List;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.Scanner;
import java.util.Vector;

import javax.swing.ComboBoxModel;
import javax.swing.ImageIcon;
import javax.swing.JComboBox;
import javax.swing.JEditorPane;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JList;

public class test2 extends Applet
{

private static final long serialVersionUID = 1L;
private static final Vector<String> listeFichiers= null;
private Panel panel = null;
private JComboBox jComboBox = null;
private Choice jComboBox1 = null;
private Choice jComboBox11 = null;
private JEditorPane jEditorPane = null;
private JButton jButton = null;
private JEditorPane jEditorPane1 = null;
private JEditorPane jEditorPane2 = null;
int nbpers = 0;
File[] List;

/**
* This is the default constructor
*/
public test2()
{
super();
}


/**
* This method initializes this
*
* @return void
*/
public void init()
{
this.setLayout(null);
this.setSize(598, 411);

this.add(getPanel(), null);
this.add(getJComboBox(listeFichiers), null);
this.add(getJComboBox1(), null);
this.add(getJComboBox11(), null);
this.add(getJEditorPane(), null);
this.add(getJButton(), null);
this.add(getJEditorPane1(), null);
this.add(getJEditorPane2(), null);
}


/**
* This method initializes panel
*
* @return java.awt.Panel
*/
private Panel getPanel()
{
if (panel == null)
{
panel = new Panel();
JLabel lab = new JLabel(new ImageIcon("image.jpeg"));
panel.setLayout(new GridBagLayout());
panel.setBounds(new Rectangle(299, 5, 0, 0));
}
return panel;
}



/**
* This method initializes jComboBox1
*
* @return javax.swing.JComboBox
*/
private Choice getJComboBox1()
{
if (jComboBox1 == null)
{
jComboBox1 = new Choice();
jComboBox1.addItem("1");
jComboBox1.addItem("2");
jComboBox1.addItem("3");
jComboBox1.addItem("4");
jComboBox1.addItem("5");
jComboBox1.addItem("6");
jComboBox1.addItem("7");
jComboBox1.addItem("8");
jComboBox1.setForeground(Color.black);
jComboBox1.setBackground(Color.green);

jComboBox1.setBounds(new Rectangle(61, 300, 151, 26));

}
return jComboBox1;

}

/**
* This method initializes jComboBox1
*
* @return javax.swing.JComboBox
*/
private Choice getJComboBox11()
{
if (jComboBox11 == null)
{
jComboBox11 = new Choice();
jComboBox11.addItem("1");
jComboBox11.addItem("2");
jComboBox11.addItem("3");
jComboBox11.addItem("4");
jComboBox11.addItem("5");
jComboBox11.addItem("6");
jComboBox11.addItem("7");
jComboBox11.addItem("8");
jComboBox11.setForeground(Color.black);
jComboBox11.setBackground(Color.green);

jComboBox11.setBounds(new Rectangle(61, 180, 151, 26));

}
return jComboBox11;

}

/**
* This method initializes jComboBox
*
* @return javax.swing.JComboBox
*/

private JComboBox getJComboBox(java.util.Vector<String> listeFichiers)
{
if (jComboBox == null)
{

jComboBox = new JComboBox();

jComboBox.setForeground(Color.black);
jComboBox.setBackground(Color.green);

jComboBox.setBounds(new Rectangle(61, 150, 100, 26));
}
return jComboBox;
}

public class ListeFichiers
{
public Vector<String> listeFichiers(File dir)
{
File[] list = dir.listFiles();
Vector<String> recettes = new Vector<String>();
if (list != null)
{
for (int i = 0; i < list.length; i++)
{
if (list[i].isFile())
recettes.add(list[i].getName());
}
}
else
{
System.err.println(dir + " : répertoire inconnu.");
}
return recettes;
}

public void main(String[] args)
{
File f = new File("java\recettes");
System.out.println(listeFichiers(f));
}
}


/**
* This method initializes jEditorPane
*
* @return javax.swing.JEditorPane
*/
private JEditorPane getJEditorPane()
{
if (jEditorPane == null)
{
jEditorPane = new JEditorPane();
jEditorPane.setBounds(new Rectangle(211, 34, 192, 28));
jEditorPane.setText("Guide de recettes de cuisine");
}
return jEditorPane;

}
/**
* This method initializes jButton
* @return
*/
private JButton getJButton()
{
if (jButton == null)
{
jButton = new JButton();
jButton.setBounds(new Rectangle(392, 177, 111, 57));
jButton.setText("OK");
jButton.addActionListener(new TraitementOK());

}

return jButton;

}

public class TraitementOK implements ActionListener
{
public void actionPerformed(ActionEvent e)
{

reponse conteneur = new reponse();


conteneur.setVisible(true);
conteneur.setBounds( 0, 0,800, 800 );



}
}



/**
* This method initializes jEditorPane1
*
* @return javax.swing.JEditorPane
*/
private JEditorPane getJEditorPane1()
{
if (jEditorPane1 == null)
{
jEditorPane1 = new JEditorPane();
jEditorPane1.setBounds(new Rectangle(59, 92, 115, 23));
jEditorPane1.setText("Choix de la recette");
jEditorPane1.setForeground(Color.black);
jEditorPane1.setBackground(Color.green);
}
return jEditorPane1;
}

/**
* This method initializes jEditorPane2
*
* @return javax.swing.JEditorPane
*/
private JEditorPane getJEditorPane2()
{
if (jEditorPane2 == null)
{
jEditorPane2 = new JEditorPane();
jEditorPane2.setBounds(new Rectangle(61, 258, 146, 28));
jEditorPane2.setText("Nombre de personnes");
jEditorPane2.setForeground(Color.black);
jEditorPane2.setBackground(Color.red);
}
return jEditorPane2;
}
}



// @jve:decl-index=0:visual-constraint="10,10"


2eme classe :
import java.applet.Applet;
import java.awt.Choice;
import java.awt.Color;
import java.awt.Component;
import java.awt.Rectangle;

import javax.swing.JComboBox;
import javax.swing.JEditorPane;


public class reponse extends Applet
{

private Choice jComboBox = null;
/**
*
*/
private static final long serialVersionUID = 1L;
public void init()
{
this.setLayout(null);
this.setSize(598, 411);
this.add(getJComboBox1(), null);
}

private Choice getJComboBox1()
{
if (jComboBox == null)
{
jComboBox = new Choice();
jComboBox.addItem("1");
jComboBox.addItem("2");
jComboBox.addItem("3");
jComboBox.addItem("4");
jComboBox.addItem("5");
jComboBox.addItem("6");
jComboBox.addItem("7");
jComboBox.addItem("8");
jComboBox.setForeground(Color.black);
jComboBox.setBackground(Color.green);

jComboBox.setBounds(new Rectangle(61, 300, 151, 26));
}
return jComboBox;
}
}

1 réponse

Utilisateur anonyme
4 mai 2011 à 21:13
Salut,

Pense à utiliser les balises pour le code la prochaine fois.

Sinon je n'ai pas compris le rapport entre
une jcombobox qui recupere les fichiers dans un dossier joint au projet en fichier texte dans un dossier.
et le fais que tes JComboBox ont pleins de chiffres sans noms de fichiers...J'ai du raté un épisode je pense.

--
Pylouq (actuellement jongleur de clavier AZERTY et de clavier QWERTZ)
0
Rejoignez-nous