Problème code java
Fermé
westerndigit
Messages postés
134
Date d'inscription
mercredi 16 février 2011
Statut
Membre
Dernière intervention
18 avril 2012
-
Modifié par westerndigit le 23/02/2012 à 06:26
irmeche Messages postés 71 Date d'inscription jeudi 10 juin 2010 Statut Membre Dernière intervention 18 juillet 2014 - 25 févr. 2012 à 09:08
irmeche Messages postés 71 Date d'inscription jeudi 10 juin 2010 Statut Membre Dernière intervention 18 juillet 2014 - 25 févr. 2012 à 09:08
A voir également:
- Problème code java
- Waptrick java football - Télécharger - Jeux vidéo
- Jeux java itel football - Télécharger - Jeux vidéo
- Code asci - Guide
- Code puk bloqué - Guide
- Java apk - Télécharger - Langages
1 réponse
irmeche
Messages postés
71
Date d'inscription
jeudi 10 juin 2010
Statut
Membre
Dernière intervention
18 juillet 2014
17
Modifié par irmeche le 25/02/2012 à 09:41
Modifié par irmeche le 25/02/2012 à 09:41
voila ton programme
import java.awt.EventQueue; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileInputStream; import java.io.FileWriter; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.util.logging.Level; import java.util.logging.Logger; import javax.swing.GroupLayout; import javax.swing.JButton; import javax.swing.JLabel; import javax.swing.JScrollPane; import javax.swing.JTextArea; import javax.swing.JTextField; import javax.swing.LayoutStyle; import javax.swing.UIManager; import javax.swing.WindowConstants; public class NewJFrame extends javax.swing.JFrame { private static final long serialVersionUID = 1L; private JButton jButton1; private JButton jButton2; private JButton jButton3; private JButton jButton4; private JButton jButton5; private JLabel jLabel1; private JLabel jLabel2; private JLabel jLabel3; private JScrollPane jScrollPane1; private JTextArea jTextArea1; private JTextField jTextField1; private JTextField jTextField2; private JTextField jTextField3; public NewJFrame() { initComponents(); } private void initComponents() { setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); jTextField1 = new JTextField(); jLabel1 = new JLabel(); jButton1 = new JButton(); jScrollPane1 = new JScrollPane(); jTextArea1 = new JTextArea(); jButton2 = new JButton(); jTextField2 = new JTextField(); jTextField3 = new JTextField(); jButton3 = new JButton(); jButton4 = new JButton(); jButton5 = new JButton(); jLabel2 = new JLabel(); jLabel3 = new JLabel(); jLabel1.setText("Prénom :"); jLabel2.setText("Nom :"); jLabel3.setText("Tél :"); jTextArea1.setColumns(20); jTextArea1.setRows(5); jScrollPane1.setViewportView(jTextArea1); jButton1.setText("OK"); jButton1.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent evt) { String Chaine1, Chaine2, Chaine3; Chaine1 = jTextField1.getText(); Chaine2 = jTextField2.getText(); Chaine3 = jTextField3.getText(); jTextArea1.setText("Bonjour " + Chaine1 + " " + Chaine2 + " " + Chaine3); } }); jButton2.setText("Quitter"); jButton2.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent evt) { System.exit(0); } }); jButton3.setText("Effacer"); jButton3.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent evt) { jTextArea1.setText(""); } }); jButton4.setText("Enregistrer"); jButton4.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent evt) { String text = jTextArea1.getText(); String adressedufichier = "C:/repertoire.txt"; try { FileWriter fw = new FileWriter(adressedufichier, true); BufferedWriter output = new BufferedWriter(fw); output.write(text); output.flush(); output.close(); } catch (IOException ioe) { ioe.printStackTrace(); } } }); jButton5.setText("Recherche"); jButton5.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent evt) { String adressedufichier = "C:/repertoire.txt"; String text = ""; try { String ligne; InputStream ips = new FileInputStream(adressedufichier); InputStreamReader ipsr = new InputStreamReader(ips); BufferedReader lecteurAvecBuffer = new BufferedReader(ipsr); while ((ligne = lecteurAvecBuffer.readLine()) != null) { text += ligne + "\n"; } lecteurAvecBuffer.close(); } catch (Exception e) { e.printStackTrace(); } jTextArea1.setText(text); } }); GroupLayout layout = new GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING) .addGroup(GroupLayout.Alignment.TRAILING,layout.createSequentialGroup().addGap(39, 39, 39) .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING) .addGroup(GroupLayout.Alignment.TRAILING,layout.createSequentialGroup() .addComponent(jButton4).addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(jButton3).addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(jButton5).addPreferredGap(LayoutStyle.ComponentPlacement.RELATED, 79, Short.MAX_VALUE) .addComponent(jButton2)).addComponent(jScrollPane1, GroupLayout.DEFAULT_SIZE, 401, Short.MAX_VALUE) .addGroup(layout.createSequentialGroup().addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING) .addComponent(jLabel1).addComponent(jLabel2) .addComponent(jLabel3)).addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED) .addGroup(layout.createParallelGroup(GroupLayout.Alignment.TRAILING) .addComponent(jTextField2, GroupLayout.Alignment.LEADING, GroupLayout.DEFAULT_SIZE, 283, Short.MAX_VALUE) .addComponent(jTextField1,GroupLayout.Alignment.LEADING,GroupLayout.DEFAULT_SIZE, 283,Short.MAX_VALUE) .addComponent(jTextField3, GroupLayout.Alignment.LEADING,GroupLayout.DEFAULT_SIZE,283,Short.MAX_VALUE)).addGap(18, 18, 18) .addComponent( jButton1))).addGap(34, 34, 34))); layout.setVerticalGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup().addContainerGap() .addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE) .addComponent(jButton1).addComponent(jTextField1,GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) .addComponent(jLabel1)).addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE) .addComponent(jTextField2, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE,GroupLayout.PREFERRED_SIZE) .addComponent(jLabel2)) .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE) .addComponent(jTextField3,GroupLayout.PREFERRED_SIZE,GroupLayout.DEFAULT_SIZE,GroupLayout.PREFERRED_SIZE) .addComponent(jLabel3)).addGap(18, 18, 18) .addComponent(jScrollPane1,GroupLayout.PREFERRED_SIZE,191, GroupLayout.PREFERRED_SIZE).addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED) .addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE) .addComponent(jButton2).addComponent(jButton4) .addComponent(jButton3).addComponent(jButton5)).addContainerGap(40, Short.MAX_VALUE))); pack(); } public static void main(String args[]) { try { for (UIManager.LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) { if ("Nimbus".equals(info.getName())) { UIManager.setLookAndFeel(info.getClassName()); break; } } } catch (Exception ex) { Logger.getLogger(NewJFrame.class.getName()).log(Level.SEVERE, null, ex); } EventQueue.invokeLater(new Runnable() { public void run() { new NewJFrame().setVisible(true); } }); } }