Então galera !!! meu sistema tem umas 3 jtext fild e um j boton…
a intenção era Editar alguns dos valores no formulário e apagar o formulário e gerar um novo grupo de identificação que é atribuído sempre que clicar no JButton.
só que ele ta dando essa exception eu tive alguns problemas com essa parte do ID e num tava funfando mtu bem…
sera que tem a ve ???
pq esta dando essa exception ???
vlw galera espero ter sido claro abraço a todos…
segue o meu codigo:
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/*
* TaskEditorPanel.java
*
* Created on Oct 25, 2010, 11:13:51 AM
*/
package com.netbeansrcp.taskeditor;
import com.netbeansrcp.taskmodel.TaskImpl;
import com.netbeansrcp.taskmodel.newpackage.API.Task;
import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import java.text.DateFormat;
import java.text.ParseException;
import java.util.Date;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
/**
*
* @author jcsouza
*/
public class TaskEditorPanel extends javax.swing.JPanel {
public static final String PROP_TASK = "TASK";
private PropertyChangeSupport pcs;
private Task task = new TaskImpl();
private boolean noUpdate = false;
private DocumentListener docListener = new DocumentListener() {
@Override
public void insertUpdate(DocumentEvent evt) {
TaskEditorPanel.this.updateTask();
}
@Override
public void removeUpdate(DocumentEvent evt) {
TaskEditorPanel.this.updateTask();
}
@Override
public void changedUpdate(DocumentEvent evt) {
TaskEditorPanel.this.updateTask();
}
};
@Override
public synchronized void addPropertyChangeListener(PropertyChangeListener listener) {
if (pcs == null) {
pcs = new PropertyChangeSupport(this);
}
this.pcs.addPropertyChangeListener(listener);
}
@Override
public synchronized void removePropertyChangeListener(PropertyChangeListener listener) {
if (pcs != null) {
this.pcs.removePropertyChangeListener(listener);
}
}
/** Creates new form TaskEditorPanel */
public TaskEditorPanel() {
initComponents();
this.updateForm();
}
private void updateTask() {
if (this.noUpdate) {
return;
}
this.task.setName(this.jTextField3.getText());
Date due = null;
try {
due =
DateFormat.getDateInstance().parse(this.jTextField4.getText());
} catch (ParseException exception) {
due = new Date();
}
this.task.setDue(due);
if (!this.jSlider1.getValueIsAdjusting()) {
switch (this.jSlider1.getValue()) {
case 0:
this.task.setPrio(Task.Priority.LOW);
break;
case 1:
this.task.setPrio(Task.Priority.MEDIUM);
break;
case 2:
this.task.setPrio(Task.Priority.HIGH);
}
}
this.task.setProgr(this.jSlider2.getValue());
this.task.setDescr(this.jTextArea1.getText());
}
private void updateForm() {
this.noUpdate = true;
this.noUpdate = false;
this.jTextField1.setText(this.task.getId());
this.jTextField2.setText(this.task.getParentId());
this.jTextField3.setText(this.task.getName());
this.jTextField4.setText(DateFormat.getDateInstance().format(this.task.getDue()));
this.jTextArea1.setText(this.task.getDescr());
if (Task.Priority.LOW.equals(this.task.getPrio())) {
this.jSlider1.setValue(0);
} else if (Task.Priority.MEDIUM.equals(this.task.getPrio())) {
this.jSlider1.setValue(1);
} else {
this.jSlider1.setValue(2);
}
this.jSlider2.setValue(this.task.getProgr());
}
/** 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() {
jSlider1 = new javax.swing.JSlider();
jSlider2 = new javax.swing.JSlider();
jTextField1 = new javax.swing.JTextField();
jTextField2 = new javax.swing.JTextField();
jTextField3 = new javax.swing.JTextField();
jTextField4 = new javax.swing.JTextField();
jScrollPane1 = new javax.swing.JScrollPane();
jTextArea1 = new javax.swing.JTextArea();
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
jLabel4 = new javax.swing.JLabel();
jLabel5 = new javax.swing.JLabel();
jLabel6 = new javax.swing.JLabel();
jLabel7 = new javax.swing.JLabel();
jButton1 = new javax.swing.JButton();
jSlider1.setMajorTickSpacing(1);
jSlider1.setMaximum(2);
jSlider1.setMinorTickSpacing(1);
jSlider1.setPaintTicks(true);
jSlider1.setSnapToTicks(true);
jSlider1.setValue(0);
jSlider1.addChangeListener(new javax.swing.event.ChangeListener() {
public void stateChanged(javax.swing.event.ChangeEvent evt) {
jSlider1StateChanged(evt);
}
});
jSlider2.setMajorTickSpacing(25);
jSlider2.setMinorTickSpacing(5);
jSlider2.setPaintLabels(true);
jSlider2.setPaintTicks(true);
jSlider2.setSnapToTicks(true);
jSlider2.setValue(0);
jSlider2.addChangeListener(new javax.swing.event.ChangeListener() {
public void stateChanged(javax.swing.event.ChangeEvent evt) {
jSlider2StateChanged(evt);
}
});
jTextField1.setText(org.openide.util.NbBundle.getMessage(TaskEditorPanel.class, "TaskEditorPanel.jTextField1.text")); // NOI18N
this.jTextField1.getDocument().addDocumentListener(this.docListener);
jTextField2.setText(org.openide.util.NbBundle.getMessage(TaskEditorPanel.class, "TaskEditorPanel.jTextField2.text")); // NOI18N
this.jTextField2.getDocument().addDocumentListener(this.docListener);
jTextField3.setText(org.openide.util.NbBundle.getMessage(TaskEditorPanel.class, "TaskEditorPanel.jTextField3.text")); // NOI18N
jTextField3.setEnabled(false);
this.jTextField3.getDocument().addDocumentListener(this.docListener);
jTextField4.setText(org.openide.util.NbBundle.getMessage(TaskEditorPanel.class, "TaskEditorPanel.jTextField4.text")); // NOI18N
jTextField4.setEnabled(false);
this.jTextField4.getDocument().addDocumentListener(this.docListener);
jTextArea1.setColumns(20);
jTextArea1.setRows(5);
jScrollPane1.setViewportView(jTextArea1);
jLabel1.setText(org.openide.util.NbBundle.getMessage(TaskEditorPanel.class, "TaskEditorPanel.jLabel1.text")); // NOI18N
jLabel2.setText(org.openide.util.NbBundle.getMessage(TaskEditorPanel.class, "TaskEditorPanel.jLabel2.text")); // NOI18N
jLabel3.setText(org.openide.util.NbBundle.getMessage(TaskEditorPanel.class, "TaskEditorPanel.jLabel3.text")); // NOI18N
jLabel4.setText(org.openide.util.NbBundle.getMessage(TaskEditorPanel.class, "TaskEditorPanel.jLabel4.text")); // NOI18N
jLabel5.setText(org.openide.util.NbBundle.getMessage(TaskEditorPanel.class, "TaskEditorPanel.jLabel5.text")); // NOI18N
jLabel6.setText(org.openide.util.NbBundle.getMessage(TaskEditorPanel.class, "TaskEditorPanel.jLabel6.text")); // NOI18N
jLabel7.setText(org.openide.util.NbBundle.getMessage(TaskEditorPanel.class, "TaskEditorPanel.jLabel7.text")); // NOI18N
jButton1.setText(org.openide.util.NbBundle.getMessage(TaskEditorPanel.class, "TaskEditorPanel.jButton1.text")); // NOI18N
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
this.setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addGap(57, 57, 57)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(jLabel1)
.addComponent(jLabel2)
.addComponent(jLabel3)
.addComponent(jLabel4)
.addComponent(jLabel5)
.addComponent(jLabel6)
.addComponent(jLabel7))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 295, Short.MAX_VALUE)
.addContainerGap())
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(jSlider2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 282, Short.MAX_VALUE)
.addComponent(jSlider1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 282, Short.MAX_VALUE)
.addComponent(jTextField4, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 282, Short.MAX_VALUE)
.addComponent(jTextField3, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 282, Short.MAX_VALUE)
.addComponent(jTextField2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 282, Short.MAX_VALUE)
.addComponent(jTextField1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 282, Short.MAX_VALUE))
.addGap(23, 23, 23))))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap(280, Short.MAX_VALUE)
.addComponent(jButton1)
.addGap(32, 32, 32))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(6, 6, 6)
.addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addComponent(jTextField4, 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.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(6, 6, 6)
.addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addComponent(jTextField3, 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.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(6, 6, 6)
.addComponent(jLabel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(6, 6, 6)
.addComponent(jLabel4, javax.swing.GroupLayout.DEFAULT_SIZE, 15, Short.MAX_VALUE))
.addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jSlider1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel5, javax.swing.GroupLayout.DEFAULT_SIZE, 36, Short.MAX_VALUE)
.addGap(11, 11, 11)))
.addGap(13, 13, 13)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jSlider2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel6, javax.swing.GroupLayout.DEFAULT_SIZE, 36, Short.MAX_VALUE)
.addGap(11, 11, 11)))
.addGap(3, 3, 3)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel7, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGap(54, 54, 54))
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 68, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addComponent(jButton1)
.addGap(11, 11, 11))
);
}// </editor-fold>
private void jSlider1StateChanged(javax.swing.event.ChangeEvent evt) {
this.updateTask();
}
private void jSlider2StateChanged(javax.swing.event.ChangeEvent evt) {
this.updateTask();
}
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
Task oldTask = this.task;
this.task = new TaskImpl();
this.pcs.firePropertyChange(PROP_TASK, oldTask, this.task);
this.updateForm();
}
// Variables declaration - do not modify
private javax.swing.JButton jButton1;
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.JScrollPane jScrollPane1;
private javax.swing.JSlider jSlider1;
private javax.swing.JSlider jSlider2;
private javax.swing.JTextArea jTextArea1;
private javax.swing.JTextField jTextField1;
private javax.swing.JTextField jTextField2;
private javax.swing.JTextField jTextField3;
private javax.swing.JTextField jTextField4;
// End of variables declaration
}