Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package mainpackage;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.PreparedStatement;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.sql.Statement;
- import java.util.ArrayList;
- import java.util.logging.Level;
- import java.util.logging.Logger;
- import javax.swing.JOptionPane;
- import javax.swing.table.DefaultTableModel;
- /*
- * 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.
- */
- /**
- *
- * @author marvi
- */
- public class StockIn extends javax.swing.JFrame {
- /**
- * Creates new form StockIn
- */
- public StockIn() {
- initComponents();
- getConnection();
- Show_Products_In_Jtable();
- }
- /**
- * 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();
- jPanel2 = new javax.swing.JPanel();
- txt_StockId = new javax.swing.JTextField();
- txt_BrandName = new javax.swing.JTextField();
- txt_GenericName = new javax.swing.JTextField();
- txt_Manufacturer = new javax.swing.JTextField();
- txt_Dosage = new javax.swing.JTextField();
- 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();
- txt_StockIn = new javax.swing.JTextField();
- txt_StockDate = new javax.swing.JTextField();
- jScrollPane1 = new javax.swing.JScrollPane();
- tbl_Stocks = new javax.swing.JTable();
- jPanel3 = new javax.swing.JPanel();
- btn_Add = new javax.swing.JButton();
- btn_Update = new javax.swing.JButton();
- btn_Delete = new javax.swing.JButton();
- btn_MainMenu = new javax.swing.JButton();
- setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
- jPanel1.setBackground(new java.awt.Color(0, 255, 255));
- txt_StockId.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- txt_StockIdActionPerformed(evt);
- }
- });
- txt_BrandName.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- txt_BrandNameActionPerformed(evt);
- }
- });
- txt_GenericName.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- txt_GenericNameActionPerformed(evt);
- }
- });
- txt_Manufacturer.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- txt_ManufacturerActionPerformed(evt);
- }
- });
- txt_Dosage.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- txt_DosageActionPerformed(evt);
- }
- });
- jLabel1.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N
- jLabel1.setText("Generic Name");
- jLabel2.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N
- jLabel2.setText("ID");
- jLabel3.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N
- jLabel3.setText("Brand Name");
- jLabel4.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N
- jLabel4.setText("Manufacturer");
- jLabel5.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N
- jLabel5.setText("Dosage");
- jLabel6.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N
- jLabel6.setText("Stock Date");
- jLabel7.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N
- jLabel7.setText("Stock In");
- txt_StockIn.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- txt_StockInActionPerformed(evt);
- }
- });
- txt_StockDate.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- txt_StockDateActionPerformed(evt);
- }
- });
- javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
- jPanel2.setLayout(jPanel2Layout);
- jPanel2Layout.setHorizontalGroup(
- jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
- .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(jPanel2Layout.createSequentialGroup()
- .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(jPanel2Layout.createSequentialGroup()
- .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
- .addComponent(jLabel2))
- .addGroup(jPanel2Layout.createSequentialGroup()
- .addGap(18, 18, 18)
- .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
- .addComponent(jLabel4)
- .addComponent(jLabel5)
- .addComponent(jLabel7)
- .addComponent(jLabel3)
- .addComponent(jLabel6))
- .addGap(0, 0, Short.MAX_VALUE)))
- .addGap(18, 18, 18))
- .addGroup(jPanel2Layout.createSequentialGroup()
- .addContainerGap()
- .addComponent(jLabel1)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
- .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(txt_Dosage, javax.swing.GroupLayout.PREFERRED_SIZE, 124, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addComponent(txt_Manufacturer, javax.swing.GroupLayout.PREFERRED_SIZE, 124, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addComponent(txt_GenericName, javax.swing.GroupLayout.PREFERRED_SIZE, 124, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addComponent(txt_BrandName, javax.swing.GroupLayout.PREFERRED_SIZE, 124, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addComponent(txt_StockId, javax.swing.GroupLayout.PREFERRED_SIZE, 124, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addComponent(txt_StockIn, javax.swing.GroupLayout.PREFERRED_SIZE, 124, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addComponent(txt_StockDate, javax.swing.GroupLayout.PREFERRED_SIZE, 124, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addGap(22, 22, 22))
- );
- jPanel2Layout.setVerticalGroup(
- jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(jPanel2Layout.createSequentialGroup()
- .addGap(24, 24, 24)
- .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
- .addGroup(jPanel2Layout.createSequentialGroup()
- .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
- .addComponent(txt_StockId, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addComponent(jLabel2))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
- .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(txt_BrandName, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addComponent(jLabel3))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
- .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
- .addComponent(txt_GenericName, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addComponent(jLabel1))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(txt_Manufacturer, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addComponent(jLabel4, javax.swing.GroupLayout.Alignment.TRAILING))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
- .addComponent(txt_Dosage, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addComponent(jLabel5))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(jLabel7))
- .addComponent(txt_StockIn, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
- .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(jLabel6)
- .addComponent(txt_StockDate, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
- );
- tbl_Stocks.setModel(new javax.swing.table.DefaultTableModel(
- new Object [][] {
- },
- new String [] {
- "Stock ID", "Brand Name", "Generic Name", "Manufacturer", "Dosage", "Stock In", "Stock Date"
- }
- ));
- jScrollPane1.setViewportView(tbl_Stocks);
- btn_Add.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
- btn_Add.setText("ADD");
- btn_Add.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- btn_AddActionPerformed(evt);
- }
- });
- btn_Update.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
- btn_Update.setText("UPDATE");
- btn_Update.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- btn_UpdateActionPerformed(evt);
- }
- });
- btn_Delete.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
- btn_Delete.setText("DELETE");
- btn_Delete.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- btn_DeleteActionPerformed(evt);
- }
- });
- btn_MainMenu.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
- btn_MainMenu.setText("Main Menu");
- btn_MainMenu.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- btn_MainMenuActionPerformed(evt);
- }
- });
- javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
- jPanel3.setLayout(jPanel3Layout);
- jPanel3Layout.setHorizontalGroup(
- jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
- .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
- .addComponent(btn_Add)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(btn_Update)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
- .addComponent(btn_Delete)
- .addGap(22, 22, 22))
- .addGroup(jPanel3Layout.createSequentialGroup()
- .addGap(91, 91, 91)
- .addComponent(btn_MainMenu)
- .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
- );
- jPanel3Layout.setVerticalGroup(
- jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(jPanel3Layout.createSequentialGroup()
- .addGap(26, 26, 26)
- .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(btn_Add)
- .addComponent(btn_Update)
- .addComponent(btn_Delete))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(btn_MainMenu)
- .addContainerGap(16, Short.MAX_VALUE))
- );
- javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
- jPanel1.setLayout(jPanel1Layout);
- jPanel1Layout.setHorizontalGroup(
- jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(jPanel1Layout.createSequentialGroup()
- .addContainerGap()
- .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
- .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
- .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
- .addGap(18, 18, 18)
- .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 678, Short.MAX_VALUE)
- .addContainerGap())
- );
- jPanel1Layout.setVerticalGroup(
- jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
- .addContainerGap()
- .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 504, Short.MAX_VALUE)
- .addGroup(jPanel1Layout.createSequentialGroup()
- .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
- .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
- .addContainerGap())
- );
- 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.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
- );
- layout.setVerticalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addGap(0, 0, Short.MAX_VALUE))
- );
- pack();
- }// </editor-fold>
- ///////////////////////////////
- public java.sql.Connection getConnection() {
- java.sql.Connection con = null;
- try {
- con = (java.sql.Connection) DriverManager.getConnection("jdbc:mysql://localhost:3306/medicaldatabase", "root", "password");
- return con; //return to con
- } catch (SQLException ex) {
- Logger.getLogger(
- StockIn.class.getName()).log(Level.SEVERE, null, ex);
- return null;
- }
- }
- public boolean checkInput() {
- if (txt_BrandName == null
- || txt_GenericName == null
- || txt_Manufacturer == null
- || txt_Dosage == null
- || txt_StockIn == null
- || txt_StockDate == null) {
- return false;
- } else {
- try {
- return true;
- } catch (Exception ex) {
- return false;
- }
- }
- }
- /////////////////////////////////
- private void txt_StockIdActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- }
- private void txt_BrandNameActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- }
- private void txt_GenericNameActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- }
- private void txt_ManufacturerActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- }
- private void txt_DosageActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- }
- private void txt_StockInActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- }
- private void txt_StockDateActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- }
- private void btn_UpdateActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- if (checkInput() && txt_StockId.getText() != null) {
- String UpdateQuery = null;
- PreparedStatement ps = null;
- Connection con = getConnection();
- try {
- UpdateQuery = "UPDATE stocktable SET BrandName = ?,GenericName = ?,Manufacturer = ?,Dosage = ?,StockIn = ?,StockDate = ?" + "WHERE Stock_ID = ?";
- ps = con.prepareStatement(UpdateQuery);
- ps.setString(1, txt_BrandName.getText());
- ps.setString(2, txt_GenericName.getText());
- ps.setString(3, txt_Manufacturer.getText());
- ps.setInt(4, Integer.parseInt(txt_Dosage.getText()));
- ps.setInt(5, Integer.parseInt(txt_StockIn.getText()));
- ps.setString(6, txt_StockDate.getText());
- ps.executeUpdate();
- Show_Products_In_Jtable();
- JOptionPane.showMessageDialog(null, "Data is Updated");
- } catch (SQLException ex) {
- Logger.getLogger(StockIn.class.getName()).log(Level.SEVERE, null, ex);
- }
- } else {
- JOptionPane.showMessageDialog(null, "One or More FIelds are Empty or Wrong");
- }
- }
- private void btn_DeleteActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- if (!txt_StockId.getText().equals("")) {
- try {
- Connection con = getConnection();
- PreparedStatement ps = con.prepareStatement("Delete FROM stocktable WHERE Stock_ID = ?");
- int id = Integer.parseInt(txt_StockId.getText());
- ps.setInt(1, id);
- ps.executeUpdate();
- Show_Products_In_Jtable();
- JOptionPane.showMessageDialog(null, "Product is Deleted");
- } catch (SQLException ex) {
- Logger.getLogger(StockIn.class.getName()).log(Level.SEVERE, null, ex);
- }
- } else {
- JOptionPane.showMessageDialog(null, "Product is NOT Deleted");
- }
- }
- private void btn_MainMenuActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- Buttons menu = new Buttons();
- menu.mtdMainMenu();
- this.dispose();
- }
- private void btn_AddActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- if (checkInput() != false) {
- try {
- Connection con = getConnection();
- PreparedStatement ps = con.prepareStatement("INSERT INTO stocktable(BrandName,GenericName,Manufacturer,Dosage,StockIn,StockDate)" + "values(?,?,?,?,?,?)");
- ps.setString(1, txt_BrandName.getText());
- ps.setString(2, txt_GenericName.getText());
- ps.setString(3, txt_Manufacturer.getText());
- ps.setInt(4, Integer.parseInt(txt_Dosage.getText()));
- ps.setInt(5, Integer.parseInt(txt_StockIn.getText()));
- ps.setString(6, txt_StockDate.getText());
- ps.executeUpdate();
- Show_Products_In_Jtable();
- JOptionPane.showMessageDialog(null, "Data Added");
- } catch (Exception ex) {
- JOptionPane.showMessageDialog(null, ex.getMessage());
- }
- } else {
- JOptionPane.showMessageDialog(null, "One or More Field Are Undefined");
- }
- //for checking purpose only
- System.out.println("Brand Name => " + txt_BrandName.getText());
- System.out.println("Generic => " + txt_GenericName.getText());
- System.out.println("Manufacturer => " + txt_Manufacturer.getText());
- System.out.println("Dosage => " + txt_Dosage.getText());
- System.out.println("StockIn =>" + txt_StockIn.getText());
- System.out.println("StockDate =>" + txt_StockDate.getText());
- }
- /////////////////////////////////////
- //Display Data in Jtable (1)
- public ArrayList<Stocks> getStocksList() {
- ArrayList<Stocks> stockList = new ArrayList<Stocks>();
- Connection con = getConnection();
- String query = "SELECT Stock_ID,Brandname,GenericName,Manufacturer,Dosage,StockIn,StockDate FROM stocktable";
- Statement st;
- ResultSet rs;
- try {
- st = con.createStatement();
- rs = st.executeQuery(query);
- Stocks stocks;
- /////
- while (rs.next()) {
- stocks = new Stocks(rs.getInt("Stock_Id"), rs.getString("BrandName"), rs.getString("GenericName"), rs.getString("Manufacturer"), rs.getInt("Dosage"), rs.getInt("StockIn"), rs.getString("StockDate"));
- stockList.add(stocks);
- }
- } catch (SQLException ex) {
- Logger.getLogger(StockIn.class.getName()).log(Level.SEVERE, null, ex);
- }
- return stockList;
- //populate Jtable
- }
- public void Show_Products_In_Jtable() {
- ArrayList<Stocks> list = getStocksList();
- DefaultTableModel model = (DefaultTableModel) tbl_Stocks.getModel();
- model.setRowCount(0);
- Object[] row = new Object[6];
- for (int i = 0; i < list.size(); i++) {
- row[0] = list.get(i).getStockId();
- row[1] = list.get(i).getBrandName();
- row[2] = list.get(i).getGenericName();
- row[3] = list.get(i).getManufacturer();
- row[4] = list.get(i).getDosage();
- row[5] = list.get(i).getStockIn();
- row[6] = list.get(i).getStockDate();
- model.addRow(row);
- }
- }
- public void ShowItem(int index) {
- txt_StockId.setText(Integer.toString(getStocksList().get(index).getStockId()));
- txt_BrandName.setText(getStocksList().get(index).getBrandName());
- txt_GenericName.setText(getStocksList().get(index).getGenericName());
- txt_Manufacturer.setText(getStocksList().get(index).getManufacturer());
- txt_Dosage.setText(Integer.toString(getStocksList().get(index).getDosage()));
- txt_StockIn.setText(Integer.toString(getStocksList().get(index).getStockIn()));
- txt_StockDate.setText(getStocksList().get(index).getStockDate());
- }
- //////////////////////////////////////
- /**
- * @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(StockIn.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (InstantiationException ex) {
- java.util.logging.Logger.getLogger(StockIn.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (IllegalAccessException ex) {
- java.util.logging.Logger.getLogger(StockIn.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (javax.swing.UnsupportedLookAndFeelException ex) {
- java.util.logging.Logger.getLogger(StockIn.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 StockIn().setVisible(true);
- }
- });
- }
- // Variables declaration - do not modify
- private javax.swing.JButton btn_Add;
- private javax.swing.JButton btn_Delete;
- private javax.swing.JButton btn_MainMenu;
- private javax.swing.JButton btn_Update;
- 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.JPanel jPanel1;
- private javax.swing.JPanel jPanel2;
- private javax.swing.JPanel jPanel3;
- private javax.swing.JScrollPane jScrollPane1;
- private javax.swing.JTable tbl_Stocks;
- private javax.swing.JTextField txt_BrandName;
- private javax.swing.JTextField txt_Dosage;
- private javax.swing.JTextField txt_GenericName;
- private javax.swing.JTextField txt_Manufacturer;
- private javax.swing.JTextField txt_StockDate;
- private javax.swing.JTextField txt_StockId;
- private javax.swing.JTextField txt_StockIn;
- // End of variables declaration
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement