Java tutorial
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package com.cch.aj.entryrecorder.frame; import com.cch.aj.entryrecorder.common.AppHelper; import com.cch.aj.entryrecorder.entities.Checkitem; import com.cch.aj.entryrecorder.entities.Entry; import com.cch.aj.entryrecorder.entities.Record; import com.cch.aj.entryrecorder.services.SettingService; import com.cch.aj.entryrecorder.services.impl.SettingServiceImpl; import java.text.SimpleDateFormat; import javax.swing.JFrame; import javax.swing.JOptionPane; import javax.swing.table.DefaultTableModel; import javax.swing.table.TableModel; import org.springframework.beans.factory.annotation.Autowired; /** * * @author chacao */ public class CheckJFrame extends javax.swing.JFrame { @Autowired private SettingService<Entry> entryService; /** * Creates new form CheckJFrame */ public CheckJFrame() { initComponents(); } private void init() { this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); this.tblCheck.getColumnModel().getColumn(1).setMaxWidth(80); DefaultTableModel model = (DefaultTableModel) this.tblCheck.getModel(); for (Checkitem ci : AppHelper.entryProduct.getCheckitemCollection()) { model.addRow(new Object[] { ci.getDescription(), false }); } } /** * 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">//GEN-BEGIN:initComponents private void initComponents() { java.awt.GridBagConstraints gridBagConstraints; jLabel1 = new javax.swing.JLabel(); jScrollPane1 = new javax.swing.JScrollPane(); tblCheck = new javax.swing.JTable(); jButton1 = new javax.swing.JButton(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); setPreferredSize(new java.awt.Dimension(600, 400)); getContentPane().setLayout(new java.awt.GridBagLayout()); jLabel1.setFont(new java.awt.Font("Dialog", 1, 14)); // NOI18N jLabel1.setText("Check List"); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 0; gridBagConstraints.insets = new java.awt.Insets(21, 21, 21, 21); getContentPane().add(jLabel1, gridBagConstraints); tblCheck.setModel(new javax.swing.table.DefaultTableModel(new Object[][] { }, new String[] { "Item", "Check" }) { Class[] types = new Class[] { java.lang.String.class, java.lang.Boolean.class }; public Class getColumnClass(int columnIndex) { return types[columnIndex]; } }); tblCheck.setToolTipText(""); jScrollPane1.setViewportView(tblCheck); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 1; gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; gridBagConstraints.weightx = 1.0; gridBagConstraints.weighty = 1.0; getContentPane().add(jScrollPane1, gridBagConstraints); jButton1.setText("OK"); jButton1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton1ActionPerformed(evt); } }); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 2; gridBagConstraints.ipadx = 9; gridBagConstraints.ipady = 9; gridBagConstraints.insets = new java.awt.Insets(13, 13, 13, 13); getContentPane().add(jButton1, gridBagConstraints); pack(); }// </editor-fold>//GEN-END:initComponents private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed boolean result = true; int count = this.tblCheck.getRowCount(); TableModel model = tblCheck.getModel(); for (int i = 0; i < count; i++) { Boolean isChecked = (Boolean) model.getValueAt(i, 1); if (!isChecked) { result = false; break; } } if (result) { AppHelper.currentEntry.setIsChecked(true); this.entryService.UpdateEntity(AppHelper.currentEntry); this.setVisible(false); this.dispose(); } else { JOptionPane.showMessageDialog(this, "Please check all items", "Warming", JOptionPane.OK_OPTION); } }//GEN-LAST:event_jButton1ActionPerformed /** * @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 http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html */ try { for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) { if ("Nimbus".equals(info.getName())) { javax.swing.UIManager.setLookAndFeel(info.getClassName()); break; } } } catch (ClassNotFoundException ex) { java.util.logging.Logger.getLogger(CheckJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (InstantiationException ex) { java.util.logging.Logger.getLogger(CheckJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (IllegalAccessException ex) { java.util.logging.Logger.getLogger(CheckJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (javax.swing.UnsupportedLookAndFeelException ex) { java.util.logging.Logger.getLogger(CheckJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } //</editor-fold> /* Create and display the form */ java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new CheckJFrame().setVisible(true); } }); } // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton jButton1; private javax.swing.JLabel jLabel1; private javax.swing.JScrollPane jScrollPane1; private javax.swing.JTable tblCheck; // End of variables declaration//GEN-END:variables }