Results 1 to 8 of 8
  1. #1
    putapepe is offline Member
    Join Date
    Apr 2014
    Posts
    7
    Rep Power
    0

    Default java.lang.String cannot be cast to java.lang.Boolean

    JAVA CODE:

    package gui.dialog;
    import cli.data001;
    import java.awt.Color;
    import java.awt.Component;
    import java.awt.Font;
    import java.awt.event.MouseEvent;
    import java.awt.event.MouseListener;
    import java.util.Vector;
    import javax.swing.JLabel;
    import javax.swing.JOptionPane;
    import javax.swing.JTable;
    import javax.swing.RowFilter;
    import javax.swing.table.DefaultTableCellRenderer;
    import javax.swing.table.DefaultTableModel;
    import javax.swing.table.JTableHeader;
    import javax.swing.table.TableCellRenderer;
    import javax.swing.table.TableColumn;
    import javax.swing.table.TableModel;
    import javax.swing.table.TableRowSorter;
    public class JDialogData001 extends javax.swing.JDialog implements MouseListener {
    private data001 data001 = new data001();

    /**
    * Creates new form JDialogData001
    */
    public JDialogData001(java.awt.Frame parent, boolean modal) {
    super(parent, modal);
    initComponents();
    autoDisableButton();
    setTable();
    select();
    }




    /**
    * 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() {

    jPanel2 = new javax.swing.JPanel();
    jPanel1 = new javax.swing.JPanel();
    jPanel9 = new javax.swing.JPanel();
    jPanel10 = new javax.swing.JPanel();
    jPanel11 = new javax.swing.JPanel();
    jPanel12 = new javax.swing.JPanel();
    jPanel15 = new javax.swing.JPanel();
    jLabel8 = new javax.swing.JLabel();
    jPanel26 = new javax.swing.JPanel();
    jButtonNew = new javax.swing.JButton();
    jButtonInsert = new javax.swing.JButton();
    jButtonUpdate = new javax.swing.JButton();
    jButtonDelete = new javax.swing.JButton();
    jTextFieldSearch = new javax.swing.JTextField();
    jPanel16 = new javax.swing.JPanel();
    jPanel20 = new javax.swing.JPanel();
    jPanel19 = new javax.swing.JPanel();
    jPanel21 = new javax.swing.JPanel();
    jLabel1 = new javax.swing.JLabel();
    jLabel2 = new javax.swing.JLabel();
    jPanel22 = new javax.swing.JPanel();
    jComboBoxGender = new javax.swing.JComboBox();
    jComboBoxCivilStatus = new javax.swing.JComboBox();
    jPanel23 = new javax.swing.JPanel();
    jPanel24 = new javax.swing.JPanel();
    jLabel5 = new javax.swing.JLabel();
    jLabel6 = new javax.swing.JLabel();
    jLabel7 = new javax.swing.JLabel();
    jLabel9 = new javax.swing.JLabel();
    jPanel25 = new javax.swing.JPanel();
    jTextFieldLastName = new javax.swing.JTextField();
    jTextFieldFirstName = new javax.swing.JTextField();
    jTextFieldMiddleName = new javax.swing.JTextField();
    jTextFieldSuffix = new javax.swing.JTextField();
    jPanel17 = new javax.swing.JPanel();
    jPanel18 = new javax.swing.JPanel();
    jPanel13 = new javax.swing.JPanel();
    jPanel14 = new javax.swing.JPanel();
    jPanel3 = new javax.swing.JPanel();
    jPanel4 = new javax.swing.JPanel();
    jPanel5 = new javax.swing.JPanel();
    jPanel6 = new javax.swing.JPanel();
    jScrollPane1 = new javax.swing.JScrollPane();
    jTableData001 = new javax.swing.JTable();
    jPanel7 = new javax.swing.JPanel();
    jPanel8 = new javax.swing.JPanel();

    setDefaultCloseOperation(javax.swing.WindowConstan ts.DISPOSE_ON_CLOSE);

    jPanel2.setPreferredSize(new java.awt.Dimension(1012, 400));
    jPanel2.setLayout(new java.awt.BorderLayout());

    jPanel1.setPreferredSize(new java.awt.Dimension(450, 0));
    jPanel1.setLayout(null);
    jPanel2.add(jPanel1, java.awt.BorderLayout.WEST);

    jPanel9.setPreferredSize(new java.awt.Dimension(800, 300));
    jPanel9.setLayout(new java.awt.BorderLayout());

    jPanel10.setPreferredSize(new java.awt.Dimension(658, 5));

    javax.swing.GroupLayout jPanel10Layout = new javax.swing.GroupLayout(jPanel10);
    jPanel10.setLayout(jPanel10Layout);
    jPanel10Layout.setHorizontalGroup(
    jPanel10Layout.createParallelGroup(javax.swing.Gro upLayout.Alignment.LEADING)
    .addGap(0, 768, Short.MAX_VALUE)
    );
    jPanel10Layout.setVerticalGroup(
    jPanel10Layout.createParallelGroup(javax.swing.Gro upLayout.Alignment.LEADING)
    .addGap(0, 5, Short.MAX_VALUE)
    );

    jPanel9.add(jPanel10, java.awt.BorderLayout.NORTH);

    jPanel11.setPreferredSize(new java.awt.Dimension(658, 5));

    javax.swing.GroupLayout jPanel11Layout = new javax.swing.GroupLayout(jPanel11);
    jPanel11.setLayout(jPanel11Layout);
    jPanel11Layout.setHorizontalGroup(
    jPanel11Layout.createParallelGroup(javax.swing.Gro upLayout.Alignment.LEADING)
    .addGap(0, 768, Short.MAX_VALUE)
    );
    jPanel11Layout.setVerticalGroup(
    jPanel11Layout.createParallelGroup(javax.swing.Gro upLayout.Alignment.LEADING)
    .addGap(0, 5, Short.MAX_VALUE)
    );

    jPanel9.add(jPanel11, java.awt.BorderLayout.SOUTH);

    jPanel12.setLayout(new java.awt.BorderLayout());

    jPanel15.setBorder(javax.swing.BorderFactory.creat eEtchedBorder());
    jPanel15.setLayout(null);

    jLabel8.setText("Search Field:");
    jPanel15.add(jLabel8);
    jLabel8.setBounds(400, 40, 70, 30);

    jPanel26.setLayout(new java.awt.GridLayout(2, 2, 2, 3));

    jButtonNew.setText("New");
    jButtonNew.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed(java.awt.event.ActionEvent evt) {
    jButtonNewActionPerformed(evt);
    }
    });
    jPanel26.add(jButtonNew);

    jButtonInsert.setText("Insert");
    jButtonInsert.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed(java.awt.event.ActionEvent evt) {
    jButtonInsertActionPerformed(evt);
    }
    });
    jPanel26.add(jButtonInsert);

    jButtonUpdate.setText("Update");
    jButtonUpdate.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed(java.awt.event.ActionEvent evt) {
    jButtonUpdateActionPerformed(evt);
    }
    });
    jPanel26.add(jButtonUpdate);

    jButtonDelete.setText("Delete");
    jButtonDelete.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed(java.awt.event.ActionEvent evt) {
    jButtonDeleteActionPerformed(evt);
    }
    });
    jPanel26.add(jButtonDelete);

    jPanel15.add(jPanel26);
    jPanel26.setBounds(40, 20, 310, 70);

    jTextFieldSearch.addKeyListener(new java.awt.event.KeyAdapter() {
    public void keyReleased(java.awt.event.KeyEvent evt) {
    jTextFieldSearchKeyReleased(evt);
    }
    });
    jPanel15.add(jTextFieldSearch);
    jTextFieldSearch.setBounds(490, 40, 230, 30);

    jPanel12.add(jPanel15, java.awt.BorderLayout.CENTER);

    jPanel16.setPreferredSize(new java.awt.Dimension(648, 280));
    jPanel16.setLayout(new java.awt.BorderLayout());

    jPanel20.setBorder(javax.swing.BorderFactory.creat eEtchedBorder());
    jPanel20.setLayout(null);

    jPanel19.setLayout(null);

    jPanel21.setLayout(new java.awt.GridLayout(4, 1));

    jLabel1.setText("Gender");
    jPanel21.add(jLabel1);

    jLabel2.setText("Civil Status");
    jPanel21.add(jLabel2);

    jPanel19.add(jPanel21);
    jPanel21.setBounds(10, 10, 130, 180);

    jPanel22.setLayout(new java.awt.GridLayout(4, 0, 0, 5));

    jComboBoxGender.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "none", "Male", "Female" }));
    jPanel22.add(jComboBoxGender);

    jComboBoxCivilStatus.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "none", "Single", "Married", "Separated" }));
    jPanel22.add(jComboBoxCivilStatus);

    jPanel19.add(jPanel22);
    jPanel22.setBounds(140, 10, 210, 190);

    jPanel20.add(jPanel19);
    jPanel19.setBounds(380, 10, 360, 140);

    jPanel23.setLayout(null);

    jPanel24.setLayout(new java.awt.GridLayout(4, 1, 0, 5));

    jLabel5.setText("Last Name");
    jPanel24.add(jLabel5);

    jLabel6.setText("First Name");
    jPanel24.add(jLabel6);

    jLabel7.setText("Middle Name");
    jPanel24.add(jLabel7);

    jLabel9.setText("Suffix");
    jPanel24.add(jLabel9);

    jPanel23.add(jPanel24);
    jPanel24.setBounds(10, 10, 130, 180);

    jPanel25.setLayout(new java.awt.GridLayout(4, 0, 0, 5));
    jPanel25.add(jTextFieldLastName);
    jPanel25.add(jTextFieldFirstName);
    jPanel25.add(jTextFieldMiddleName);
    jPanel25.add(jTextFieldSuffix);

    jPanel23.add(jPanel25);
    jPanel25.setBounds(140, 10, 210, 180);

    jPanel20.add(jPanel23);
    jPanel23.setBounds(20, 10, 360, 200);

    jPanel16.add(jPanel20, java.awt.BorderLayout.CENTER);

    jPanel17.setPreferredSize(new java.awt.Dimension(758, 30));

    javax.swing.GroupLayout jPanel17Layout = new javax.swing.GroupLayout(jPanel17);
    jPanel17.setLayout(jPanel17Layout);
    jPanel17Layout.setHorizontalGroup(
    jPanel17Layout.createParallelGroup(javax.swing.Gro upLayout.Alignment.LEADING)
    .addGap(0, 758, Short.MAX_VALUE)
    );
    jPanel17Layout.setVerticalGroup(
    jPanel17Layout.createParallelGroup(javax.swing.Gro upLayout.Alignment.LEADING)
    .addGap(0, 30, Short.MAX_VALUE)
    );

    jPanel16.add(jPanel17, java.awt.BorderLayout.NORTH);

    jPanel18.setPreferredSize(new java.awt.Dimension(758, 30));

    javax.swing.GroupLayout jPanel18Layout = new javax.swing.GroupLayout(jPanel18);
    jPanel18.setLayout(jPanel18Layout);
    jPanel18Layout.setHorizontalGroup(
    jPanel18Layout.createParallelGroup(javax.swing.Gro upLayout.Alignment.LEADING)
    .addGap(0, 758, Short.MAX_VALUE)
    );
    jPanel18Layout.setVerticalGroup(
    jPanel18Layout.createParallelGroup(javax.swing.Gro upLayout.Alignment.LEADING)
    .addGap(0, 30, Short.MAX_VALUE)
    );

    jPanel16.add(jPanel18, java.awt.BorderLayout.SOUTH);

    jPanel12.add(jPanel16, java.awt.BorderLayout.NORTH);

    jPanel9.add(jPanel12, java.awt.BorderLayout.CENTER);

    jPanel13.setPreferredSize(new java.awt.Dimension(5, 290));

    javax.swing.GroupLayout jPanel13Layout = new javax.swing.GroupLayout(jPanel13);
    jPanel13.setLayout(jPanel13Layout);
    jPanel13Layout.setHorizontalGroup(
    jPanel13Layout.createParallelGroup(javax.swing.Gro upLayout.Alignment.LEADING)
    .addGap(0, 5, Short.MAX_VALUE)
    );
    jPanel13Layout.setVerticalGroup(
    jPanel13Layout.createParallelGroup(javax.swing.Gro upLayout.Alignment.LEADING)
    .addGap(0, 390, Short.MAX_VALUE)
    );

    jPanel9.add(jPanel13, java.awt.BorderLayout.EAST);

    jPanel14.setPreferredSize(new java.awt.Dimension(5, 290));

    javax.swing.GroupLayout jPanel14Layout = new javax.swing.GroupLayout(jPanel14);
    jPanel14.setLayout(jPanel14Layout);
    jPanel14Layout.setHorizontalGroup(
    jPanel14Layout.createParallelGroup(javax.swing.Gro upLayout.Alignment.LEADING)
    .addGap(0, 5, Short.MAX_VALUE)
    );
    jPanel14Layout.setVerticalGroup(
    jPanel14Layout.createParallelGroup(javax.swing.Gro upLayout.Alignment.LEADING)
    .addGap(0, 390, Short.MAX_VALUE)
    );

    jPanel9.add(jPanel14, java.awt.BorderLayout.WEST);

    jPanel2.add(jPanel9, java.awt.BorderLayout.CENTER);

    getContentPane().add(jPanel2, java.awt.BorderLayout.PAGE_START);

    jPanel3.setLayout(new java.awt.BorderLayout());

    jPanel4.setPreferredSize(new java.awt.Dimension(1012, 5));

    javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
    jPanel4.setLayout(jPanel4Layout);
    jPanel4Layout.setHorizontalGroup(
    jPanel4Layout.createParallelGroup(javax.swing.Grou pLayout.Alignment.LEADING)
    .addGap(0, 1218, Short.MAX_VALUE)
    );
    jPanel4Layout.setVerticalGroup(
    jPanel4Layout.createParallelGroup(javax.swing.Grou pLayout.Alignment.LEADING)
    .addGap(0, 5, Short.MAX_VALUE)
    );

    jPanel3.add(jPanel4, java.awt.BorderLayout.NORTH);

    jPanel5.setPreferredSize(new java.awt.Dimension(1012, 5));

    javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
    jPanel5.setLayout(jPanel5Layout);
    jPanel5Layout.setHorizontalGroup(
    jPanel5Layout.createParallelGroup(javax.swing.Grou pLayout.Alignment.LEADING)
    .addGap(0, 1218, Short.MAX_VALUE)
    );
    jPanel5Layout.setVerticalGroup(
    jPanel5Layout.createParallelGroup(javax.swing.Grou pLayout.Alignment.LEADING)
    .addGap(0, 5, Short.MAX_VALUE)
    );

    jPanel3.add(jPanel5, java.awt.BorderLayout.SOUTH);

    jPanel6.setLayout(new java.awt.BorderLayout());

    jTableData001.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"
    }
    ));
    jTableData001.addKeyListener(new java.awt.event.KeyAdapter() {
    public void keyReleased(java.awt.event.KeyEvent evt) {
    jTableData001KeyReleased(evt);
    }
    });
    jScrollPane1.setViewportView(jTableData001);

    jPanel6.add(jScrollPane1, java.awt.BorderLayout.CENTER);

    jPanel3.add(jPanel6, java.awt.BorderLayout.CENTER);

    jPanel7.setPreferredSize(new java.awt.Dimension(5, 222));

    javax.swing.GroupLayout jPanel7Layout = new javax.swing.GroupLayout(jPanel7);
    jPanel7.setLayout(jPanel7Layout);
    jPanel7Layout.setHorizontalGroup(
    jPanel7Layout.createParallelGroup(javax.swing.Grou pLayout.Alignment.LEADING)
    .addGap(0, 5, Short.MAX_VALUE)
    );
    jPanel7Layout.setVerticalGroup(
    jPanel7Layout.createParallelGroup(javax.swing.Grou pLayout.Alignment.LEADING)
    .addGap(0, 250, Short.MAX_VALUE)
    );

    jPanel3.add(jPanel7, java.awt.BorderLayout.EAST);

    jPanel8.setPreferredSize(new java.awt.Dimension(5, 222));

    javax.swing.GroupLayout jPanel8Layout = new javax.swing.GroupLayout(jPanel8);
    jPanel8.setLayout(jPanel8Layout);
    jPanel8Layout.setHorizontalGroup(
    jPanel8Layout.createParallelGroup(javax.swing.Grou pLayout.Alignment.LEADING)
    .addGap(0, 5, Short.MAX_VALUE)
    );
    jPanel8Layout.setVerticalGroup(
    jPanel8Layout.createParallelGroup(javax.swing.Grou pLayout.Alignment.LEADING)
    .addGap(0, 250, Short.MAX_VALUE)
    );

    jPanel3.add(jPanel8, java.awt.BorderLayout.WEST);

    getContentPane().add(jPanel3, java.awt.BorderLayout.CENTER);

    setSize(new java.awt.Dimension(1234, 698));
    setLocationRelativeTo(null);
    }// </editor-fold>

    private void jButtonNewActionPerformed(java.awt.event.ActionEve nt evt) {
    // TODO add your handling code here:
    clear();
    }

    private void jButtonInsertActionPerformed(java.awt.event.Action Event evt) {
    // TODO add your handling code here:
    insert();
    }

    private void jButtonUpdateActionPerformed(java.awt.event.Action Event evt) {
    // TODO add your handling code here:
    update();
    }

    private void jButtonDeleteActionPerformed(java.awt.event.Action Event evt) {
    // TODO add your handling code here:
    delete();
    }

    private void jTextFieldSearchKeyReleased(java.awt.event.KeyEven t evt) {
    // TODO add your handling code here:
    searchKeyReleased();
    }

    private void jTableData001KeyReleased(java.awt.event.KeyEvent evt) {
    // TODO add your handling code here:
    }

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
    /* Set the Nimbus look and feel */
    //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
    /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
    * For details see How to Set the Look and Feel (The Java™ Tutorials > Creating a GUI With JFC/Swing > Modifying the Look and Feel)
    */
    try {
    for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
    if ("Nimbus".equals(info.getName())) {
    javax.swing.UIManager.setLookAndFeel(info.getClass Name());
    break;
    }
    }
    } catch (ClassNotFoundException ex) {
    java.util.logging.Logger.getLogger(JDialogData001. class.getName()).log(java.util.logging.Level.SEVER E, null, ex);
    } catch (InstantiationException ex) {
    java.util.logging.Logger.getLogger(JDialogData001. class.getName()).log(java.util.logging.Level.SEVER E, null, ex);
    } catch (IllegalAccessException ex) {
    java.util.logging.Logger.getLogger(JDialogData001. class.getName()).log(java.util.logging.Level.SEVER E, null, ex);
    } catch (javax.swing.UnsupportedLookAndFeelException ex) {
    java.util.logging.Logger.getLogger(JDialogData001. class.getName()).log(java.util.logging.Level.SEVER E, null, ex);
    }
    //</editor-fold>

    /* Create and display the dialog */
    java.awt.EventQueue.invokeLater(new Runnable() {
    public void run() {
    JDialogData001 dialog = new JDialogData001(new javax.swing.JFrame(), true);
    dialog.addWindowListener(new java.awt.event.WindowAdapter() {
    @Override
    public void windowClosing(java.awt.event.WindowEvent e) {
    System.exit(0);
    }
    });
    dialog.setVisible(true);
    }
    });
    }
    // Variables declaration - do not modify
    private javax.swing.JButton jButtonDelete;
    private javax.swing.JButton jButtonInsert;
    private javax.swing.JButton jButtonNew;
    private javax.swing.JButton jButtonUpdate;
    private javax.swing.JComboBox jComboBoxCivilStatus;
    private javax.swing.JComboBox jComboBoxGender;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel10;
    private javax.swing.JPanel jPanel11;
    private javax.swing.JPanel jPanel12;
    private javax.swing.JPanel jPanel13;
    private javax.swing.JPanel jPanel14;
    private javax.swing.JPanel jPanel15;
    private javax.swing.JPanel jPanel16;
    private javax.swing.JPanel jPanel17;
    private javax.swing.JPanel jPanel18;
    private javax.swing.JPanel jPanel19;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel20;
    private javax.swing.JPanel jPanel21;
    private javax.swing.JPanel jPanel22;
    private javax.swing.JPanel jPanel23;
    private javax.swing.JPanel jPanel24;
    private javax.swing.JPanel jPanel25;
    private javax.swing.JPanel jPanel26;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JPanel jPanel6;
    private javax.swing.JPanel jPanel7;
    private javax.swing.JPanel jPanel8;
    private javax.swing.JPanel jPanel9;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable jTableData001;
    private javax.swing.JTextField jTextFieldFirstName;
    private javax.swing.JTextField jTextFieldLastName;
    private javax.swing.JTextField jTextFieldMiddleName;
    private javax.swing.JTextField jTextFieldSearch;
    private javax.swing.JTextField jTextFieldSuffix;
    // End of variables declaration
    private void searchKeyReleased() {
    String text = jTextFieldSearch.getText().trim();
    if (text.length() == 0) {
    sorter.setRowFilter(null);
    } else {
    sorter.setRowFilter(RowFilter.regexFilter("(?i)" + text + ",*"));
    }
    }
    DefaultTableModel tmodel = new DefaultTableModel() {
    public Class getColumnClass(int columnIndex) {
    if (columnIndex == 5) {
    return Boolean.class;
    } else {
    return Object.class;
    }
    }

    //note that the data/cell address is constant
    //no matter where the cell appears onscreen.
    public boolean isCellEditable(int row, int col) {
    if (col < 10) {
    return false;

    } else {
    return true;
    }
    }
    };
    private TableRowSorter<TableModel> sorter = new TableRowSorter<TableModel>(tmodel);
    public static final DefaultTableCellRenderer DEFAULT_RENDERER = new DefaultTableCellRenderer();

    @Override
    public void mouseClicked(MouseEvent me) {
    if (me.getSource() == this.jTableData001) {
    if (me.getButton() == MouseEvent.BUTTON1) {
    if (me.getClickCount() == 1) {
    Object employeeidm;
    Object lastnamem;
    Object firstnamem;
    Object middlenamem;
    Object suffixm;
    Object genderm;
    Object civilstatusm;

    int selectedRow = jTableData001.getSelectedRow();
    employeeidm = jTableData001.getValueAt(selectedRow, 0);
    lastnamem = jTableData001.getValueAt(selectedRow, 2);
    firstnamem = jTableData001.getValueAt(selectedRow, 3);
    middlenamem = jTableData001.getValueAt(selectedRow, 4);
    suffixm = jTableData001.getValueAt(selectedRow, 5);
    genderm = jTableData001.getValueAt(selectedRow, 6);
    civilstatusm = jTableData001.getValueAt(selectedRow, 7);

    data001.setEmployee001ID(Integer.parseInt(employee idm.toString()));
    jTextFieldLastName.setText(lastnamem.toString());
    jTextFieldFirstName.setText(firstnamem.toString()) ;
    jTextFieldMiddleName.setText(middlenamem.toString( ));
    jTextFieldSuffix.setText(suffixm.toString());
    jComboBoxGender.setSelectedItem(genderm.toString() );
    jComboBoxCivilStatus.setSelectedItem(civilstatusm. toString());

    jButtonDelete.setEnabled(true);
    jButtonUpdate.setEnabled(true);
    jButtonInsert.setEnabled(false);
    }
    }
    }
    }

    @Override
    public void mousePressed(MouseEvent me) {
    }

    @Override
    public void mouseReleased(MouseEvent me) {
    }

    @Override
    public void mouseEntered(MouseEvent me) {
    }

    @Override
    public void mouseExited(MouseEvent me) {
    }

    class EvenOddRenderer implements TableCellRenderer {

    public Component getTableCellRendererComponent(JTable table, Object value,
    boolean isSelected, boolean hasFocus, int row, int column) {
    Component renderer = DEFAULT_RENDERER.getTableCellRendererComponent(
    table, value, isSelected, hasFocus, row, column);
    ((JLabel) renderer).setOpaque(true);
    Color foreground, background;
    if (isSelected) {
    foreground = Color.BLACK;
    background = Color.darkGray;
    } else {
    if (row % 2 == 0) {
    foreground = Color.getHSBColor(120, 100, 0);
    // background = Color.getHSBColor(30, 0, 362);
    background = Color.gray;
    } else {
    foreground = Color.getHSBColor(120, 100, 0);
    // background = Color.getHSBColor(10, 0, 60);
    background = Color.lightGray;
    }
    }
    renderer.setForeground(foreground);
    renderer.setBackground(background);
    return renderer;
    }
    }

    private void setTable() {
    String[] columnNames = {
    "EmployeeID",
    "EmployeeName",
    "Last_Name",
    "First_Name",
    "Middle_Name",
    "Suffix",
    "Gender",
    "Civil_Status"};

    jTableData001 = new javax.swing.JTable(tmodel);
    jTableData001.setAutoResizeMode(jTableData001.AUTO _RESIZE_LAST_COLUMN);
    jTableData001.setShowGrid(true);
    jTableData001.setRowSorter(sorter);
    this.jTableData001.setGridColor(Color.GREEN);
    jTableData001.setFillsViewportHeight(true);
    jTableData001.getTableHeader().setReorderingAllowe d(false);
    jTableData001.addMouseListener(this);
    jScrollPane1.setViewportView(jTableData001);
    JTableHeader hd = jTableData001.getTableHeader();
    hd.setForeground(Color.RED);
    hd.setBackground(Color.YELLOW);
    hd.setFont(hd.getFont().deriveFont(Font.BOLD));

    // header.setBackground(Color.darkGray);

    for (int i = 0; i
    < columnNames.length;) {
    tmodel.addColumn(columnNames[i]);
    i++;
    }



    TableColumn[] column = new TableColumn[100];
    TableColumn hidden = jTableData001.getColumnModel().getColumn(0);
    hidden.setMinWidth(0);
    hidden.setPreferredWidth(0);
    hidden.setMaxWidth(0);

    TableColumn hidden1 = jTableData001.getColumnModel().getColumn(2);
    hidden1.setMinWidth(0);
    hidden1.setPreferredWidth(0);
    hidden1.setMaxWidth(0);

    TableColumn hidden2 = jTableData001.getColumnModel().getColumn(3);
    hidden2.setMinWidth(0);
    hidden2.setPreferredWidth(0);
    hidden2.setMaxWidth(0);

    TableColumn hidden3 = jTableData001.getColumnModel().getColumn(4);
    hidden3.setMinWidth(0);
    hidden3.setPreferredWidth(0);
    hidden3.setMaxWidth(0);

    TableColumn hidden4 = jTableData001.getColumnModel().getColumn(5);
    hidden4.setMinWidth(0);
    hidden4.setPreferredWidth(0);
    hidden4.setMaxWidth(0);


    }

    private void select() {
    tmodel.setRowCount(0);
    data001.select();
    for (int i = 0; i < data001.getData().size(); i++) {
    tmodel.addRow((Vector) data001.getData().get(i));

    }
    }

    private void clear() {
    jTextFieldLastName.setText("");
    jTextFieldFirstName.setText("");
    jTextFieldMiddleName.setText("");
    jTextFieldSuffix.setText("");
    jComboBoxGender.setSelectedItem("none");
    jComboBoxCivilStatus.setSelectedItem("none");

    jButtonInsert.setEnabled(true);
    jButtonUpdate.setEnabled(false);
    jButtonDelete.setEnabled(false);

    }

    private void fieldValidation() {
    if(jTextFieldLastName.getText() == "") {
    JOptionPane.showMessageDialog(this, "Last name is empty!");
    return;

    }else if(jTextFieldFirstName.getText()=="") {
    JOptionPane.showMessageDialog(this, "First name is empty!");
    return;
    }
    else if(jTextFieldMiddleName.getText()=="") {
    JOptionPane.showMessageDialog(this, "Middle name is empty!");
    return;
    }
    else if(jComboBoxGender.getSelectedItem()=="none") {
    JOptionPane.showMessageDialog(this, "Gender was not selected!");
    return;
    }
    else if(jComboBoxCivilStatus.getSelectedItem()=="") {
    JOptionPane.showMessageDialog(this, "Civil status was not selected!");
    return;
    }
    }
    private void insert() {
    if(jTextFieldLastName.getText() == "") {
    JOptionPane.showMessageDialog(this, "Last name is empty!");
    return;

    }else if(jTextFieldFirstName.getText()=="") {
    JOptionPane.showMessageDialog(this, "First name is empty!");
    return;
    }
    else if(jTextFieldMiddleName.getText()=="") {
    JOptionPane.showMessageDialog(this, "Middle name is empty!");
    return;
    }
    else if(jComboBoxGender.getSelectedItem()=="none") {
    JOptionPane.showMessageDialog(this, "Gender was not selected!");
    return;
    }
    else if(jComboBoxCivilStatus.getSelectedItem()=="") {
    JOptionPane.showMessageDialog(this, "Civil status was not selected!");
    return;
    }

    int reply = JOptionPane.showConfirmDialog(this, "Are you sure to save this course?", "Save confirmation", JOptionPane.OK_CANCEL_OPTION);
    if(reply == JOptionPane.YES_OPTION) {
    data001.setLastname(jTextFieldLastName.getText());
    data001.setFirstname(jTextFieldFirstName.getText() );
    data001.setMiddlename(jTextFieldMiddleName.getText ());
    data001.setSuffix(jTextFieldSuffix.getText());
    data001.setGender(jComboBoxGender.getSelectedItem( ).toString());
    data001.setCivilstatus(jComboBoxCivilStatus.getSel ectedItem().toString());
    data001.insert();
    JOptionPane.showMessageDialog(this, " Successfully saved!");
    select();
    clear();

    }else if(reply == JOptionPane.CLOSED_OPTION) {
    JOptionPane.showMessageDialog(this, " Insert canceled!");
    }
    }

    private void update() {
    int reply = JOptionPane.showConfirmDialog(this, "Are you sure to update this course?", "Update confirmation", JOptionPane.OK_CANCEL_OPTION);
    if(reply == JOptionPane.YES_OPTION) {
    data001.setLastname(jTextFieldLastName.getText());
    data001.setFirstname(jTextFieldFirstName.getText() );
    data001.setMiddlename(jTextFieldMiddleName.getText ());
    data001.setSuffix(jTextFieldSuffix.getText());
    data001.setGender(jComboBoxGender.getSelectedItem( ).toString());
    data001.setCivilstatus(jComboBoxCivilStatus.getSel ectedItem().toString());
    data001.update();
    JOptionPane.showMessageDialog(this, " Successfully updated!");
    select();
    clear();
    }else if(reply == JOptionPane.CLOSED_OPTION) {
    JOptionPane.showMessageDialog(this, " Update canceled!");
    }
    }

    private void delete() {
    int reply = JOptionPane.showConfirmDialog(this, "Are you sure to delete this course?", "Delete confirmation", JOptionPane.OK_CANCEL_OPTION);
    if(reply == JOptionPane.YES_OPTION) {
    data001.delete();
    JOptionPane.showMessageDialog(this, " Successfully deleted!");
    select();
    clear();
    }else if(reply == JOptionPane.CLOSED_OPTION) {
    JOptionPane.showMessageDialog(this, " Delete canceled!");
    }
    }

    private void autoDisableButton() {
    jButtonUpdate.setEnabled(false);
    jButtonDelete.setEnabled(false);

    }

    }

    OUTPUT:
    Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Boolean
    at javax.swing.plaf.synth.SynthTableUI$SynthBooleanTa bleCellRenderer.getTableCellRendererComponent(Synt hTableUI.java:731)
    at javax.swing.JTable.prepareRenderer(JTable.java:573 1)
    at javax.swing.plaf.synth.SynthTableUI.paintCell(Synt hTableUI.java:684)
    at javax.swing.plaf.synth.SynthTableUI.paintCells(Syn thTableUI.java:581)
    at javax.swing.plaf.synth.SynthTableUI.paint(SynthTab leUI.java:365)
    at javax.swing.plaf.synth.SynthTableUI.update(SynthTa bleUI.java:276)
    at javax.swing.JComponent.paintComponent(JComponent.j ava:778)
    at javax.swing.JComponent.paint(JComponent.java:1054)
    at javax.swing.JComponent.paintChildren(JComponent.ja va:887)
    at javax.swing.JComponent.paint(JComponent.java:1063)
    at javax.swing.JViewport.paint(JViewport.java:731)
    at javax.swing.JComponent.paintChildren(JComponent.ja va:887)
    at javax.swing.JComponent.paint(JComponent.java:1063)
    at javax.swing.JComponent.paintChildren(JComponent.ja va:887)
    at javax.swing.JComponent.paint(JComponent.java:1063)
    at javax.swing.JComponent.paintChildren(JComponent.ja va:887)
    at javax.swing.JComponent.paint(JComponent.java:1063)
    at javax.swing.JComponent.paintChildren(JComponent.ja va:887)
    at javax.swing.JComponent.paint(JComponent.java:1063)
    at javax.swing.JComponent.paintChildren(JComponent.ja va:887)
    at javax.swing.JComponent.paint(JComponent.java:1063)
    at javax.swing.JLayeredPane.paint(JLayeredPane.java:5 85)
    at javax.swing.JComponent.paintChildren(JComponent.ja va:887)
    at javax.swing.JComponent.paintToOffscreen(JComponent .java:5228)
    at javax.swing.RepaintManager$PaintManager.paintDoubl eBuffered(RepaintManager.java:1512)
    at javax.swing.RepaintManager$PaintManager.paint(Repa intManager.java:1443)
    at javax.swing.RepaintManager.paint(RepaintManager.ja va:1236)
    at javax.swing.JComponent.paint(JComponent.java:1040)
    at java.awt.GraphicsCallback$PaintCallback.run(Graphi csCallback.java:39)
    at sun.awt.SunGraphicsCallback.runOneComponent(SunGra phicsCallback.java:78)
    at sun.awt.SunGraphicsCallback.runComponents(SunGraph icsCallback.java:115)
    at java.awt.Container.paint(Container.java:1967)
    at java.awt.Window.paint(Window.java:3877)
    at javax.swing.RepaintManager$3.run(RepaintManager.ja va:807)
    at javax.swing.RepaintManager$3.run(RepaintManager.ja va:784)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPri vilege(ProtectionDomain.java:76)
    at javax.swing.RepaintManager.paintDirtyRegions(Repai ntManager.java:784)
    at javax.swing.RepaintManager.paintDirtyRegions(Repai ntManager.java:757)
    at javax.swing.RepaintManager.prePaintDirtyRegions(Re paintManager.java:706)
    at javax.swing.RepaintManager.access$1000(RepaintMana ger.java:62)
    at javax.swing.RepaintManager$ProcessingRunnable.run( RepaintManager.java:1651)
    at java.awt.event.InvocationEvent.dispatch(Invocation Event.java:251)
    at java.awt.EventQueue.dispatchEventImpl(EventQueue.j ava:727)
    at java.awt.EventQueue.access$200(EventQueue.java:103 )
    at java.awt.EventQueue$3.run(EventQueue.java:688)
    at java.awt.EventQueue$3.run(EventQueue.java:686)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPri vilege(ProtectionDomain.java:76)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java: 697)
    at java.awt.EventDispatchThread.pumpOneEventForFilter s(EventDispatchThread.java:242)
    at java.awt.EventDispatchThread.pumpEventsForFilter(E ventDispatchThread.java:161)
    at java.awt.EventDispatchThread.pumpEventsForFilter(E ventDispatchThread.java:154)
    at java.awt.WaitDispatchSupport$2.run(WaitDispatchSup port.java:182)
    at java.awt.WaitDispatchSupport$4.run(WaitDispatchSup port.java:222
    BUILD SUCCESSFUL (total time: 1 minute 36 seconds)

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,776
    Blog Entries
    7
    Rep Power
    21

    Default Re: java.lang.String cannot be cast to java.lang.Boolean

    Ask the folks who wrote that Form Editor; you can't expect us to wade through all that unformatted, crappy code, with nothing more than a stack trace that gives no indication whatsoever where in 'your' code the exception was raised. My suggestion: rewrite everything and dump this crap.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,899
    Rep Power
    25

    Default Re: java.lang.String cannot be cast to java.lang.Boolean

    A String is NOT a Boolean
    and a Boolean is NOT a String.
    If you don't understand my response, don't ignore it, ask a question.

  4. #4
    putapepe is offline Member
    Join Date
    Apr 2014
    Posts
    7
    Rep Power
    0

    Default Re: java.lang.String cannot be cast to java.lang.Boolean

    Dear Sir Jos,
    Actually I'm making a GUI system using JFrameDialog. When I run my program, there's no error. So now, I'm going to fill up those text field to be able to save in my database. After I successfully save some data in those text fields, the "java.lang.String cannot be cast to java.lang.Boolean" will show. And when I open my MySQL (source database), the data is completely there. And every time I run my program, "java.lang.String cannot be cast to java.lang.Boolean" will show and I cannot see those text fields, labels for text fields, combobox, button, and table. The funny thing there is, when those palette didn't display, I simply click those palette and they will show but my others design will not display. But i can still insert, update and delete my database. My only main problem is, this error "java.lang.String cannot be cast to java.lang.Boolean". Please help me sir.

    Thanks for your consideration,
    pepe

  5. #5
    putapepe is offline Member
    Join Date
    Apr 2014
    Posts
    7
    Rep Power
    0

    Default Re: java.lang.String cannot be cast to java.lang.Boolean

    If you have question in my code, just ask me and i'll answer you...
    This is my Code:

    import java.awt.Color;
    import java.awt.Component;
    import java.awt.Font;
    import java.awt.event.MouseEvent;
    import java.awt.event.MouseListener;
    import java.util.Vector;
    import javax.swing.JLabel;
    import javax.swing.JOptionPane;
    import javax.swing.JTable;
    import javax.swing.RowFilter;
    import javax.swing.table.DefaultTableCellRenderer;
    import javax.swing.table.DefaultTableModel;
    import javax.swing.table.JTableHeader;
    import javax.swing.table.TableCellRenderer;
    import javax.swing.table.TableColumn;
    import javax.swing.table.TableModel;
    import javax.swing.table.TableRowSorter;
    public class JDialogData001 extends javax.swing.JDialog implements MouseListener {
    private data001 data001 = new data001();

    public JDialogData001(java.awt.Frame parent, boolean modal) {
    super(parent, modal);
    initComponents();
    autoDisableButton();
    setTable();
    select();
    }

    private void jButtonNewActionPerformed(java.awt.event.ActionEve nt evt) {
    // TODO add your handling code here:
    clear();
    }

    private void jButtonInsertActionPerformed(java.awt.event.Action Event evt) {
    // TODO add your handling code here:
    insert();
    }

    private void jButtonUpdateActionPerformed(java.awt.event.Action Event evt) {
    // TODO add your handling code here:
    update();
    }

    private void jButtonDeleteActionPerformed(java.awt.event.Action Event evt) {
    // TODO add your handling code here:
    delete();
    }

    private void jTextFieldSearchKeyReleased(java.awt.event.KeyEven t evt) {
    // TODO add your handling code here:
    searchKeyReleased();
    }

    private void searchKeyReleased() {
    String text = jTextFieldSearch.getText().trim();
    if (text.length() == 0) {
    sorter.setRowFilter(null);
    } else {
    sorter.setRowFilter(RowFilter.regexFilter("(?i)" + text + ",*"));
    }
    }
    DefaultTableModel tmodel = new DefaultTableModel() {
    public Class getColumnClass(int columnIndex) {
    if (columnIndex == 5) {
    return Boolean.class;
    } else {
    return Object.class;
    }
    }

    private void searchKeyReleased() {
    String text = jTextFieldSearch.getText().trim();
    if (text.length() == 0) {
    sorter.setRowFilter(null);
    } else {
    sorter.setRowFilter(RowFilter.regexFilter("(?i)" + text + ",*"));
    }
    }
    DefaultTableModel tmodel = new DefaultTableModel() {
    public Class getColumnClass(int columnIndex) {
    if (columnIndex == 5) {
    return Boolean.class;
    } else {
    return Object.class;
    }
    }

    //note that the data/cell address is constant
    //no matter where the cell appears onscreen.
    public boolean isCellEditable(int row, int col) {
    if (col < 10) {
    return false;

    } else {
    return true;
    }
    }
    };
    private TableRowSorter<TableModel> sorter = new TableRowSorter<TableModel>(tmodel);
    public static final DefaultTableCellRenderer DEFAULT_RENDERER = new DefaultTableCellRenderer();

    @Override
    public void mouseClicked(MouseEvent me) {
    if (me.getSource() == this.jTableData001) {
    if (me.getButton() == MouseEvent.BUTTON1) {
    if (me.getClickCount() == 1) {
    Object employeeidm;
    Object lastnamem;
    Object firstnamem;
    Object middlenamem;
    Object suffixm;
    Object genderm;
    Object civilstatusm;

    int selectedRow = jTableData001.getSelectedRow();
    employeeidm = jTableData001.getValueAt(selectedRow, 0);
    lastnamem = jTableData001.getValueAt(selectedRow, 2);
    firstnamem = jTableData001.getValueAt(selectedRow, 3);
    middlenamem = jTableData001.getValueAt(selectedRow, 4);
    suffixm = jTableData001.getValueAt(selectedRow, 5);
    genderm = jTableData001.getValueAt(selectedRow, 6);
    civilstatusm = jTableData001.getValueAt(selectedRow, 7);

    data001.setEmployee001ID(Integer.parseInt(employee idm.toString()));
    jTextFieldLastName.setText(lastnamem.toString());
    jTextFieldFirstName.setText(firstnamem.toString()) ;
    jTextFieldMiddleName.setText(middlenamem.toString( ));
    jTextFieldSuffix.setText(suffixm.toString());
    jComboBoxGender.setSelectedItem(genderm.toString() );
    jComboBoxCivilStatus.setSelectedItem(civilstatusm. toString());

    jButtonDelete.setEnabled(true);
    jButtonUpdate.setEnabled(true);
    jButtonInsert.setEnabled(false);
    }
    }
    }
    }

    @Override
    public void mousePressed(MouseEvent me) {
    }

    @Override
    public void mouseReleased(MouseEvent me) {
    }

    @Override
    public void mouseEntered(MouseEvent me) {
    }

    @Override
    public void mouseExited(MouseEvent me) {
    }

    class EvenOddRenderer implements TableCellRenderer {

    public Component getTableCellRendererComponent(JTable table, Object value,
    boolean isSelected, boolean hasFocus, int row, int column) {
    Component renderer = DEFAULT_RENDERER.getTableCellRendererComponent(
    table, value, isSelected, hasFocus, row, column);
    ((JLabel) renderer).setOpaque(true);
    Color foreground, background;
    if (isSelected) {
    foreground = Color.BLACK;
    background = Color.darkGray;
    } else {
    if (row % 2 == 0) {
    foreground = Color.getHSBColor(120, 100, 0);
    // background = Color.getHSBColor(30, 0, 362);
    background = Color.gray;
    } else {
    foreground = Color.getHSBColor(120, 100, 0);
    // background = Color.getHSBColor(10, 0, 60);
    background = Color.lightGray;
    }
    }
    renderer.setForeground(foreground);
    renderer.setBackground(background);
    return renderer;
    }
    }

    private void setTable() {
    String[] columnNames = {
    "EmployeeID",
    "EmployeeName",
    "Last_Name",
    "First_Name",
    "Middle_Name",
    "Suffix",
    "Gender",
    "Civil_Status"};

    jTableData001 = new javax.swing.JTable(tmodel);
    jTableData001.setAutoResizeMode(jTableData001.AUTO _RESIZE_LAST_COLUMN);
    jTableData001.setShowGrid(true);
    jTableData001.setRowSorter(sorter);
    this.jTableData001.setGridColor(Color.GREEN);
    jTableData001.setFillsViewportHeight(true);
    jTableData001.getTableHeader().setReorderingAllowe d(false);
    jTableData001.addMouseListener(this);
    jScrollPane1.setViewportView(jTableData001);
    JTableHeader hd = jTableData001.getTableHeader();
    hd.setForeground(Color.RED);
    hd.setBackground(Color.YELLOW);
    hd.setFont(hd.getFont().deriveFont(Font.BOLD));

    // header.setBackground(Color.darkGray);

    for (int i = 0; i
    < columnNames.length;) {
    tmodel.addColumn(columnNames[i]);
    i++;
    }



    TableColumn[] column = new TableColumn[100];
    TableColumn hidden = jTableData001.getColumnModel().getColumn(0);
    hidden.setMinWidth(0);
    hidden.setPreferredWidth(0);
    hidden.setMaxWidth(0);

    TableColumn hidden1 = jTableData001.getColumnModel().getColumn(2);
    hidden1.setMinWidth(0);
    hidden1.setPreferredWidth(0);
    hidden1.setMaxWidth(0);

    TableColumn hidden2 = jTableData001.getColumnModel().getColumn(3);
    hidden2.setMinWidth(0);
    hidden2.setPreferredWidth(0);
    hidden2.setMaxWidth(0);

    TableColumn hidden3 = jTableData001.getColumnModel().getColumn(4);
    hidden3.setMinWidth(0);
    hidden3.setPreferredWidth(0);
    hidden3.setMaxWidth(0);

    TableColumn hidden4 = jTableData001.getColumnModel().getColumn(5);
    hidden4.setMinWidth(0);
    hidden4.setPreferredWidth(0);
    hidden4.setMaxWidth(0);


    }

    private void select() {
    tmodel.setRowCount(0);
    data001.select();
    for (int i = 0; i < data001.getData().size(); i++) {
    tmodel.addRow((Vector) data001.getData().get(i));

    }
    }

    private void clear() {
    jTextFieldLastName.setText("");
    jTextFieldFirstName.setText("");
    jTextFieldMiddleName.setText("");
    jTextFieldSuffix.setText("");
    jComboBoxGender.setSelectedItem("none");
    jComboBoxCivilStatus.setSelectedItem("none");

    jButtonInsert.setEnabled(true);
    jButtonUpdate.setEnabled(false);
    jButtonDelete.setEnabled(false);

    }

    private void fieldValidation() {
    if(jTextFieldLastName.getText() == "") {
    JOptionPane.showMessageDialog(this, "Last name is empty!");
    return;

    }else if(jTextFieldFirstName.getText()=="") {
    JOptionPane.showMessageDialog(this, "First name is empty!");
    return;
    }
    else if(jTextFieldMiddleName.getText()=="") {
    JOptionPane.showMessageDialog(this, "Middle name is empty!");
    return;
    }
    else if(jComboBoxGender.getSelectedItem()=="none") {
    JOptionPane.showMessageDialog(this, "Gender was not selected!");
    return;
    }
    else if(jComboBoxCivilStatus.getSelectedItem()=="") {
    JOptionPane.showMessageDialog(this, "Civil status was not selected!");
    return;
    }
    }
    private void insert() {
    if(jTextFieldLastName.getText() == "") {
    JOptionPane.showMessageDialog(this, "Last name is empty!");
    return;

    }else if(jTextFieldFirstName.getText()=="") {
    JOptionPane.showMessageDialog(this, "First name is empty!");
    return;
    }
    else if(jTextFieldMiddleName.getText()=="") {
    JOptionPane.showMessageDialog(this, "Middle name is empty!");
    return;
    }
    else if(jComboBoxGender.getSelectedItem()=="none") {
    JOptionPane.showMessageDialog(this, "Gender was not selected!");
    return;
    }
    else if(jComboBoxCivilStatus.getSelectedItem()=="") {
    JOptionPane.showMessageDialog(this, "Civil status was not selected!");
    return;
    }

    int reply = JOptionPane.showConfirmDialog(this, "Are you sure to save this course?", "Save confirmation", JOptionPane.OK_CANCEL_OPTION);
    if(reply == JOptionPane.YES_OPTION) {
    data001.setLastname(jTextFieldLastName.getText());
    data001.setFirstname(jTextFieldFirstName.getText() );
    data001.setMiddlename(jTextFieldMiddleName.getText ());
    data001.setSuffix(jTextFieldSuffix.getText());
    data001.setGender(jComboBoxGender.getSelectedItem( ).toString());
    data001.setCivilstatus(jComboBoxCivilStatus.getSel ectedItem().toString());
    data001.insert();
    JOptionPane.showMessageDialog(this, " Successfully saved!");
    select();
    clear();

    }else if(reply == JOptionPane.CLOSED_OPTION) {
    JOptionPane.showMessageDialog(this, " Insert canceled!");
    }
    }

    private void update() {
    int reply = JOptionPane.showConfirmDialog(this, "Are you sure to update this course?", "Update confirmation", JOptionPane.OK_CANCEL_OPTION);
    if(reply == JOptionPane.YES_OPTION) {
    data001.setLastname(jTextFieldLastName.getText());
    data001.setFirstname(jTextFieldFirstName.getText() );
    data001.setMiddlename(jTextFieldMiddleName.getText ());
    data001.setSuffix(jTextFieldSuffix.getText());
    data001.setGender(jComboBoxGender.getSelectedItem( ).toString());
    data001.setCivilstatus(jComboBoxCivilStatus.getSel ectedItem().toString());
    data001.update();
    JOptionPane.showMessageDialog(this, " Successfully updated!");
    select();
    clear();
    }else if(reply == JOptionPane.CLOSED_OPTION) {
    JOptionPane.showMessageDialog(this, " Update canceled!");
    }
    }

    private void delete() {
    int reply = JOptionPane.showConfirmDialog(this, "Are you sure to delete this course?", "Delete confirmation", JOptionPane.OK_CANCEL_OPTION);
    if(reply == JOptionPane.YES_OPTION) {
    data001.delete();
    JOptionPane.showMessageDialog(this, " Successfully deleted!");
    select();
    clear();
    }else if(reply == JOptionPane.CLOSED_OPTION) {
    JOptionPane.showMessageDialog(this, " Delete canceled!");
    }
    }

    private void autoDisableButton() {
    jButtonUpdate.setEnabled(false);
    jButtonDelete.setEnabled(false);

    }

    }
    Last edited by putapepe; 04-06-2014 at 08:04 PM.

  6. #6
    putapepe is offline Member
    Join Date
    Apr 2014
    Posts
    7
    Rep Power
    0

    Default Re: java.lang.String cannot be cast to java.lang.Boolean

    Is there any problem with this?

    ...
    public JDialogData001(java.awt.Frame parent, boolean modal) {
    super(parent, modal);
    initComponents();
    autoDisableButton();
    setTable();
    select();
    }
    ...

  7. #7
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,776
    Blog Entries
    7
    Rep Power
    21

    Default Re: java.lang.String cannot be cast to java.lang.Boolean

    No, that's not the problem; it just defines that your dialog should be mobile; if it were incorrect, you would've received a compilation error.

    kind regards,

    Jos

    ps. don't post too much (unformatted) code; it scares people off (at least, I don't want to plough through all that messy stuff). Maybe you can sprinkle in some System.err.println( ... ) statements and figure out where your code throws that exception (note that I used the 'err' stream instead of the more usual 'out' stream).
    cenosillicaphobia: the fear for an empty beer glass

  8. #8
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,899
    Rep Power
    25

    Default Re: java.lang.String cannot be cast to java.lang.Boolean

    The code is using == to compare Strings. It should use the equals() method.
    If you don't understand my response, don't ignore it, ask a question.

Similar Threads

  1. Replies: 3
    Last Post: 05-02-2011, 08:51 AM
  2. Replies: 5
    Last Post: 03-17-2011, 03:26 PM
  3. Replies: 6
    Last Post: 05-27-2009, 02:17 AM
  4. Replies: 2
    Last Post: 09-18-2008, 08:30 AM
  5. Replies: 1
    Last Post: 08-02-2007, 05:07 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •