Trouver une ressource (Nouvelle version du moteur, plus rapide & pertinent, essayez le !)
Vous ne trouvez pas de réponse à votre problème ? Alors posez la question dans le forum.
Souvenez-vous qu'il n'y a jamais de question bête, mais rester dans l'ignorance parce que l'on n'ose pas poser une question, ça c'est une erreur !
Sujet : fenetre redimensionner en click [ Divers / Débutant(e) ] (aminetsdi6)
|
fenetre redimensionner en click
le 16/07/2008 16:06:36

aminetsdi6
|
bonjour j'est un probleme , je travaille sur une application est je voudrais en click sur une button le fenêtre se redimention est safiche un jtable ,le probleme c'est que le jtable ne s affiche pas ,mais lorsque je redimension manuel le jtable saffiche if(o==">>>"){bre.setText("<<<");setSize(700,300); } else{bre.setText(">>>");setSize(300,300);} merci
|
|
|
|
Re : fenetre redimensionner en click
le 16/07/2008 23:12:34

uhrand
|
Réponse acceptée !
C'est mieux de faire la comparaison comme ceci: if (o.equals(">>>")) { As-tu essayé avec validate(), respectivement revalidate() et/ou repaint() ?
|
|
|
|
Re : fenetre redimensionner en click
le 17/07/2008 02:33:20

aminetsdi6
|
merci pour la réponse mais je suis pas comment faire ????????
|
|
|
|
Re : fenetre redimensionner en click
le 17/07/2008 02:47:24

