Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- here my full code .. i added listener in addbtn action performed method.. but not showing total in the total column as i enter qty and discount... :(
- import java.awt.Toolkit;
- import java.awt.event.KeyAdapter;
- import java.awt.event.KeyEvent;
- import java.sql.Connection;
- import java.sql.PreparedStatement;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.sql.Statement;
- import java.util.ArrayList;
- import java.util.Vector;
- import java.util.logging.Level;
- import java.util.logging.Logger;
- import javax.swing.DefaultComboBoxModel;
- import javax.swing.JOptionPane;
- import javax.swing.JTable;
- import javax.swing.JTextField;
- import javax.swing.SwingUtilities;
- import javax.swing.event.TableModelEvent;
- import javax.swing.event.TableModelListener;
- import javax.swing.table.DefaultTableModel;
- import javax.swing.table.TableModel;
- import net.proteanit.sql.DbUtils;
- /**
- *
- * @author Tili
- */
- public class Newsale extends javax.swing.JFrame {
- Connection conn = null;
- Statement stmt= null;
- PreparedStatement pst = null;
- ResultSet rs = null;
- private TableModelListener tableModelListener;
- /**
- * Creates new form newSale
- */
- public Newsale() throws SQLException {
- initComponents();
- this.setLocation(300,100);
- initialize();
- conn = MYSQLConnect.ConnectDB();
- setLocationRelativeTo(null);
- final JTextField txtfield = (JTextField) IDcombo.getEditor().getEditorComponent();
- txtfield.addKeyListener(new KeyAdapter() {
- public void keyReleased(KeyEvent ke){
- SwingUtilities.invokeLater(new Runnable() {
- @Override
- public void run() {
- try {
- comboFilter(txtfield.getText());
- } catch (SQLException ex) {
- Logger.getLogger(Newsale.class.getName()).log(Level.SEVERE, null, ex);
- }
- }
- });
- }
- });
- final JTextField txtfield2 = (JTextField) Namecombo.getEditor().getEditorComponent();
- txtfield2.addKeyListener(new KeyAdapter() {
- public void keyReleased(KeyEvent ke){
- SwingUtilities.invokeLater(new Runnable() {
- @Override
- public void run() {
- try {
- comboFilter(txtfield2.getText());
- } catch (SQLException ex) {
- Logger.getLogger(Newsale.class.getName()).log(Level.SEVERE, null, ex);
- }
- }
- });
- }
- });
- }
- public void comboFilter(String enteredText) throws SQLException{
- ArrayList<String> filterArray = new ArrayList<String>();
- ArrayList<String> filterArray2 = new ArrayList<String>();
- String str1="";
- String str2="";
- try{
- String str = "SELECT * FROM druginfo WHERE ItemId LIKE '"+enteredText+"%'";
- stmt = conn.createStatement();
- rs = stmt.executeQuery(str);
- while(rs.next()){
- str1=rs.getString("ItemId");
- filterArray.add(str1);
- }
- }catch(Exception e ){
- JOptionPane.showMessageDialog(null,"Error " +e);
- }
- try{
- String str0 = "SELECT * FROM druginfo WHERE ItemName LIKE '"+enteredText+"%'";
- stmt = conn.createStatement();
- rs = stmt.executeQuery(str0);
- while(rs.next()){
- str2=rs.getString("ItemName");
- filterArray2.add(str2);
- }
- }catch(Exception e ){
- JOptionPane.showMessageDialog(null,"Error " +e);
- }
- if(filterArray.size()>0){
- IDcombo.setModel(new DefaultComboBoxModel(filterArray.toArray()));
- IDcombo.setSelectedItem(enteredText);
- IDcombo.showPopup();
- } else{
- IDcombo.hidePopup();
- }
- if(filterArray2.size()>0){
- Namecombo.setModel(new DefaultComboBoxModel(filterArray2.toArray()));
- Namecombo.setSelectedItem(enteredText);
- Namecombo.showPopup();
- }else{
- Namecombo.hidePopup();
- }
- }
- //changing the titile bar java icon
- private void initialize(){
- this.setIconImage(Toolkit.getDefaultToolkit().getImage(getClass().getResource("cash-register-icon.png")));
- }
- //for adding multiple lines in the jtable
- public void addDataToTable(JTable table,TableModel model) {
- DefaultTableModel tableModel = (DefaultTableModel) table.getModel();
- DefaultTableModel resultSetModel = (DefaultTableModel) model;
- for (int i = 0; i < resultSetModel.getRowCount(); i++) {
- Vector row=new Vector();
- for (int j = 0; j < resultSetModel.getColumnCount(); j++) {
- row.addElement(resultSetModel.getValueAt(i, j));
- }
- tableModel.addRow(row);
- }
- tableModel.fireTableDataChanged();
- }
- // }
- //}
- /**
- * 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() {
- jPanel1 = new javax.swing.JPanel();
- jDesktopPane1 = new javax.swing.JDesktopPane();
- newSaleBtn = new javax.swing.JButton();
- searchInvoiceBtn = new javax.swing.JButton();
- saleInvoiceHelpBtn = new javax.swing.JButton();
- saleInvoicePrintBtn = new javax.swing.JButton();
- saleInvoicePreviousBtn = new javax.swing.JButton();
- saleInvoiceNextBtn = new javax.swing.JButton();
- saleInvoiceHomeBtn = new javax.swing.JButton();
- jLabel4 = new javax.swing.JLabel();
- jLabel5 = new javax.swing.JLabel();
- jLabel7 = new javax.swing.JLabel();
- dayChooser = new com.toedter.calendar.JDateChooser();
- jButton5 = new javax.swing.JButton();
- countitems_txt = new javax.swing.JTextField();
- jTextField1 = new javax.swing.JTextField();
- IDcombo = new javax.swing.JComboBox();
- jTextField3 = new javax.swing.JTextField();
- jLabel9 = new javax.swing.JLabel();
- instock = new javax.swing.JTextField();
- showDruglist_btn = new javax.swing.JButton();
- exptxt = new javax.swing.JTextField();
- jLabel6 = new javax.swing.JLabel();
- add_btn = new javax.swing.JButton();
- explbl1 = new javax.swing.JLabel();
- explbl = new javax.swing.JLabel();
- Namecombo = new javax.swing.JComboBox();
- jScrollPane2 = new javax.swing.JScrollPane();
- tableSale = new javax.swing.JTable();
- jLabel8 = new javax.swing.JLabel();
- jLabel3 = new javax.swing.JLabel();
- jTextField5 = new javax.swing.JTextField();
- jLabel2 = new javax.swing.JLabel();
- jLabel1 = new javax.swing.JLabel();
- jTextField4 = new javax.swing.JTextField();
- setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
- setTitle("New Sale");
- setMinimumSize(new java.awt.Dimension(800, 500));
- setResizable(false);
- jPanel1.setLayout(null);
- newSaleBtn.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/bit/project/new.png"))); // NOI18N
- newSaleBtn.setToolTipText("New");
- newSaleBtn.setPreferredSize(new java.awt.Dimension(60, 40));
- newSaleBtn.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- newSaleBtnActionPerformed(evt);
- }
- });
- searchInvoiceBtn.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/bit/project/findinvoice.png"))); // NOI18N
- searchInvoiceBtn.setToolTipText("Search");
- searchInvoiceBtn.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- searchInvoiceBtnActionPerformed(evt);
- }
- });
- saleInvoiceHelpBtn.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/bit/project/help-icon.png"))); // NOI18N
- saleInvoiceHelpBtn.setToolTipText("Help");
- saleInvoicePrintBtn.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/bit/project/print-icon.png"))); // NOI18N
- saleInvoicePrintBtn.setToolTipText("Print");
- saleInvoicePreviousBtn.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/bit/project/previous.png"))); // NOI18N
- saleInvoicePreviousBtn.setToolTipText("Previous ");
- saleInvoiceNextBtn.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/bit/project/next.png"))); // NOI18N
- saleInvoiceNextBtn.setToolTipText("Next");
- saleInvoiceHomeBtn.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/bit/project/blue-home-icon.png"))); // NOI18N
- saleInvoiceHomeBtn.setToolTipText("Home");
- saleInvoiceHomeBtn.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- saleInvoiceHomeBtnActionPerformed(evt);
- }
- });
- javax.swing.GroupLayout jDesktopPane1Layout = new javax.swing.GroupLayout(jDesktopPane1);
- jDesktopPane1.setLayout(jDesktopPane1Layout);
- jDesktopPane1Layout.setHorizontalGroup(
- jDesktopPane1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(jDesktopPane1Layout.createSequentialGroup()
- .addContainerGap()
- .addComponent(saleInvoiceHomeBtn, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
- .addComponent(newSaleBtn, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
- .addComponent(searchInvoiceBtn, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
- .addComponent(saleInvoicePrintBtn, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 413, Short.MAX_VALUE)
- .addComponent(saleInvoicePreviousBtn, javax.swing.GroupLayout.PREFERRED_SIZE, 58, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
- .addComponent(saleInvoiceNextBtn, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addGap(11, 11, 11)
- .addComponent(saleInvoiceHelpBtn, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addGap(22, 22, 22))
- );
- jDesktopPane1Layout.setVerticalGroup(
- jDesktopPane1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(jDesktopPane1Layout.createSequentialGroup()
- .addContainerGap()
- .addGroup(jDesktopPane1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(searchInvoiceBtn, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
- .addComponent(saleInvoicePrintBtn, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
- .addComponent(saleInvoiceHelpBtn, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
- .addComponent(newSaleBtn, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
- .addComponent(saleInvoicePreviousBtn, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
- .addComponent(saleInvoiceNextBtn, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
- .addComponent(saleInvoiceHomeBtn, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
- .addContainerGap())
- );
- jDesktopPane1.setLayer(newSaleBtn, javax.swing.JLayeredPane.DEFAULT_LAYER);
- jDesktopPane1.setLayer(searchInvoiceBtn, javax.swing.JLayeredPane.DEFAULT_LAYER);
- jDesktopPane1.setLayer(saleInvoiceHelpBtn, javax.swing.JLayeredPane.DEFAULT_LAYER);
- jDesktopPane1.setLayer(saleInvoicePrintBtn, javax.swing.JLayeredPane.DEFAULT_LAYER);
- jDesktopPane1.setLayer(saleInvoicePreviousBtn, javax.swing.JLayeredPane.DEFAULT_LAYER);
- jDesktopPane1.setLayer(saleInvoiceNextBtn, javax.swing.JLayeredPane.DEFAULT_LAYER);
- jDesktopPane1.setLayer(saleInvoiceHomeBtn, javax.swing.JLayeredPane.DEFAULT_LAYER);
- jPanel1.add(jDesktopPane1);
- jDesktopPane1.setBounds(0, 0, 920, 60);
- jLabel4.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
- jLabel4.setText("Total Discount");
- jPanel1.add(jLabel4);
- jLabel4.setBounds(660, 490, 100, 17);
- jLabel5.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
- jLabel5.setText("Total items");
- jPanel1.add(jLabel5);
- jLabel5.setBounds(660, 460, 70, 30);
- jLabel7.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
- jLabel7.setText("Item Name");
- jPanel1.add(jLabel7);
- jLabel7.setBounds(50, 150, 80, 30);
- dayChooser.setToolTipText("Give the date");
- dayChooser.setDateFormatString("yyyy-MM-dd");
- jPanel1.add(dayChooser);
- dayChooser.setBounds(650, 120, 210, 25);
- jButton5.setText("OK");
- jPanel1.add(jButton5);
- jButton5.setBounds(760, 570, 100, 30);
- countitems_txt.setEnabled(false);
- jPanel1.add(countitems_txt);
- countitems_txt.setBounds(760, 460, 100, 25);
- jPanel1.add(jTextField1);
- jTextField1.setBounds(650, 150, 210, 25);
- IDcombo.setEditable(true);
- IDcombo.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- IDcomboActionPerformed(evt);
- }
- });
- jPanel1.add(IDcombo);
- IDcombo.setBounds(130, 120, 150, 24);
- jPanel1.add(jTextField3);
- jTextField3.setBounds(760, 520, 100, 25);
- jLabel9.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
- jLabel9.setText("Date");
- jPanel1.add(jLabel9);
- jLabel9.setBounds(570, 120, 29, 17);
- instock.setEditable(false);
- jPanel1.add(instock);
- instock.setBounds(130, 520, 190, 30);
- showDruglist_btn.setText("Show Drug List");
- showDruglist_btn.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- showDruglist_btnActionPerformed(evt);
- }
- });
- jPanel1.add(showDruglist_btn);
- showDruglist_btn.setBounds(370, 120, 130, 30);
- exptxt.setEditable(false);
- jPanel1.add(exptxt);
- exptxt.setBounds(130, 480, 190, 30);
- jLabel6.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
- jLabel6.setText("Item");
- jPanel1.add(jLabel6);
- jLabel6.setBounds(50, 120, 40, 20);
- add_btn.setText("Add");
- add_btn.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- add_btnActionPerformed(evt);
- }
- });
- jPanel1.add(add_btn);
- add_btn.setBounds(130, 190, 100, 30);
- explbl1.setFont(new java.awt.Font("Dialog", 1, 14)); // NOI18N
- explbl1.setText("In Stock");
- jPanel1.add(explbl1);
- explbl1.setBounds(50, 520, 70, 30);
- explbl.setFont(new java.awt.Font("Dialog", 1, 14)); // NOI18N
- explbl.setText("exp date");
- jPanel1.add(explbl);
- explbl.setBounds(50, 480, 70, 30);
- Namecombo.setEditable(true);
- Namecombo.setFont(new java.awt.Font("Dialog", 1, 12)); // NOI18N
- Namecombo.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- NamecomboActionPerformed(evt);
- }
- });
- jPanel1.add(Namecombo);
- Namecombo.setBounds(130, 160, 370, 25);
- tableSale.setModel(new javax.swing.table.DefaultTableModel(
- new Object [][] {
- },
- new String [] {
- "ItemID", "Item Name", "Cost", "Qty", "Discount", "Total"
- }
- ) {
- Class[] types = new Class [] {
- java.lang.String.class, java.lang.String.class, java.lang.Double.class, java.lang.Double.class, java.lang.Double.class, java.lang.Double.class
- };
- boolean[] canEdit = new boolean [] {
- false, false, true, true, true, true
- };
- public Class getColumnClass(int columnIndex) {
- return types [columnIndex];
- }
- public boolean isCellEditable(int rowIndex, int columnIndex) {
- return canEdit [columnIndex];
- }
- });
- tableSale.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
- tableSale.getTableHeader().setReorderingAllowed(false);
- tableSale.addKeyListener(new java.awt.event.KeyAdapter() {
- public void keyPressed(java.awt.event.KeyEvent evt) {
- tableSaleKeyPressed(evt);
- }
- });
- jScrollPane2.setViewportView(tableSale);
- jPanel1.add(jScrollPane2);
- jScrollPane2.setBounds(50, 230, 810, 210);
- jLabel8.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
- jLabel8.setText("Total Price");
- jPanel1.add(jLabel8);
- jLabel8.setBounds(660, 520, 80, 17);
- jLabel3.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
- jLabel3.setText("Invoice No");
- jPanel1.add(jLabel3);
- jLabel3.setBounds(570, 150, 70, 20);
- jPanel1.add(jTextField5);
- jTextField5.setBounds(760, 490, 100, 25);
- jLabel2.setFont(new java.awt.Font("Calibri", 1, 24)); // NOI18N
- jLabel2.setText("Sales Invoice");
- jPanel1.add(jLabel2);
- jLabel2.setBounds(410, 60, 150, 50);
- jLabel1.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
- jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/bit/project/plain_old.jpeg"))); // NOI18N
- jPanel1.add(jLabel1);
- jLabel1.setBounds(0, 0, 910, 620);
- jPanel1.add(jTextField4);
- jTextField4.setBounds(650, 400, 80, 20);
- javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
- getContentPane().setLayout(layout);
- layout.setHorizontalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 910, Short.MAX_VALUE)
- );
- layout.setVerticalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 613, Short.MAX_VALUE)
- );
- pack();
- setLocationRelativeTo(null);
- }// </editor-fold>
- private void saleInvoiceHomeBtnActionPerformed(java.awt.event.ActionEvent evt) {
- this.setVisible(false);
- }
- private void searchInvoiceBtnActionPerformed(java.awt.event.ActionEvent evt) {
- Findinvoice fiobj = new Findinvoice();
- fiobj.setVisible(true);
- }
- private void NamecomboActionPerformed(java.awt.event.ActionEvent evt) {
- String drugname = (String) Namecombo.getSelectedItem();
- try{
- String name = "SELECT * FROM druginfo WHERE ItemName LIKE '"+drugname+"%'";
- PreparedStatement pstmt = conn.prepareStatement(name);
- ResultSet rs = pstmt.executeQuery();
- while (rs.next()){
- IDcombo.setSelectedItem(rs.getString("ItemID"));
- }
- }catch(Exception e){
- JOptionPane.showMessageDialog(null,"error "+ e);
- }
- }
- private void IDcomboActionPerformed(java.awt.event.ActionEvent evt) {
- String drugid = (String) IDcombo.getSelectedItem();
- try{
- String name = "SELECT * FROM druginfo WHERE ItemID LIKE '"+drugid+"%'";
- PreparedStatement pstmt = conn.prepareStatement(name);
- rs = pstmt.executeQuery();
- while (rs.next()){
- Namecombo.setSelectedItem(rs.getString("ItemName"));
- }
- }catch(Exception e){
- JOptionPane.showMessageDialog(null,"error "+ e);
- }
- try{
- String exp = "SELECT ExpDate,InStock FROM druginfo WHERE ItemID LIKE '"+drugid+"%'";
- PreparedStatement pstmt = conn.prepareStatement(exp);
- ResultSet rs2 = pstmt.executeQuery();
- while (rs2.next()){
- String date = rs2.getString("ExpDate");
- String stock = rs2.getString("InStock");
- exptxt.setText(date);
- instock.setText(stock);
- }
- }catch(Exception e){
- JOptionPane.showMessageDialog(null,"error "+ e);
- }
- }
- private void showDruglist_btnActionPerformed(java.awt.event.ActionEvent evt) {
- try {
- NewSaleDruglist nsd = new NewSaleDruglist();
- nsd.setVisible(true);
- } catch (SQLException ex) {
- Logger.getLogger(Newsale.class.getName()).log(Level.SEVERE, null, ex);
- }
- }
- private void add_btnActionPerformed(java.awt.event.ActionEvent evt) {
- String temp = (String) IDcombo.getSelectedItem();
- String sql = "select ItemID,ItemName,CostPrice from druginfo where ItemID=?";
- try {
- pst=conn.prepareStatement(sql);
- pst.setString(1, temp);
- rs=pst.executeQuery();
- addDataToTable(tableSale,DbUtils.resultSetToTableModel(rs));
- tableSale.getModel().addTableModelListener( new TableModelListener() {
- @Override
- public void tableChanged(TableModelEvent e) {
- int row = e.getFirstRow();
- int column = e.getColumn();
- if (column == 6 ) {
- TableModel model = tableSale.getModel();
- double cost = ( model.getValueAt(row, 3)==null)?0:((double)model.getValueAt(row, 3));
- double quantity = ( model.getValueAt(row, 4)==null)?0:((double) model.getValueAt(row, 4));
- double discount = ( model.getValueAt(row, 5)==null)?0:((double) model.getValueAt(row, 5));
- double total = new Double ((quantity * cost)-discount);
- System.out.println("pppppppp"+total);
- model.setValueAt(total, row, 6);
- }
- }
- });
- IDcombo.setSelectedItem(null);
- Namecombo.setSelectedItem(null);
- exptxt.setText(null);
- instock.setText(null);
- } catch (Exception ex) {
- JOptionPane.showMessageDialog(null, "errorrr"+ex);
- }
- // int rows = tableSale.getRowCount();
- // countitems_txt.settext(Integer.parseInt();
- }
- private void newSaleBtnActionPerformed(java.awt.event.ActionEvent evt) {
- int clear = JOptionPane.showConfirmDialog(null, "Do you really want to clear the data ?","Clear Data",JOptionPane.YES_NO_OPTION);
- if((clear)==0){
- addDataToTable(tableSale,DbUtils.resultSetToTableModel(null));
- }
- }
- private void tableSaleKeyPressed(java.awt.event.KeyEvent evt) {
- tableSale.getModel().addTableModelListener( new TableModelListener() {
- @Override
- public void tableChanged(TableModelEvent evt) {
- if (evt.getType() == TableModelEvent.UPDATE) {
- int row = evt.getFirstRow();
- int column = evt.getColumn();
- if (column == 6 ) {
- TableModel model = tableSale.getModel();
- double cost = ( model.getValueAt(row, 3)==null)?0:((Double)model.getValueAt(row, 3));
- double quantity = ( model.getValueAt(row, 4)==null)?0:((Double) model.getValueAt(row, 4));
- double discount = ( model.getValueAt(row, 5)==null)?0:((Double) model.getValueAt(row, 5));
- double total = new Double ((quantity * cost)-discount);
- // System.out.println("pppppppp"+total);
- model.setValueAt(total, row, 6);
- }
- }
- }
- });
- }
- /**
- * @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(Newsale.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (InstantiationException ex) {
- java.util.logging.Logger.getLogger(Newsale.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (IllegalAccessException ex) {
- java.util.logging.Logger.getLogger(Newsale.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (javax.swing.UnsupportedLookAndFeelException ex) {
- java.util.logging.Logger.getLogger(Newsale.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- }
- //</editor-fold>
- //</editor-fold>
- /* Create and display the form */
- java.awt.EventQueue.invokeLater(new Runnable() {
- public void run() {
- try {
- new Newsale().setVisible(true);
- } catch (SQLException ex) {
- Logger.getLogger(Newsale.class.getName()).log(Level.SEVERE, null, ex);
- }
- }
- });
- }
- // Variables declaration - do not modify
- private javax.swing.JComboBox IDcombo;
- private javax.swing.JComboBox Namecombo;
- private javax.swing.JButton add_btn;
- private javax.swing.JTextField countitems_txt;
- private com.toedter.calendar.JDateChooser dayChooser;
- private javax.swing.JLabel explbl;
- private javax.swing.JLabel explbl1;
- private javax.swing.JTextField exptxt;
- private javax.swing.JTextField instock;
- private javax.swing.JButton jButton5;
- private javax.swing.JDesktopPane jDesktopPane1;
- 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.JLabel jLabel9;
- private javax.swing.JPanel jPanel1;
- private javax.swing.JScrollPane jScrollPane2;
- private javax.swing.JTextField jTextField1;
- private javax.swing.JTextField jTextField3;
- private javax.swing.JTextField jTextField4;
- private javax.swing.JTextField jTextField5;
- private javax.swing.JButton newSaleBtn;
- private javax.swing.JButton saleInvoiceHelpBtn;
- private javax.swing.JButton saleInvoiceHomeBtn;
- private javax.swing.JButton saleInvoiceNextBtn;
- private javax.swing.JButton saleInvoicePreviousBtn;
- private javax.swing.JButton saleInvoicePrintBtn;
- private javax.swing.JButton searchInvoiceBtn;
- private javax.swing.JButton showDruglist_btn;
- private javax.swing.JTable tableSale;
- // End of variables declaration
- }
Advertisement
Add Comment
Please, Sign In to add comment