我不知道这里有什么问题。有什么建议吗?
我是一个小组的学生。这个问题似乎只会影响我。
谢谢你, Ramon的。
/ ** *从构造函数中调用此方法以初始化表单。 *警告:请勿修改此代码。这种方法的内容总是如此 *由表单编辑器重新生成。 * /
public class ManteSocis extends JPanel {
private static final String FALTEN_DADES = "Hi falta el nom i/o el primer cognom";
private static final String ID_NEGATIU = "L'identificador ha de ser mes gran que zero";
private static final String FORMAT_ERRONI = "Format erroni";
private static final String AFICIO_EXISTENT = "L'aficio ja afegida";
private final GestorPersistencia db;
private final FormListener formListener1 = new FormListener();
private DefaultListModel <String> modelLlista;
private JTextField calNetejar[];
public ManteSocis(GestorPersistencia db) {
this.db=db;
initComponents();
calNetejar=new JTextField[]{idTextField,nomTextField,primerCognomTextField,segonCognomTextField,aficioTextField};
}
/**
* 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() {
bindingGroup = new org.jdesktop.beansbinding.BindingGroup();
try{
list = java.beans.Beans.isDesignTime() ? java.util.Collections.emptyList() : org.jdesktop.observablecollections.ObservableCollections.observableList(Collections.checkedList(db.obtenirSocisOrdenatsPerId(),model.Soci.class));
try{
listAficions = java.beans.Beans.isDesignTime() ? java.util.Collections.emptyList() : org.jdesktop.observablecollections.ObservableCollections.observableList(Collections.checkedList(db.obtenirSocisOrdenatsPerId(),model.Soci.class));
masterScrollPane = new javax.swing.JScrollPane();
masterTable = new javax.swing.JTable();
deleteButton = new javax.swing.JButton();
detailScrollPane = new javax.swing.JScrollPane();
detailTable = new javax.swing.JTable();
saveButton = new javax.swing.JButton();
refreshButton = new javax.swing.JButton();
jLabel1 = new javax.swing.JLabel();
jPanel1 = new javax.swing.JPanel();
aficioTextField = new javax.swing.JTextField();
jLabel2 = new javax.swing.JLabel();
newButton = new javax.swing.JButton();
suprimeixButton = new javax.swing.JButton();
afegeixButton = new javax.swing.JButton();
jLabel3 = new javax.swing.JLabel();
idTextField = new javax.swing.JTextField();
nomTextField = new javax.swing.JTextField();
primerCognomTextField = new javax.swing.JTextField();
segonCognomTextField = new javax.swing.JTextField();
jLabel4 = new javax.swing.JLabel();
jLabel5 = new javax.swing.JLabel();
jLabel6 = new javax.swing.JLabel();
jLabel7 = new javax.swing.JLabel();
jScrollPane1 = new javax.swing.JScrollPane();
aficionsList = new javax.swing.JList<String>();
jLabel8 = new javax.swing.JLabel();
FormListener formListener1 = new FormListener();
}catch(UtilitatPersistenciaException e){
Util.tractaExcepcio(this,e);
}
}catch(UtilitatPersistenciaException e){
Util.tractaExcepcio(this,e);
}
masterTable.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
org.jdesktop.swingbinding.JTableBinding jTableBinding = org.jdesktop.swingbinding.SwingBindings.createJTableBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, list, masterTable);
org.jdesktop.swingbinding.JTableBinding.ColumnBinding columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${id}"));
columnBinding.setColumnName("Id");
columnBinding.setColumnClass(Integer.class);
columnBinding.setEditable(false);
columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${nom}"));
columnBinding.setColumnName("Nom");
columnBinding.setColumnClass(String.class);
columnBinding.setEditable(false);
columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${cognom1}"));
columnBinding.setColumnName("Cognom1");
columnBinding.setColumnClass(String.class);
columnBinding.setEditable(false);
columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${cognom2}"));
columnBinding.setColumnName("Cognom2");
columnBinding.setColumnClass(String.class);
columnBinding.setEditable(false);
bindingGroup.addBinding(jTableBinding);
jTableBinding.bind();
masterScrollPane.setViewportView(masterTable);
deleteButton.setText("Esborra soci");
org.jdesktop.beansbinding.Binding binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, masterTable, org.jdesktop.beansbinding.ELProperty.create("${selectedElement != null}"), deleteButton, org.jdesktop.beansbinding.BeanProperty.create("enabled"));
bindingGroup.addBinding(binding);
deleteButton.addActionListener(formListener1);
org.jdesktop.beansbinding.ELProperty eLProperty = org.jdesktop.beansbinding.ELProperty.create("${selectedElement.aficions}");
jTableBinding = org.jdesktop.swingbinding.SwingBindings.createJTableBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, masterTable, eLProperty, detailTable);
columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ObjectProperty.create());
columnBinding.setColumnName("Aficio");
columnBinding.setEditable(false);
jTableBinding.setSourceUnreadableValue(java.util.Collections.emptyList());
bindingGroup.addBinding(jTableBinding);
jTableBinding.bind();
detailScrollPane.setViewportView(detailTable);
saveButton.setText("Grava");
saveButton.addActionListener(formListener1);
refreshButton.setText("Refresca");
refreshButton.addActionListener(formListener1);
jLabel1.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
jLabel1.setText("Manteniment socis");
jLabel1.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
jPanel1.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
jLabel2.setText("Aficio:");
newButton.setText("Nou soci");
newButton.addActionListener(formListener1);
suprimeixButton.setText("-");
suprimeixButton.setToolTipText("Esborra l'aficio seleccionada");
binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, aficionsList, org.jdesktop.beansbinding.ELProperty.create("${selectedElement!=null}"), suprimeixButton, org.jdesktop.beansbinding.BeanProperty.create("enabled"));
bindingGroup.addBinding(binding);
suprimeixButton.addActionListener(formListener1);
afegeixButton.setText("+");
afegeixButton.setToolTipText("Afegeixi l'aficio del quadre de text");
afegeixButton.addActionListener(formListener1);
jLabel3.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
jLabel3.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
jLabel3.setText("Alta de socis");
jLabel3.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
jLabel4.setText("Id:");
jLabel5.setText("Nom:");
jLabel6.setText("Primer cognom:");
jLabel7.setText("Segon cognom:");
aficionsList.setModel(modelLlista=new DefaultListModel<String>());
jScrollPane1.setViewportView(aficionsList);
jLabel8.setText("Aficions");
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(49, 49, 49)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(jLabel4)
.addComponent(jLabel5)))
.addComponent(jLabel6, javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(jLabel7, javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(jLabel2, javax.swing.GroupLayout.Alignment.TRAILING))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(idTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 38, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(nomTextField)
.addComponent(primerCognomTextField)
.addComponent(segonCognomTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 136, Short.MAX_VALUE)
.addComponent(aficioTextField))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(afegeixButton)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(suprimeixButton, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 231, Short.MAX_VALUE))
.addComponent(jLabel8, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(newButton))
.addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 636, javax.swing.GroupLayout.PREFERRED_SIZE))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addComponent(jLabel3)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 17, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(idTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel4))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(nomTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel5))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(primerCognomTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel6))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(segonCognomTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel7))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(aficioTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel2)
.addComponent(afegeixButton)
.addComponent(suprimeixButton))
.addGap(0, 8, Short.MAX_VALUE))
.addGroup(jPanel1Layout.createSequentialGroup()
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jLabel8)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE))
.addGroup(jPanel1Layout.createSequentialGroup()
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(newButton)))
.addContainerGap())
);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
this.setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(layout.createSequentialGroup()
.addComponent(masterScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, 430, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(deleteButton)
.addGap(0, 0, Short.MAX_VALUE))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(detailScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, 231, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap())))
.addGroup(layout.createSequentialGroup()
.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(0, 0, Short.MAX_VALUE))))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(refreshButton)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(saveButton)
.addGap(9, 9, 9))
);
layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {refreshButton, saveButton});
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(masterScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, 133, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(layout.createSequentialGroup()
.addComponent(detailScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, 112, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(deleteButton)))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(refreshButton)
.addComponent(saveButton))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
bindingGroup.bind();
}
// Code for dispatching events from components to event handlers.
private class FormListener implements java.awt.event.ActionListener {
FormListener() {}
public void actionPerformed(java.awt.event.ActionEvent evt) {
if (evt.getSource() == deleteButton) {
ManteSocis.this.deleteButtonActionPerformed(evt);
}
else if (evt.getSource() == saveButton) {
ManteSocis.this.saveButtonActionPerformed(evt);
}
else if (evt.getSource() == refreshButton) {
ManteSocis.this.refreshButtonActionPerformed(evt);
}
else if (evt.getSource() == newButton) {
ManteSocis.this.newButtonActionPerformed(evt);
}
else if (evt.getSource() == suprimeixButton) {
ManteSocis.this.suprimeixButtonActionPerformed(evt);
}
else if (evt.getSource() == afegeixButton) {
ManteSocis.this.afegeixButtonActionPerformed(evt);
}
}
}// </editor-fold>
@SuppressWarnings("unchecked")
private void refreshButtonActionPerformed(java.awt.event.ActionEvent evt) {
try {
db.anullaCanvis();
list.clear();
list.addAll(db.obtenirSocisOrdenatsPerId());
} catch (UtilitatPersistenciaException ex) {
Util.tractaExcepcio(this, ex);
}
}
private void deleteButtonActionPerformed(java.awt.event.ActionEvent evt) {
int sel=masterTable.getSelectedRow();
if(sel!=-1){
try {
db.eliminar((model.Soci)list.get(sel));
list.remove(sel);
} catch (UtilitatPersistenciaException ex) {
Util.tractaExcepcio(this, ex);
}
}
else{
Util.avisa(this, Util.CAP_FILA_SEL);
}
}
private void newButtonActionPerformed(java.awt.event.ActionEvent evt) {
int id;
String nom, primerCognom, segonCognom;
try{
id = new Integer(idTextField.getText());
if(id<0){
Util.avisa(this,ID_NEGATIU);
}else{
nom=nomTextField.getText().trim();
primerCognom=primerCognomTextField.getText().trim();
segonCognom=segonCognomTextField.getText().trim();
if(nom.isEmpty()||primerCognom.isEmpty()){
Util.avisa(this,FALTEN_DADES);
}
else {
try{
List<String> aficions;
Soci s=db.nouSociTemporal(id);
s.setNom(nom);
s.setCognom1(primerCognom);
s.setCognom2(segonCognom);
aficions=s.getAficions();
for(Object cadena:modelLlista.toArray()){ // afegim les aficions
aficions.add(""+cadena);
}
db.inserir(s);
list.add(s);
netejaCamps();
modelLlista.removeAllElements();
// situar el cursor de la taula sobre l'element afegit
int x =list.size()-1;
masterTable.setRowSelectionInterval(x, x);
masterTable.scrollRectToVisible(masterTable.getCellRect(x, 0, true));
}catch(UtilitatPersistenciaException e){
Util.avisa(this, e.getMessage());
}
}
}
}catch(NumberFormatException e){
Util.avisa(this,FORMAT_ERRONI);
}
}
private void saveButtonActionPerformed(java.awt.event.ActionEvent evt) {
try {
db.gravaCanvis();
} catch (UtilitatPersistenciaException ex) {
try {
Util.tractaExcepcio(this, ex);
db.anullaCanvis();
} catch (UtilitatPersistenciaException e) {
Util.tractaExcepcio(this, e);
}
}
}
private void afegeixButtonActionPerformed(java.awt.event.ActionEvent evt) {
String aux = aficioTextField.getText().trim();
if(modelLlista.contains(aux)){
Util.avisa(this,AFICIO_EXISTENT);
}else{
modelLlista.addElement(aux);
}
}
private void suprimeixButtonActionPerformed(java.awt.event.ActionEvent evt) {
String aux = (String)aficionsList.getSelectedValue();
if(aux==null){
Util.avisa(this,Util.CAP_FILA_SEL);
}
else{
modelLlista.removeElement(aux);
}
}
private void netejaCamps(){
for(JTextField t:calNetejar){
t.setText("");
}
}
// Variables declaration - do not modify
private javax.swing.JButton afegeixButton;
private javax.swing.JTextField aficioTextField;
private javax.swing.JList<String> aficionsList;
private javax.swing.JButton deleteButton;
private javax.swing.JScrollPane detailScrollPane;
private javax.swing.JTable detailTable;
private javax.swing.JTextField idTextField;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JLabel jLabel5;
private javax.swing.JLabel jLabel6;
private javax.swing.JLabel jLabel7;
private javax.swing.JLabel jLabel8;
private javax.swing.JPanel jPanel1;
private javax.swing.JScrollPane jScrollPane1;
private java.util.List<model.Soci> list;
private java.util.List<model.Soci> listAficions;
private javax.swing.JScrollPane masterScrollPane;
private javax.swing.JTable masterTable;
private javax.swing.JButton newButton;
private javax.swing.JTextField nomTextField;
private javax.swing.JTextField primerCognomTextField;
private javax.swing.JButton refreshButton;
private javax.swing.JButton saveButton;
private javax.swing.JTextField segonCognomTextField;
private javax.swing.JButton suprimeixButton;
private org.jdesktop.beansbinding.BindingGroup bindingGroup;
// End of variables declaration
public static JInternalFrame perMDI(GestorPersistencia db){
JInternalFrame frame = new JInternalFrame();
frame.setContentPane(new ManteSocis(db));
frame.pack();
frame.setVisible(true);
return frame;
}
}
答案 0 :(得分:0)
新的NetBeans安装解决了这个问题。
谢谢,