HELP POUR DU JAVA
Résolu/Fermé
femeril1805
Messages postés
29
Date d'inscription
jeudi 19 novembre 2009
Statut
Membre
Dernière intervention
20 janvier 2011
-
19 nov. 2009 à 10:11
vintz72 - 22 déc. 2009 à 10:11
vintz72 - 22 déc. 2009 à 10:11
A voir également:
- Exception in thread "awt-eventqueue-0" java.lang.unsupportedoperationexception: not supported yet.
- Waptrick java football - Télécharger - Jeux vidéo
- Jeux java itel football - Télécharger - Jeux vidéo
- Java apk - Télécharger - Langages
- Waptrick java voiture - Télécharger - Jeux vidéo
- Java décompiler - Télécharger - Langages
22 réponses
sandul
Messages postés
3927
Date d'inscription
jeudi 22 mai 2008
Statut
Membre
Dernière intervention
8 octobre 2010
723
19 nov. 2009 à 11:40
19 nov. 2009 à 11:40
Ah, c'est une erreur de COMPILATION ? Ca change tout, lol. Je pensais qu'il s'agissait d'une erreur de runtime. Ben, pour la compil: tu es sous Eclipse, à tout hasard ?
sandul
Messages postés
3927
Date d'inscription
jeudi 22 mai 2008
Statut
Membre
Dernière intervention
8 octobre 2010
723
19 nov. 2009 à 10:31
19 nov. 2009 à 10:31
Salut,
Je n'ai pas lu tout ton code, mais l'exception obtenue est simple: NullPointer = une variable qui n'est pas initialisée. Et ta ligne est
Regardons la variable model. Déclaration:
Initialisation dans le constructeur de AddFrame
Tu ne donnes pas le code (il me semble) d'appel de ce constructeur. Je pense que tu l'appelles avec un paramètre personsTableModel à null (vérifie ceci en mode debug).
++
Je n'ai pas lu tout ton code, mais l'exception obtenue est simple: NullPointer = une variable qui n'est pas initialisée. Et ta ligne est
this.model.refreshPerson(person)
Regardons la variable model. Déclaration:
private PersonsModel model = null;
Initialisation dans le constructeur de AddFrame
this.model = personsTableModel;
Tu ne donnes pas le code (il me semble) d'appel de ce constructeur. Je pense que tu l'appelles avec un paramètre personsTableModel à null (vérifie ceci en mode debug).
++
femeril1805
Messages postés
29
Date d'inscription
jeudi 19 novembre 2009
Statut
Membre
Dernière intervention
20 janvier 2011
19 nov. 2009 à 11:16
19 nov. 2009 à 11:16
Je n'ai pas compris ta phrase "Tu ne donnes pas le code (il me semble) d'appel de ce constructeur. Je pense que tu l'appelles avec un paramètre personsTableModel à null (vérifie ceci en mode debug).
"
de quel code parles-tu ?
"
de quel code parles-tu ?
sandul
Messages postés
3927
Date d'inscription
jeudi 22 mai 2008
Statut
Membre
Dernière intervention
8 octobre 2010
723
>
femeril1805
Messages postés
29
Date d'inscription
jeudi 19 novembre 2009
Statut
Membre
Dernière intervention
20 janvier 2011
19 nov. 2009 à 11:20
19 nov. 2009 à 11:20
Ben, ton code posté n'est pas complet, n'est-ce pas ? Tu as une classe AddFrame avec 2 constructeurs. Mais je ne vois pas où tu appelles ces constructeurs (avec un new AddFrame(...))
choubaka
Messages postés
39420
Date d'inscription
jeudi 4 avril 2002
Statut
Modérateur
Dernière intervention
19 février 2025
2 104
19 nov. 2009 à 11:18
19 nov. 2009 à 11:18
salut
j'ai un peu regardé ton code, il y a un truc bizarre aussi...
public static final int MODE_CREATE = 0;
public static final int MODE_UPDATE = 1;
private int mode = MODE_CREATE;
Je remarque aussi qu'un peu partout dans ton code, la valeur de ta variable sera modifiée puis testée par rapport aux attributs statiques...
Je me pose donc la question si le fait de créer un objet sur base de cette condition n'est pas la source du problème.
la valeur de la variable "mode" me paraît "nébuleuse".
j'ai un peu regardé ton code, il y a un truc bizarre aussi...
public static final int MODE_CREATE = 0;
public static final int MODE_UPDATE = 1;
private int mode = MODE_CREATE;
Je remarque aussi qu'un peu partout dans ton code, la valeur de ta variable sera modifiée puis testée par rapport aux attributs statiques...
Je me pose donc la question si le fait de créer un objet sur base de cette condition n'est pas la source du problème.
if (mode == MODE_CREATE) { Person newPerson = new Person(); newPerson.setFirstName(textFirstName.getText()); newPerson.setLastName(textLastName.getText()); this.model.addPerson(newPerson);
la valeur de la variable "mode" me paraît "nébuleuse".
femeril1805
Messages postés
29
Date d'inscription
jeudi 19 novembre 2009
Statut
Membre
Dernière intervention
20 janvier 2011
19 nov. 2009 à 11:22
19 nov. 2009 à 11:22
ça m'aide pas vraiment j'ai pas très bien saisi à vrai dire..
Je galère tjrs snif..
Je galère tjrs snif..
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre question
choubaka
Messages postés
39420
Date d'inscription
jeudi 4 avril 2002
Statut
Modérateur
Dernière intervention
19 février 2025
2 104
19 nov. 2009 à 11:28
19 nov. 2009 à 11:28
ok ...
j'ai quand même une question..
pourquoi deux constructeurs ?
Personnellement, je verrais bien deux classes (frame) distinctes. Une pour la création et une pour l'update.
Vu qu'apparemment, le mode (crate ou upgrade) est connu puisqu'il est mis en argument dans l'appel des constructeurs.
j'ai quand même une question..
pourquoi deux constructeurs ?
Personnellement, je verrais bien deux classes (frame) distinctes. Une pour la création et une pour l'update.
Vu qu'apparemment, le mode (crate ou upgrade) est connu puisqu'il est mis en argument dans l'appel des constructeurs.
femeril1805
Messages postés
29
Date d'inscription
jeudi 19 novembre 2009
Statut
Membre
Dernière intervention
20 janvier 2011
19 nov. 2009 à 11:29
19 nov. 2009 à 11:29
LE MESSAGE D'ERREUR QUE J'AI EN COMPILANT
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at crudapplication.AddFrame.okButtonActionPerformed(AddFrame.java:169)
at crudapplication.AddFrame.access$200(AddFrame.java:21)
at crudapplication.AddFrame$3.actionPerformed(AddFrame.java:102)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
at java.awt.Component.processMouseEvent(Component.java:6263)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3267)
at java.awt.Component.processEvent(Component.java:6028)
at java.awt.Container.processEvent(Container.java:2041)
at java.awt.Component.dispatchEventImpl(Component.java:4630)
at java.awt.Container.dispatchEventImpl(Container.java:2099)
at java.awt.Component.dispatchEvent(Component.java:4460)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4574)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4238)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4168)
at java.awt.Container.dispatchEventImpl(Container.java:2085)
at java.awt.Window.dispatchEventImpl(Window.java:2475)
at java.awt.Component.dispatchEvent(Component.java:4460)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at crudapplication.AddFrame.okButtonActionPerformed(AddFrame.java:169)
at crudapplication.AddFrame.access$200(AddFrame.java:21)
at crudapplication.AddFrame$3.actionPerformed(AddFrame.java:102)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
at java.awt.Component.processMouseEvent(Component.java:6263)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3267)
at java.awt.Component.processEvent(Component.java:6028)
at java.awt.Container.processEvent(Container.java:2041)
at java.awt.Component.dispatchEventImpl(Component.java:4630)
at java.awt.Container.dispatchEventImpl(Container.java:2099)
at java.awt.Component.dispatchEvent(Component.java:4460)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4574)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4238)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4168)
at java.awt.Container.dispatchEventImpl(Container.java:2085)
at java.awt.Window.dispatchEventImpl(Window.java:2475)
at java.awt.Component.dispatchEvent(Component.java:4460)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
femeril1805
Messages postés
29
Date d'inscription
jeudi 19 novembre 2009
Statut
Membre
Dernière intervention
20 janvier 2011
19 nov. 2009 à 11:36
19 nov. 2009 à 11:36
Help please....
sandul
Messages postés
3927
Date d'inscription
jeudi 22 mai 2008
Statut
Membre
Dernière intervention
8 octobre 2010
723
19 nov. 2009 à 11:38
19 nov. 2009 à 11:38
Help please....
Nanméoh... Faut lire les réponses, bonhomme... Sinon tu ne peux pas avancer
Nanméoh... Faut lire les réponses, bonhomme... Sinon tu ne peux pas avancer
femeril1805
Messages postés
29
Date d'inscription
jeudi 19 novembre 2009
Statut
Membre
Dernière intervention
20 janvier 2011
19 nov. 2009 à 11:48
19 nov. 2009 à 11:48
NetBeans... je ne vois tjrs pas où ça cloche pourtant NullPointer = une variable qui n'est pas initialisée comme tu dis ;
tout dépend de cette ligne "this.model.refreshPerson(person)"
c'est model qui est mal instancié ? person ?
public class AddFrame extends javax.swing.JFrame {
private PersonsModel model = null;)
private Person person = null;)
.....
public AddFrame(PersonsModel personsTableModel, int mode) {
this.model = personsTableModel;
initComponents();
setVisible(true);
setMode(mode);
}
public AddFrame(PersonsModel personsTableModel, int mode, Person person) {
this(personsTableModel, mode);
this.person = person;
textFirstName.setText(person.getFirstName());
textLastName.setText(person.getLastName());
}
private void setMode(int mode) {
this.mode = mode;
if (mode == MODE_CREATE) {
this.setTitle("Create Mode");
} else {
this.setTitle("Update Mode");
}
}
private void okButtonActionPerformed(java.awt.event.ActionEvent evt) {
if ((textFirstName.getText().length() > 0) && (textLastName.getText().length() > 0)) {
if (mode == MODE_CREATE) {
Person newPerson = new Person();
newPerson.setFirstName(textFirstName.getText());
newPerson.setLastName(textLastName.getText());
this.model.addPerson(newPerson);
} else {
this.person.setFirstName(textFirstName.getText());
this.person.setLastName(textLastName.getText());
======================================================================
this.model.refreshPerson(person);<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
======================================================================
}
this.dispose();
}
======================================================================
la méthode refreshPerson
public void refreshPerson(Person person) {
int rowIndex = persons.indexOf(person);
fireTableRowsUpdated(rowIndex, rowIndex);
}
======================================================================
Est ce que tu y vois un peu plus claire ??
tout dépend de cette ligne "this.model.refreshPerson(person)"
c'est model qui est mal instancié ? person ?
public class AddFrame extends javax.swing.JFrame {
private PersonsModel model = null;)
private Person person = null;)
.....
public AddFrame(PersonsModel personsTableModel, int mode) {
this.model = personsTableModel;
initComponents();
setVisible(true);
setMode(mode);
}
public AddFrame(PersonsModel personsTableModel, int mode, Person person) {
this(personsTableModel, mode);
this.person = person;
textFirstName.setText(person.getFirstName());
textLastName.setText(person.getLastName());
}
private void setMode(int mode) {
this.mode = mode;
if (mode == MODE_CREATE) {
this.setTitle("Create Mode");
} else {
this.setTitle("Update Mode");
}
}
private void okButtonActionPerformed(java.awt.event.ActionEvent evt) {
if ((textFirstName.getText().length() > 0) && (textLastName.getText().length() > 0)) {
if (mode == MODE_CREATE) {
Person newPerson = new Person();
newPerson.setFirstName(textFirstName.getText());
newPerson.setLastName(textLastName.getText());
this.model.addPerson(newPerson);
} else {
this.person.setFirstName(textFirstName.getText());
this.person.setLastName(textLastName.getText());
======================================================================
this.model.refreshPerson(person);<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
======================================================================
}
this.dispose();
}
======================================================================
la méthode refreshPerson
public void refreshPerson(Person person) {
int rowIndex = persons.indexOf(person);
fireTableRowsUpdated(rowIndex, rowIndex);
}
======================================================================
Est ce que tu y vois un peu plus claire ??
sandul
Messages postés
3927
Date d'inscription
jeudi 22 mai 2008
Statut
Membre
Dernière intervention
8 octobre 2010
723
19 nov. 2009 à 11:51
19 nov. 2009 à 11:51
[Edit]
L'étude du stack trace ne dévoile pas une erreur de compil, mais une erreur d'exécution :P
Est ce que tu y vois un peu plus claire ??
Nan, pas du tout. Car tu ne postes toujours pas le morceau de code demandé. Regarde donc l'endroit où tu fais un new AddFrame(...) dans ton code et assure-toi de ne pas passer un paramètre non initialisé. Voilou ///
L'étude du stack trace ne dévoile pas une erreur de compil, mais une erreur d'exécution :P
Est ce que tu y vois un peu plus claire ??
Nan, pas du tout. Car tu ne postes toujours pas le morceau de code demandé. Regarde donc l'endroit où tu fais un new AddFrame(...) dans ton code et assure-toi de ne pas passer un paramètre non initialisé. Voilou ///
femeril1805
Messages postés
29
Date d'inscription
jeudi 19 novembre 2009
Statut
Membre
Dernière intervention
20 janvier 2011
19 nov. 2009 à 11:57
19 nov. 2009 à 11:57
Je ne fais jamais de new AddFram()...
sandul
Messages postés
3927
Date d'inscription
jeudi 22 mai 2008
Statut
Membre
Dernière intervention
8 octobre 2010
723
19 nov. 2009 à 11:58
19 nov. 2009 à 11:58
Et comment appelles-tu le constructeur, alors ? Par introspection ?
choubaka
Messages postés
39420
Date d'inscription
jeudi 4 avril 2002
Statut
Modérateur
Dernière intervention
19 février 2025
2 104
19 nov. 2009 à 12:02
19 nov. 2009 à 12:02
ici ?
this(personsTableModel, mode);
this(personsTableModel, mode);
femeril1805
Messages postés
29
Date d'inscription
jeudi 19 novembre 2009
Statut
Membre
Dernière intervention
20 janvier 2011
19 nov. 2009 à 12:05
19 nov. 2009 à 12:05
Le mieux c'est de vous montrer tout mon code et d'essayer de l'executer depuis votre poste
/*
* CrudApplication.java
*/
package crudapplication;
import org.jdesktop.application.Application;
import org.jdesktop.application.SingleFrameApplication;
/**
* The main class of the application.
*/
public class CrudApplication extends SingleFrameApplication {
/**
* At startup create and show the main frame of the application.
*/
@Override protected void startup() {
show(new CrudFrame());
}
/**
* This method is to initialize the specified window by injecting resources.
* Windows shown in our application come fully initialized from the GUI
* builder, so this additional configuration is not needed.
*/
@Override protected void configureWindow(java.awt.Window root) {
}
/**
* A convenient static getter for the application instance.
* @return the instance of CrudApplication
*/
public static CrudApplication getApplication() {
return Application.getInstance(CrudApplication.class);
}
/**
* Main method launching the application.
*/
public static void main(String[] args) {
launch(CrudApplication.class, args);
}
}
======================================================================
======================================================================
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/*
* CurdFrame.java
*
* Created on 8 nov. 2009, 14:16:50
*/
package crudapplication;
import crudapplication.actions.AddAction;
import crudapplication.actions.DelAction;
import crudapplication.actions.LoadAction;
import crudapplication.actions.SaveAction;
import crudapplication.actions.UpdateAction;
import java.awt.event.InputEvent;
import java.awt.event.KeyEvent;
import javax.swing.Action;
import javax.swing.KeyStroke;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
/**
*
* @author Administrateur
*/
public class CrudFrame extends javax.swing.JFrame {
PersonsModel tableModel = null;
private boolean a = true;
private boolean b = false;
private Action loadAction = null;
private Action addAction = null;
private DelAction delAction = null;
private UpdateAction updAction = null;
private Action saveAction = null;
/** Creates new form CurdFrame */
public CrudFrame() {
super("CRUD_FRAME_APPLICATION");
initComponents();
creationTable.setComponentPopupMenu(jPopupMenu1);
tableModel = new PersonsModel();
creationTable.setModel(tableModel);
creationTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
public void valueChanged(ListSelectionEvent e) {
int[] selectedRows = creationTable.getSelectedRows();
for (int row = 0; row < selectedRows.length; row++) {
selectedRows[row] = creationTable.convertRowIndexToModel(row);
}
delAction.setSelectedRows(selectedRows);
updAction.setSelectedRows(selectedRows);
}
}); //int selectedRow = creationTable.convertRowIndexToModel(creationTable.getSelectedRow());
//==============================================================================
// ACTIONS
//==============================================================================
loadAction = new LoadAction(tableModel);
saveAction = new SaveAction(tableModel);
addAction = new AddAction(tableModel);
delAction = new DelAction(tableModel);
delAction.setEnabled(false);
updAction = new UpdateAction(tableModel);
updAction.setEnabled(false);
//==============================================================================
//Setting action
//==============================================================================
bLoad.setAction(loadAction);
loadMenuItem.setAction(loadAction);
loadMenuItem.setMnemonic(KeyEvent.VK_L);
loadMenuItem.setAccelerator(KeyStroke.getKeyStroke('L',InputEvent.CTRL_DOWN_MASK));
bSave.setAction(saveAction);
saveAsMenuItem.setAction(saveAction);
saveAsMenuItem.setMnemonic(KeyEvent.VK_S);
saveAsMenuItem.setAccelerator(KeyStroke.getKeyStroke('S',InputEvent.CTRL_DOWN_MASK));
bAdd.setAction(addAction);
bDel.setAction(delAction);
deleteMenuItem.setAction(delAction);
deleteMenuItem.setMnemonic(KeyEvent.VK_DELETE);
//deleteMenuItem.setAccelerator(KeyStroke.getKeyStroke('Supprimer',InputEvent.
bUp.setAction(updAction);
jPopupMenu1.add(delAction);
jPopupMenu1.add(updAction);
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jPopupMenu1 = new javax.swing.JPopupMenu();
jScrollPane1 = new javax.swing.JScrollPane();
creationTable = new javax.swing.JTable();
bAdd = new javax.swing.JButton();
bDel = new javax.swing.JButton();
bUp = new javax.swing.JButton();
bLoad = new javax.swing.JButton();
bSave = new javax.swing.JButton();
jMenuBar1 = new javax.swing.JMenuBar();
jMenu1 = new javax.swing.JMenu();
loadMenuItem = new javax.swing.JMenuItem();
saveAsMenuItem = new javax.swing.JMenuItem();
jSeparator1 = new javax.swing.JSeparator();
exitMenuItem = new javax.swing.JMenuItem();
jMenu2 = new javax.swing.JMenu();
deleteMenuItem = new javax.swing.JMenuItem();
jPopupMenu1.setName("jPopupMenu1"); // NOI18N
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setName("Form"); // NOI18N
jScrollPane1.setName("jScrollPane1"); // NOI18N
creationTable.setAutoCreateRowSorter(true);
creationTable.setModel(new javax.swing.table.DefaultTableModel(
new Object [][] {
{null, null, null, null},
{null, null, null, null},
{null, null, null, null},
{null, null, null, null}
},
new String [] {
"Title 1", "Title 2", "Title 3", "Title 4"
}
));
creationTable.setName("creationTable"); // NOI18N
jScrollPane1.setViewportView(creationTable);
org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(crudapplication.CrudApplication.class).getContext().getResourceMap(CrudFrame.class);
creationTable.getColumnModel().getColumn(0).setHeaderValue(resourceMap.getString("creationTable.columnModel.title0")); // NOI18N
creationTable.getColumnModel().getColumn(1).setHeaderValue(resourceMap.getString("creationTable.columnModel.title1")); // NOI18N
creationTable.getColumnModel().getColumn(2).setHeaderValue(resourceMap.getString("creationTable.columnModel.title2")); // NOI18N
creationTable.getColumnModel().getColumn(3).setHeaderValue(resourceMap.getString("creationTable.columnModel.title3")); // NOI18N
bAdd.setText(resourceMap.getString("bAdd.text")); // NOI18N
bAdd.setName("bAdd"); // NOI18N
bDel.setText(resourceMap.getString("bDel.text")); // NOI18N
bDel.setEnabled(false);
bDel.setName("bDel"); // NOI18N
bUp.setText(resourceMap.getString("bUp.text")); // NOI18N
bUp.setEnabled(false);
bUp.setName("bUp"); // NOI18N
bLoad.setText(resourceMap.getString("bLoad.text")); // NOI18N
bLoad.setName("bLoad"); // NOI18N
bSave.setText(resourceMap.getString("bSave.text")); // NOI18N
bSave.setName("bSave"); // NOI18N
jMenuBar1.setName("jMenuBar1"); // NOI18N
jMenu1.setText(resourceMap.getString("jMenu1.text")); // NOI18N
jMenu1.setName("jMenu1"); // NOI18N
loadMenuItem.setText(resourceMap.getString("loadMenuItem.text")); // NOI18N
loadMenuItem.setName("loadMenuItem"); // NOI18N
jMenu1.add(loadMenuItem);
saveAsMenuItem.setText(resourceMap.getString("saveAsMenuItem.text")); // NOI18N
saveAsMenuItem.setName("saveAsMenuItem"); // NOI18N
jMenu1.add(saveAsMenuItem);
jSeparator1.setName("jSeparator1"); // NOI18N
jMenu1.add(jSeparator1);
exitMenuItem.setText(resourceMap.getString("exitMenuItem.text")); // NOI18N
exitMenuItem.setName("exitMenuItem"); // NOI18N
jMenu1.add(exitMenuItem);
jMenuBar1.add(jMenu1);
jMenu2.setText(resourceMap.getString("jMenu2.text")); // NOI18N
jMenu2.setName("jMenu2"); // NOI18N
deleteMenuItem.setText(resourceMap.getString("deleteMenuItem.text")); // NOI18N
deleteMenuItem.setName("deleteMenuItem"); // NOI18N
jMenu2.add(deleteMenuItem);
jMenuBar1.add(jMenu2);
setJMenuBar(jMenuBar1);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(bAdd)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(bDel)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(bUp))
.addGroup(layout.createSequentialGroup()
.addComponent(bLoad)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(bSave))
.addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 420, Short.MAX_VALUE))
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(bLoad)
.addComponent(bSave))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 317, Short.MAX_VALUE)
.addGap(16, 16, 16)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(bAdd)
.addComponent(bDel)
.addComponent(bUp))
.addContainerGap())
);
pack();
}// </editor-fold>
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new CrudFrame().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JButton bAdd;
private javax.swing.JButton bDel;
private javax.swing.JButton bLoad;
private javax.swing.JButton bSave;
private javax.swing.JButton bUp;
private javax.swing.JTable creationTable;
private javax.swing.JMenuItem deleteMenuItem;
private javax.swing.JMenuItem exitMenuItem;
private javax.swing.JMenu jMenu1;
private javax.swing.JMenu jMenu2;
private javax.swing.JMenuBar jMenuBar1;
private javax.swing.JPopupMenu jPopupMenu1;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JSeparator jSeparator1;
private javax.swing.JMenuItem loadMenuItem;
private javax.swing.JMenuItem saveAsMenuItem;
// End of variables declaration
}
======================================================================
======================================================================
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package crudapplication;
import java.util.ArrayList;
import java.util.List;
import javax.swing.table.AbstractTableModel;
/**
*
* @author Administrateur
*/
public class PersonsModel extends AbstractTableModel {
private static String[] columns = {"FirstName", "LastName"};
private List<Person> persons = new ArrayList<Person>();
public PersonsModel() {
/* Person person = new Person();
person.setFirstName("Rachid");
person.setLastName("FLICI");
persons.add(person);
Person person2 = new Person();
person2.setFirstName("Jean");
person2.setLastName("AUDIBERT");
persons.add(person2);
Person person3 = new Person();
person3.setFirstName("Saïd");
person3.setLastName("LAYADI");
persons.add(person3);*/
}
public void addPerson(Person person) {
persons.add(person);
int rowIndex = persons.indexOf(person);
this.fireTableRowsInserted(rowIndex, rowIndex);
}
public Person getPerson(int indexRowSelected) {
return persons.get(indexRowSelected);
}
public List<Person> getAll() {
return this.persons;
}
public void removePerson(int indexRowSelected) {
persons.remove(indexRowSelected);
this.fireTableRowsDeleted(indexRowSelected, indexRowSelected);
}
public void refreshPerson(Person person) {
int rowIndex = persons.indexOf(person);
fireTableRowsUpdated(rowIndex, rowIndex);
}
@Override
public String getColumnName(int column) {
try {
return columns[column];
} catch (ArrayIndexOutOfBoundsException e) {
return "N/A";
}
}
public int getRowCount() {
// throw new UnsupportedOperationException("Not supported yet.");
return persons.size();
}
public int getColumnCount() {
// throw new UnsupportedOperationException("Not supported yet.");
return 2;
}
public Object getValueAt(int rowIndex, int columnIndex) {
//throw new UnsupportedOperationException("Not supported yet.");
Object valeur;
Person person = persons.get(rowIndex);
switch (columnIndex) {
case 0:
valeur = person.getFirstName();
break;
case 1:
valeur = person.getLastName();
break;
default:
valeur = null;
}
return valeur;
}
@Override
public boolean isCellEditable(int rowIndex, int columnIndex) {
return true;
}
@Override
public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
Person person = this.persons.get(rowIndex);
switch (columnIndex) {
case 0:
person.setFirstName(aValue.toString());
break;
case 1:
person.setLastName(aValue.toString());
break;
}
}
public void removePerson(int[] selectedRows) {
List<Person> toDelete = new ArrayList<Person>(selectedRows.length);
for (int i = 0; i < selectedRows.length; i++) {
toDelete.add(persons.get(i));
}
for (Person person : toDelete) {
int index = persons.indexOf(person);
persons.remove(person);
this.fireTableRowsDeleted(index, index);
}
}
}
======================================================================
======================================================================
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package crudapplication.actions;
import crudapplication.AddFrame;
import crudapplication.Person;
import crudapplication.PersonsModel;
import java.awt.event.ActionEvent;
import javax.swing.AbstractAction;
/**
*
* @author FRWD9529
*/
public class UpdateAction extends AbstractAction {
private PersonsModel tableModel = null;
int selectedRow = -1;
public UpdateAction(PersonsModel tableModel) {
super("Update");
this.tableModel = tableModel;
}
public void setSelectedRows(int[] selectedRows) {
setEnabled(selectedRows.length == 1);
if (selectedRows.length == 1) {
this.selectedRow = selectedRows[0];
} else {
this.selectedRow = -1;
}
}
public void actionPerformed(ActionEvent e) {
if (this.selectedRow == -1) return;
Person person = tableModel.getPerson(selectedRow);
AddFrame updatePerson = new AddFrame(null, AddFrame.MODE_UPDATE, person);
}
}
============================================================================================================================================
/*
* CrudApplication.java
*/
package crudapplication;
import org.jdesktop.application.Application;
import org.jdesktop.application.SingleFrameApplication;
/**
* The main class of the application.
*/
public class CrudApplication extends SingleFrameApplication {
/**
* At startup create and show the main frame of the application.
*/
@Override protected void startup() {
show(new CrudFrame());
}
/**
* This method is to initialize the specified window by injecting resources.
* Windows shown in our application come fully initialized from the GUI
* builder, so this additional configuration is not needed.
*/
@Override protected void configureWindow(java.awt.Window root) {
}
/**
* A convenient static getter for the application instance.
* @return the instance of CrudApplication
*/
public static CrudApplication getApplication() {
return Application.getInstance(CrudApplication.class);
}
/**
* Main method launching the application.
*/
public static void main(String[] args) {
launch(CrudApplication.class, args);
}
}
======================================================================
======================================================================
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/*
* CurdFrame.java
*
* Created on 8 nov. 2009, 14:16:50
*/
package crudapplication;
import crudapplication.actions.AddAction;
import crudapplication.actions.DelAction;
import crudapplication.actions.LoadAction;
import crudapplication.actions.SaveAction;
import crudapplication.actions.UpdateAction;
import java.awt.event.InputEvent;
import java.awt.event.KeyEvent;
import javax.swing.Action;
import javax.swing.KeyStroke;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
/**
*
* @author Administrateur
*/
public class CrudFrame extends javax.swing.JFrame {
PersonsModel tableModel = null;
private boolean a = true;
private boolean b = false;
private Action loadAction = null;
private Action addAction = null;
private DelAction delAction = null;
private UpdateAction updAction = null;
private Action saveAction = null;
/** Creates new form CurdFrame */
public CrudFrame() {
super("CRUD_FRAME_APPLICATION");
initComponents();
creationTable.setComponentPopupMenu(jPopupMenu1);
tableModel = new PersonsModel();
creationTable.setModel(tableModel);
creationTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
public void valueChanged(ListSelectionEvent e) {
int[] selectedRows = creationTable.getSelectedRows();
for (int row = 0; row < selectedRows.length; row++) {
selectedRows[row] = creationTable.convertRowIndexToModel(row);
}
delAction.setSelectedRows(selectedRows);
updAction.setSelectedRows(selectedRows);
}
}); //int selectedRow = creationTable.convertRowIndexToModel(creationTable.getSelectedRow());
//==============================================================================
// ACTIONS
//==============================================================================
loadAction = new LoadAction(tableModel);
saveAction = new SaveAction(tableModel);
addAction = new AddAction(tableModel);
delAction = new DelAction(tableModel);
delAction.setEnabled(false);
updAction = new UpdateAction(tableModel);
updAction.setEnabled(false);
//==============================================================================
//Setting action
//==============================================================================
bLoad.setAction(loadAction);
loadMenuItem.setAction(loadAction);
loadMenuItem.setMnemonic(KeyEvent.VK_L);
loadMenuItem.setAccelerator(KeyStroke.getKeyStroke('L',InputEvent.CTRL_DOWN_MASK));
bSave.setAction(saveAction);
saveAsMenuItem.setAction(saveAction);
saveAsMenuItem.setMnemonic(KeyEvent.VK_S);
saveAsMenuItem.setAccelerator(KeyStroke.getKeyStroke('S',InputEvent.CTRL_DOWN_MASK));
bAdd.setAction(addAction);
bDel.setAction(delAction);
deleteMenuItem.setAction(delAction);
deleteMenuItem.setMnemonic(KeyEvent.VK_DELETE);
//deleteMenuItem.setAccelerator(KeyStroke.getKeyStroke('Supprimer',InputEvent.
bUp.setAction(updAction);
jPopupMenu1.add(delAction);
jPopupMenu1.add(updAction);
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jPopupMenu1 = new javax.swing.JPopupMenu();
jScrollPane1 = new javax.swing.JScrollPane();
creationTable = new javax.swing.JTable();
bAdd = new javax.swing.JButton();
bDel = new javax.swing.JButton();
bUp = new javax.swing.JButton();
bLoad = new javax.swing.JButton();
bSave = new javax.swing.JButton();
jMenuBar1 = new javax.swing.JMenuBar();
jMenu1 = new javax.swing.JMenu();
loadMenuItem = new javax.swing.JMenuItem();
saveAsMenuItem = new javax.swing.JMenuItem();
jSeparator1 = new javax.swing.JSeparator();
exitMenuItem = new javax.swing.JMenuItem();
jMenu2 = new javax.swing.JMenu();
deleteMenuItem = new javax.swing.JMenuItem();
jPopupMenu1.setName("jPopupMenu1"); // NOI18N
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setName("Form"); // NOI18N
jScrollPane1.setName("jScrollPane1"); // NOI18N
creationTable.setAutoCreateRowSorter(true);
creationTable.setModel(new javax.swing.table.DefaultTableModel(
new Object [][] {
{null, null, null, null},
{null, null, null, null},
{null, null, null, null},
{null, null, null, null}
},
new String [] {
"Title 1", "Title 2", "Title 3", "Title 4"
}
));
creationTable.setName("creationTable"); // NOI18N
jScrollPane1.setViewportView(creationTable);
org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(crudapplication.CrudApplication.class).getContext().getResourceMap(CrudFrame.class);
creationTable.getColumnModel().getColumn(0).setHeaderValue(resourceMap.getString("creationTable.columnModel.title0")); // NOI18N
creationTable.getColumnModel().getColumn(1).setHeaderValue(resourceMap.getString("creationTable.columnModel.title1")); // NOI18N
creationTable.getColumnModel().getColumn(2).setHeaderValue(resourceMap.getString("creationTable.columnModel.title2")); // NOI18N
creationTable.getColumnModel().getColumn(3).setHeaderValue(resourceMap.getString("creationTable.columnModel.title3")); // NOI18N
bAdd.setText(resourceMap.getString("bAdd.text")); // NOI18N
bAdd.setName("bAdd"); // NOI18N
bDel.setText(resourceMap.getString("bDel.text")); // NOI18N
bDel.setEnabled(false);
bDel.setName("bDel"); // NOI18N
bUp.setText(resourceMap.getString("bUp.text")); // NOI18N
bUp.setEnabled(false);
bUp.setName("bUp"); // NOI18N
bLoad.setText(resourceMap.getString("bLoad.text")); // NOI18N
bLoad.setName("bLoad"); // NOI18N
bSave.setText(resourceMap.getString("bSave.text")); // NOI18N
bSave.setName("bSave"); // NOI18N
jMenuBar1.setName("jMenuBar1"); // NOI18N
jMenu1.setText(resourceMap.getString("jMenu1.text")); // NOI18N
jMenu1.setName("jMenu1"); // NOI18N
loadMenuItem.setText(resourceMap.getString("loadMenuItem.text")); // NOI18N
loadMenuItem.setName("loadMenuItem"); // NOI18N
jMenu1.add(loadMenuItem);
saveAsMenuItem.setText(resourceMap.getString("saveAsMenuItem.text")); // NOI18N
saveAsMenuItem.setName("saveAsMenuItem"); // NOI18N
jMenu1.add(saveAsMenuItem);
jSeparator1.setName("jSeparator1"); // NOI18N
jMenu1.add(jSeparator1);
exitMenuItem.setText(resourceMap.getString("exitMenuItem.text")); // NOI18N
exitMenuItem.setName("exitMenuItem"); // NOI18N
jMenu1.add(exitMenuItem);
jMenuBar1.add(jMenu1);
jMenu2.setText(resourceMap.getString("jMenu2.text")); // NOI18N
jMenu2.setName("jMenu2"); // NOI18N
deleteMenuItem.setText(resourceMap.getString("deleteMenuItem.text")); // NOI18N
deleteMenuItem.setName("deleteMenuItem"); // NOI18N
jMenu2.add(deleteMenuItem);
jMenuBar1.add(jMenu2);
setJMenuBar(jMenuBar1);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(bAdd)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(bDel)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(bUp))
.addGroup(layout.createSequentialGroup()
.addComponent(bLoad)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(bSave))
.addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 420, Short.MAX_VALUE))
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(bLoad)
.addComponent(bSave))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 317, Short.MAX_VALUE)
.addGap(16, 16, 16)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(bAdd)
.addComponent(bDel)
.addComponent(bUp))
.addContainerGap())
);
pack();
}// </editor-fold>
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new CrudFrame().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JButton bAdd;
private javax.swing.JButton bDel;
private javax.swing.JButton bLoad;
private javax.swing.JButton bSave;
private javax.swing.JButton bUp;
private javax.swing.JTable creationTable;
private javax.swing.JMenuItem deleteMenuItem;
private javax.swing.JMenuItem exitMenuItem;
private javax.swing.JMenu jMenu1;
private javax.swing.JMenu jMenu2;
private javax.swing.JMenuBar jMenuBar1;
private javax.swing.JPopupMenu jPopupMenu1;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JSeparator jSeparator1;
private javax.swing.JMenuItem loadMenuItem;
private javax.swing.JMenuItem saveAsMenuItem;
// End of variables declaration
}
======================================================================
======================================================================
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package crudapplication;
import java.util.ArrayList;
import java.util.List;
import javax.swing.table.AbstractTableModel;
/**
*
* @author Administrateur
*/
public class PersonsModel extends AbstractTableModel {
private static String[] columns = {"FirstName", "LastName"};
private List<Person> persons = new ArrayList<Person>();
public PersonsModel() {
/* Person person = new Person();
person.setFirstName("Rachid");
person.setLastName("FLICI");
persons.add(person);
Person person2 = new Person();
person2.setFirstName("Jean");
person2.setLastName("AUDIBERT");
persons.add(person2);
Person person3 = new Person();
person3.setFirstName("Saïd");
person3.setLastName("LAYADI");
persons.add(person3);*/
}
public void addPerson(Person person) {
persons.add(person);
int rowIndex = persons.indexOf(person);
this.fireTableRowsInserted(rowIndex, rowIndex);
}
public Person getPerson(int indexRowSelected) {
return persons.get(indexRowSelected);
}
public List<Person> getAll() {
return this.persons;
}
public void removePerson(int indexRowSelected) {
persons.remove(indexRowSelected);
this.fireTableRowsDeleted(indexRowSelected, indexRowSelected);
}
public void refreshPerson(Person person) {
int rowIndex = persons.indexOf(person);
fireTableRowsUpdated(rowIndex, rowIndex);
}
@Override
public String getColumnName(int column) {
try {
return columns[column];
} catch (ArrayIndexOutOfBoundsException e) {
return "N/A";
}
}
public int getRowCount() {
// throw new UnsupportedOperationException("Not supported yet.");
return persons.size();
}
public int getColumnCount() {
// throw new UnsupportedOperationException("Not supported yet.");
return 2;
}
public Object getValueAt(int rowIndex, int columnIndex) {
//throw new UnsupportedOperationException("Not supported yet.");
Object valeur;
Person person = persons.get(rowIndex);
switch (columnIndex) {
case 0:
valeur = person.getFirstName();
break;
case 1:
valeur = person.getLastName();
break;
default:
valeur = null;
}
return valeur;
}
@Override
public boolean isCellEditable(int rowIndex, int columnIndex) {
return true;
}
@Override
public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
Person person = this.persons.get(rowIndex);
switch (columnIndex) {
case 0:
person.setFirstName(aValue.toString());
break;
case 1:
person.setLastName(aValue.toString());
break;
}
}
public void removePerson(int[] selectedRows) {
List<Person> toDelete = new ArrayList<Person>(selectedRows.length);
for (int i = 0; i < selectedRows.length; i++) {
toDelete.add(persons.get(i));
}
for (Person person : toDelete) {
int index = persons.indexOf(person);
persons.remove(person);
this.fireTableRowsDeleted(index, index);
}
}
}
======================================================================
======================================================================
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package crudapplication.actions;
import crudapplication.AddFrame;
import crudapplication.Person;
import crudapplication.PersonsModel;
import java.awt.event.ActionEvent;
import javax.swing.AbstractAction;
/**
*
* @author FRWD9529
*/
public class UpdateAction extends AbstractAction {
private PersonsModel tableModel = null;
int selectedRow = -1;
public UpdateAction(PersonsModel tableModel) {
super("Update");
this.tableModel = tableModel;
}
public void setSelectedRows(int[] selectedRows) {
setEnabled(selectedRows.length == 1);
if (selectedRows.length == 1) {
this.selectedRow = selectedRows[0];
} else {
this.selectedRow = -1;
}
}
public void actionPerformed(ActionEvent e) {
if (this.selectedRow == -1) return;
Person person = tableModel.getPerson(selectedRow);
AddFrame updatePerson = new AddFrame(null, AddFrame.MODE_UPDATE, person);
}
}
============================================================================================================================================
sandul
Messages postés
3927
Date d'inscription
jeudi 22 mai 2008
Statut
Membre
Dernière intervention
8 octobre 2010
723
19 nov. 2009 à 12:13
19 nov. 2009 à 12:13
Et la classe Person ?
femeril1805
Messages postés
29
Date d'inscription
jeudi 19 novembre 2009
Statut
Membre
Dernière intervention
20 janvier 2011
19 nov. 2009 à 12:14
19 nov. 2009 à 12:14
new AddFrame(null, AddFrame.MODE_UPDATE, person);
T'avais raison j'ai mis null...trop nul
j'ai modifié un grand merci SANDUL
T'avais raison j'ai mis null...trop nul
j'ai modifié un grand merci SANDUL
sandul
Messages postés
3927
Date d'inscription
jeudi 22 mai 2008
Statut
Membre
Dernière intervention
8 octobre 2010
723
19 nov. 2009 à 12:14
19 nov. 2009 à 12:14
De rien =)
femeril1805
Messages postés
29
Date d'inscription
jeudi 19 novembre 2009
Statut
Membre
Dernière intervention
20 janvier 2011
19 nov. 2009 à 12:41
19 nov. 2009 à 12:41
J'ai oublié de t'indiquer ma méthode removePerson()
public void removePerson(int[] selectedRows) {
List<Person> toDelete = new ArrayList<Person>(selectedRows.length);
for (int i = 0; i < selectedRows.length; i++) {
toDelete.add(persons.get(i));
}
for (Person person : toDelete) {
int index = persons.indexOf(person);
persons.remove(person);
this.fireTableRowsDeleted(index, index);
}
public void removePerson(int[] selectedRows) {
List<Person> toDelete = new ArrayList<Person>(selectedRows.length);
for (int i = 0; i < selectedRows.length; i++) {
toDelete.add(persons.get(i));
}
for (Person person : toDelete) {
int index = persons.indexOf(person);
persons.remove(person);
this.fireTableRowsDeleted(index, index);
}
femeril1805
Messages postés
29
Date d'inscription
jeudi 19 novembre 2009
Statut
Membre
Dernière intervention
20 janvier 2011
19 nov. 2009 à 12:38
19 nov. 2009 à 12:38
Autre petit (grand?) pb, brievement mon appli s'ouvre avec une fenetre et de là g un bouton load qui charge un fichier texte (nom et prenom) et le met dans ma table ( 2 colonnes et ligne dynamiques...)
quand je clik et veux supprimer la ligne 3 par exemple il me supprime la ligne a l'indice 0 (ma 1ere ligne)
pourtant je pensais qu'en faisant " selectedRows[row] = creationTable.convertRowIndexToModel(row) " cela corrigerait mon pb...
encore une fois je fais appel à ta lumière SANDUL
========================================================================
public void valueChanged(ListSelectionEvent e) {
int[] selectedRows = creationTable.getSelectedRows();
for (int row = 0; row < selectedRows.length; row++) {
selectedRows[row] = creationTable.convertRowIndexToModel(row);<<<<<<<<<<<<<<
}
delAction.setSelectedRows(selectedRows);
updAction.setSelectedRows(selectedRows);
}
});
========================================================================
public class DelAction extends AbstractAction {
private int[] selectedRows = new int[0];
private PersonsModel model = null;
public DelAction(PersonsModel model) {
super("Delete…");
this.model = model;
}
public void setSelectedRows(int[] selectedRows) {
this.selectedRows = selectedRows;
setEnabled((this.selectedRows.length > 0));
}
public void actionPerformed(ActionEvent e) {
int result = JOptionPane.showConfirmDialog(null, "Voulez-vous vraiment confirmer votre choix ?",
"Confirmation de la suppression", JOptionPane.YES_NO_OPTION);
switch (result) {
case JOptionPane.YES_OPTION:
model.removePerson(selectedRows);
break;
case JOptionPane.NO_OPTION:
break;
}
}
}
quand je clik et veux supprimer la ligne 3 par exemple il me supprime la ligne a l'indice 0 (ma 1ere ligne)
pourtant je pensais qu'en faisant " selectedRows[row] = creationTable.convertRowIndexToModel(row) " cela corrigerait mon pb...
encore une fois je fais appel à ta lumière SANDUL
========================================================================
public void valueChanged(ListSelectionEvent e) {
int[] selectedRows = creationTable.getSelectedRows();
for (int row = 0; row < selectedRows.length; row++) {
selectedRows[row] = creationTable.convertRowIndexToModel(row);<<<<<<<<<<<<<<
}
delAction.setSelectedRows(selectedRows);
updAction.setSelectedRows(selectedRows);
}
});
========================================================================
public class DelAction extends AbstractAction {
private int[] selectedRows = new int[0];
private PersonsModel model = null;
public DelAction(PersonsModel model) {
super("Delete…");
this.model = model;
}
public void setSelectedRows(int[] selectedRows) {
this.selectedRows = selectedRows;
setEnabled((this.selectedRows.length > 0));
}
public void actionPerformed(ActionEvent e) {
int result = JOptionPane.showConfirmDialog(null, "Voulez-vous vraiment confirmer votre choix ?",
"Confirmation de la suppression", JOptionPane.YES_NO_OPTION);
switch (result) {
case JOptionPane.YES_OPTION:
model.removePerson(selectedRows);
break;
case JOptionPane.NO_OPTION:
break;
}
}
}
femeril1805
Messages postés
29
Date d'inscription
jeudi 19 novembre 2009
Statut
Membre
Dernière intervention
20 janvier 2011
19 nov. 2009 à 13:00
19 nov. 2009 à 13:00
Personne n'a une ptite idée ?
femeril1805
Messages postés
29
Date d'inscription
jeudi 19 novembre 2009
Statut
Membre
Dernière intervention
20 janvier 2011
19 nov. 2009 à 13:41
19 nov. 2009 à 13:41
allo...y a quelqu'un ??
19 nov. 2009 à 11:53