aminetsdi6
|
voila mon application je voudrais en click sur le button (>>>) le jtable apparu
import java.awt.*; import javax.swing.*; import java.awt.event.*; import java.util.*; import java.io.*; class monproje extends JFrame { JTextField tnom=new JTextField(); JTextField tprenom=new JTextField(); JTextField tage=new JTextField(); JTextField ttelephone=new JTextField(); JButton bok=new JButton("ajout"); JButton ben=new JButton("enregistre"); JButton bch=new JButton("cherche"); JButton bre=new JButton(">>>"); JLabel lnom=new JLabel("nom :"); JLabel lprenom=new JLabel("prenom :"); JLabel lage=new JLabel("age :"); JLabel ltelephone=new JLabel("telephone :"); JPanel panel=new JPanel(); JPanel panel2=new JPanel(); public monproje(){ super("employe"); setSize(300,300); H h=new H(); bok.addActionListener(h); Ha hz=new Ha(); ben.addActionListener(hz); Hch ch=new Hch(); bch.addActionListener(ch); Hre re=new Hre(); bre.addActionListener(re); add(bre);add(bch);add(bok); add(lnom);add(lprenom);add(lage);add(ltelephone);add(ben); add(tnom);add(tprenom);add(tage);add(ttelephone); bok.setBounds(60,160,80,20);ben.setBounds(160,160,95,20);bch.setBounds(100,190,90,20);bre.setBounds(230,240,60,20); lnom.setBounds(30,20,50,20); tnom.setBounds(130,20,80,20); lprenom.setBounds(30,50,60,20);tprenom.setBounds(130,50,80,20); lage.setBounds(30,80,30,20);tage.setBounds(130,80,40,20);; ltelephone.setBounds(30,110,70,30);ttelephone.setBounds(130,110,70,20); String[] columnNames = {"Nom","Prenom","Age","Telephone"}; Object[][] data = { }; final JTable table = new JTable(data, columnNames); JScrollPane scrollPane = new JScrollPane(table); panel.setBackground(Color.blue); panel.add(scrollPane); panel.setBounds(300,10,455,100); add(panel); add(panel2); } ///////////////////////////main//////////////////////////// public static void main(String[]args){ SwingUtilities.invokeLater(new Runnable() { public void run() { } }); monproje p=new monproje(); p.setVisible(true); }public void ecrire()throws IOException{ try { ObjectInputStream entree = new ObjectInputStream(new FileInputStream("a.txt")); employe personnel[] = (employe[]) entree.readObject(); entree.close(); for (int i=0;i<personnel.length;i++) { personnel[i].toString(); } } catch (Exception ex) { } } private class Hre implements ActionListener { public void actionPerformed(ActionEvent evt) { String o; o=bre.getText(); if(o==">>>"){bre.setText("<<<");setSize(700,300); } else{bre.setText(">>>");setSize(300,300);} } } private class H implements ActionListener { public void actionPerformed(ActionEvent evt) { ajoute(); } } private class Ha implements ActionListener { public void actionPerformed(ActionEvent evt) { enregistre(); } } private class Hch implements ActionListener { public void actionPerformed(ActionEvent evt) { r(); } } Vector v=new Vector(); public void ajoute(){ if(tnom.getText().length()==0||tprenom.getText().length()==0||tage.getText().length()==0||ttelephone.getText().length()==0){ JOptionPane.showMessageDialog(null,"un ou plusieur champ son vide","erreur",JOptionPane.ERROR_MESSAGE); } else{ employe ee=new employe(tnom.getText(),tprenom.getText(),tage.getText(),ttelephone.getText()); v.add(ee); tnom.setText(""); tprenom.setText(""); ttelephone.setText(""); tage.setText(""); JOptionPane.showMessageDialog(null,"l'employe est enregistre"); } } public void enregistre() { try { PrintWriter f = new PrintWriter(new FileWriter("a.txt")); f.print(v); f.close(); JOptionPane.showMessageDialog(null,"enregistre"); } catch (Exception ex) { System.out.println ("a"); } } public void r(){ String ch ; ch=JOptionPane.showInputDialog("entrez le nom que vous voules cherche"); boolean a=false; for(int i=0;i<v.size();i++){ if(((employe)v.get(i)).getNom().equals(ch)){ a=true; tprenom.setText(((employe)v.get(i)).getPrenom()); tnom.setText(((employe)v.get(i)).getNom()); tage.setText(((employe)v.get(i)).getAge()); ttelephone.setText(((employe)v.get(i)).getTelephone()); } } if(a==false){ JOptionPane.showMessageDialog(null,"se nom n'est pas enregistre"); } } }
|
|
|
|
Re : fenetre redimensionner en click
le 17/07/2008 11:22:37

uhrand
|
Réponse acceptée !
Le positionnement avec setBounds n'est pas conseillé. Apprends à utiliser les LayoutManager. Voici un exemple avec GridBagLayout: package test; /* * FenetreEmploye.java */
import java.awt.*; import javax.swing.*; import java.awt.event.*; import java.util.*; import java.io.*;
class FenetreEmploye extends JFrame {
private JTextField tnom = new JTextField(); private JTextField tprenom = new JTextField(); private JTextField tage = new JTextField(); private JTextField ttelephone = new JTextField(); private JButton btAjoute = new JButton("ajout"); private JButton btEnregistre = new JButton("enregistre"); private JButton btRecherche = new JButton("cherche"); private JButton btResize = new JButton(">>>"); private JLabel lnom = new JLabel("nom :"); private JLabel lprenom = new JLabel("prenom :"); private JLabel lage = new JLabel("age :"); private JLabel ltelephone = new JLabel("telephone :"); private JTable table; private JScrollPane scrollPane;
public FenetreEmploye() { super("Employe"); java.awt.GridBagConstraints gridBagConstraints; lnom.setPreferredSize(new Dimension(70, 20)); lprenom.setPreferredSize(new Dimension(70, 20)); lage.setPreferredSize(new Dimension(70, 20)); ltelephone.setPreferredSize(new Dimension(70, 20)); tnom.setPreferredSize(new Dimension(70, 20)); tprenom.setPreferredSize(new Dimension(70, 20)); tage.setPreferredSize(new Dimension(70, 20)); ttelephone.setPreferredSize(new Dimension(70, 20));
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); getContentPane().setLayout(new java.awt.GridBagLayout());
gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5); getContentPane().add(lnom, gridBagConstraints);
gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5); getContentPane().add(tnom, gridBagConstraints);
gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 1; gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5); getContentPane().add(lprenom, gridBagConstraints);
gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 1; gridBagConstraints.gridy = 1; gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5); getContentPane().add(tprenom, gridBagConstraints);
gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 2; gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5); getContentPane().add(lage, gridBagConstraints);
gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 1; gridBagConstraints.gridy = 2; gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5); getContentPane().add(tage, gridBagConstraints);
gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 3; gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5); getContentPane().add(ltelephone, gridBagConstraints);
gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 1; gridBagConstraints.gridy = 3; gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5); getContentPane().add(ttelephone, gridBagConstraints);
gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 4; gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5); getContentPane().add(btAjoute, gridBagConstraints);
gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 1; gridBagConstraints.gridy = 4; gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5); getContentPane().add(btEnregistre, gridBagConstraints);
gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 2; gridBagConstraints.gridy = 4; gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5); getContentPane().add(btRecherche, gridBagConstraints);
gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 2; gridBagConstraints.gridy = 5; gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5); getContentPane().add(btResize, gridBagConstraints);
gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 3; gridBagConstraints.gridy = 0; gridBagConstraints.gridheight = 6; String[] columnNames = {"Nom", "Prenom", "Age", "Telephone"}; Object[][] data = {}; table = new JTable(data, columnNames); table.setPreferredScrollableViewportSize(new Dimension(400, 150)); scrollPane = new JScrollPane(table); getContentPane().add(scrollPane, gridBagConstraints); scrollPane.setVisible(false); pack();
ActionAjoute actionAjoute = new ActionAjoute(); btAjoute.addActionListener(actionAjoute); ActionEnregistre actionEnregistre = new ActionEnregistre(); btEnregistre.addActionListener(actionEnregistre); ActionRecherche actionRecherche = new ActionRecherche(); btRecherche.addActionListener(actionRecherche); ActionResize actionResize = new ActionResize(); btResize.addActionListener(actionResize); } ///////////////////////////main//////////////////////////// public static void main(final String[] args) { SwingUtilities.invokeLater(new Runnable() {
@Override public void run() { new FenetreEmploye().setVisible(true); } }); }
public void ecrire() throws IOException { try {
ObjectInputStream entree = new ObjectInputStream(new FileInputStream("a.txt")); Employe[] personnel = (Employe[]) entree.readObject(); entree.close();
for (int i = 0; i < personnel.length; i++) { personnel[i].toString();
} } catch (Exception ex) { }
}
private class ActionResize implements ActionListener {
@Override public void actionPerformed(final ActionEvent evt) { String o; o = btResize.getText(); if (o.equals(">>>")) { scrollPane.setVisible(true); btResize.setText("<<<"); pack(); } else { scrollPane.setVisible(false); btResize.setText(">>>"); pack(); } } }
private class ActionAjoute implements ActionListener {
@Override public void actionPerformed(final ActionEvent evt) { ajoute(); } }
private class ActionEnregistre implements ActionListener {
@Override public void actionPerformed(final ActionEvent evt) { enregistre(); } }
private class ActionRecherche implements ActionListener {
@Override public void actionPerformed(final ActionEvent evt) { recherche(); } } Vector v = new Vector();
public void ajoute() { if (tnom.getText().length() == 0 || tprenom.getText().length() == 0 || tage.getText().length() == 0 || ttelephone.getText().length() == 0) { JOptionPane.showMessageDialog(null, "un ou plusieur champ son vide", "erreur", JOptionPane.ERROR_MESSAGE); } else {
Employe ee = new Employe(tnom.getText(), tprenom.getText(), tage.getText(), ttelephone.getText()); v.add(ee); tnom.setText(""); tprenom.setText(""); ttelephone.setText(""); tage.setText(""); JOptionPane.showMessageDialog(null, "l'employe est enregistre"); } }
public void enregistre() { try { PrintWriter f = new PrintWriter(new FileWriter("a.txt")); f.print(v); f.close(); JOptionPane.showMessageDialog(null, "enregistre"); } catch (Exception ex) { System.out.println("a"); }
}
public void recherche() { String nomRecherche; nomRecherche = JOptionPane.showInputDialog("entrez le nom que vous voulez chercher"); boolean a = false; for (int i = 0; i < v.size(); i++) { if (((Employe) v.get(i)).getNom().equals(nomRecherche)) { a = true; tprenom.setText(((Employe) v.get(i)).getPrenom()); tnom.setText(((Employe) v.get(i)).getNom()); tage.setText(((Employe) v.get(i)).getAge()); ttelephone.setText(((Employe) v.get(i)).getTelephone()); } } if (a == false) { JOptionPane.showMessageDialog(null, "ce nom n'est pas enregistre"); }
} }
class Employe {
private String nom; private String prenom; private String age; private String telephone;
Employe(final String nom, final String prenom, final String age, final String telephone) { this.nom = nom; this.prenom = prenom; this.age = age; this.telephone = telephone; }
public String getAge() { return age; }
public String getNom() { return nom; }
public String getPrenom() { return prenom; }
public String getTelephone() { return telephone; } }
|
|
|
|
Re : fenetre redimensionner en click
le 17/07/2008 15:04:19

aminetsdi6
|
merci pour le code ,je veux recuperer les information du fichier dans les execution de l'application(load)
|
|
|
|
Re : fenetre redimensionner en click
le 17/07/2008 19:57:05

uhrand
|
Réponse acceptée !
Voici un exemple avec XMLEncoder/XMLDencoder: EmployeDemo.jar (code source dans le jar)
|
|
|
|
Re : fenetre redimensionner en click
le 17/07/2008 20:15:09
|
|
Re : fenetre redimensionner en click
le 17/07/2008 20:42:28

uhrand
|
Attention! Il faut bien lire 
|
|
|
|
Re : fenetre redimensionner en click
le 17/07/2008 21:44:47

aminetsdi6
|
dsl pour le derangement mais le code source s'execute pas si vous pouvez me lancer le fichier .java :) merci d avance
|
|
|
Classé sous : probleme, fenetre, click, jtable, redimensionner
|
CalendriCode
| | | L | M | M | J | V | S | D |
| | | | | 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 |
|
Téléchargements
Logiciels à télécharger sur le même thème :
|