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.dvd.ui; import java.awt.Color; import java.io.BufferedReader; import java.io.InputStreamReader; import java.net.HttpURLConnection; import java.net.URL; import java.util.ArrayList; import java.util.List; import java.util.logging.Level; import java.util.logging.Logger; import javax.swing.table.DefaultTableModel; import org.json.JSONObject; import com.dvd.domain.Dvd; import com.dvd.domain.DvdCopy; import com.dvd.domain.User; import com.dvd.hibernate.doa.BookingDao; import com.dvd.hibernate.doa.DVDCopyDao; import com.dvd.hibernate.repo.BookingRepository; import com.dvd.persistance.DVDRepository; import com.dvd.prop.PropReader; public class SearchDVD extends javax.swing.JFrame { private List<Dvd> searchDVDList; private List<DvdCopy> searchCopyDVDList; private boolean isServiceOn = false; /** * Creates new form AddProduct */ public SearchDVD(User user) { initComponents(); PropReader properties = new PropReader(); isServiceOn = properties.getConnectionProp(); System.out.println(isServiceOn); searchTable.setVisible(false); copyTable.setVisible(false); errorTag.setVisible(false); searchDVDList = new ArrayList<Dvd>(); searchCopyDVDList = new ArrayList<DvdCopy>(); DVDRepository dVDRepository = new DVDRepository(); try { if (isServiceOn) { searchDVDList = dVDRepository.getDVDList(); } else { com.dvd.hibernate.repo.DVDRepository repository = new com.dvd.hibernate.repo.DVDRepository(); List<Dvd> s = repository.getDVDList(); searchDVDList = s; } } catch (Exception ex) { Logger.getLogger(SearchDVD.class.getName()).log(Level.SEVERE, null, ex); } if (user.getUserType().equals("emp")) { bookinPanel.setVisible(true); } else if (user.getUserType().equals("mem")) { bookinPanel.setVisible(false); } else { dispose(); } } /** * 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() { label1 = new java.awt.Label(); label2 = new java.awt.Label(); jLabel6 = new javax.swing.JLabel(); keyword = new javax.swing.JTextField(); jLabel7 = new javax.swing.JLabel(); search = new javax.swing.JButton(); jScrollPane1 = new javax.swing.JScrollPane(); searchTable = new javax.swing.JTable(); definition = new javax.swing.JComboBox(); rating = new javax.swing.JComboBox(); jLabel8 = new javax.swing.JLabel(); jLabel9 = new javax.swing.JLabel(); jLabel2 = new javax.swing.JLabel(); errorTag = new javax.swing.JLabel(); year = new javax.swing.JComboBox(); jPanel1 = new javax.swing.JPanel(); jLabel1 = new javax.swing.JLabel(); dvdCodeTxt = new javax.swing.JTextField(); getDvdBtn = new javax.swing.JButton(); jPanel2 = new javax.swing.JPanel(); jLabel3 = new javax.swing.JLabel(); jLabelDVDCode = new javax.swing.JLabel(); jLabel5 = new javax.swing.JLabel(); jLabelDVDTitle = new javax.swing.JLabel(); jLabel11 = new javax.swing.JLabel(); jLabelYear = new javax.swing.JLabel(); jLabel13 = new javax.swing.JLabel(); jLabelImdb = new javax.swing.JLabel(); jLabel15 = new javax.swing.JLabel(); jLabelActors = new javax.swing.JLabel(); jLabel17 = new javax.swing.JLabel(); jLabel18 = new javax.swing.JLabel(); jLabel19 = new javax.swing.JLabel(); jLabelCopies = new javax.swing.JLabel(); jScrollPane2 = new javax.swing.JScrollPane(); copyTable = new javax.swing.JTable(); jLabel16 = new javax.swing.JLabel(); jLabelFormat = new javax.swing.JLabel(); bookinPanel = new javax.swing.JPanel(); jLabel21 = new javax.swing.JLabel(); jLabel22 = new javax.swing.JLabel(); jLabelDVDCode1 = new javax.swing.JLabel(); jLabel24 = new javax.swing.JLabel(); jLabelDVDTitle1 = new javax.swing.JLabel(); jLabel26 = new javax.swing.JLabel(); copyNumberTxt = new javax.swing.JTextField(); jLabel27 = new javax.swing.JLabel(); userIDTxt = new javax.swing.JTextField(); bookDVD = new javax.swing.JButton(); jLabel28 = new javax.swing.JLabel(); resultLabel = new javax.swing.JLabel(); errorLabelReserve = new javax.swing.JLabel(); setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); setBackground(new java.awt.Color(23, 193, 111)); setPreferredSize(new java.awt.Dimension(938, 930)); setResizable(false); label1.setFont(new java.awt.Font("Dialog", 0, 14)); // NOI18N label1.setName("lblPrice"); // NOI18N label2.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR)); label2.setFont(new java.awt.Font("Ubuntu", 1, 36)); // NOI18N label2.setForeground(new java.awt.Color(23, 193, 111)); label2.setText("Search DVD"); jLabel6.setFont(new java.awt.Font("Ubuntu", 0, 18)); // NOI18N jLabel6.setText("Enter Keyword"); jLabel7.setFont(new java.awt.Font("Ubuntu", 0, 18)); // NOI18N jLabel7.setText("Definition"); search.setText("Search DVD"); search.setToolTipText("Search for DVD"); search.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { searchActionPerformed(evt); } }); searchTable.setBorder(new javax.swing.border.MatteBorder(null)); searchTable.setModel(new javax.swing.table.DefaultTableModel( new Object[][] { { null, null, null, null, null, null, null } }, new String[] { "DVD Code", "DVD Title", "Year", "Rating", "Definition", "Main Actors", "Book" }) { Class[] types = new Class[] { java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.Object.class, java.lang.Object.class }; public Class getColumnClass(int columnIndex) { return types[columnIndex]; } }); searchTable.setEditingColumn(0); searchTable.setEditingRow(0); searchTable.setEnabled(false); jScrollPane1.setViewportView(searchTable); definition.setFont(new java.awt.Font("Arial", 1, 14)); // NOI18N definition .setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Any", "1080i", "720i", "normal" })); definition.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { definitionActionPerformed(evt); } }); rating.setFont(new java.awt.Font("Arial", 1, 14)); // NOI18N rating.setModel(new javax.swing.DefaultComboBoxModel( new String[] { "Any", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10" })); rating.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { ratingActionPerformed(evt); } }); jLabel8.setFont(new java.awt.Font("Ubuntu", 0, 18)); // NOI18N jLabel8.setText("Year"); jLabel9.setFont(new java.awt.Font("Ubuntu", 0, 18)); // NOI18N jLabel9.setText("Rating"); jLabel2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/pic6.jpg"))); // NOI18N jLabel2.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0), 2)); errorTag.setFont(new java.awt.Font("Ubuntu", 1, 18)); // NOI18N errorTag.setForeground(new java.awt.Color(185, 13, 13)); errorTag.setText("No result found"); year.setFont(new java.awt.Font("Arial", 1, 14)); // NOI18N year.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Any", "2015", "2014", "2013", "2012", "2011", "2010", "2009", "2008", "2007", "2006", "2005", "2004", "2003", "2002", "2001", "2000", "1999", "1998", "1997", "1996", "1995", "1994", "1993", "1992", "1991", "1990" })); year.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { yearActionPerformed(evt); } }); jPanel1.setBackground(new java.awt.Color(23, 193, 111)); jPanel1.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0), 2)); jPanel1.setAutoscrolls(true); jLabel1.setForeground(new java.awt.Color(1, 1, 1)); jLabel1.setText("Enter DVD Code"); getDvdBtn.setForeground(new java.awt.Color(1, 1, 1)); getDvdBtn.setText("Get DVD"); getDvdBtn.setActionCommand("Get Location"); getDvdBtn.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { getDvdBtnActionPerformed(evt); } }); jPanel2.setBackground(new java.awt.Color(246, 235, 224)); jPanel2.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0), 2)); jPanel2.setForeground(new java.awt.Color(1, 1, 1)); jLabel3.setText("DVD Code"); jLabel5.setText("Title"); jLabel11.setText("Year"); jLabel13.setText("IMDB Rating"); jLabel15.setText("Main Actors"); jLabel17.setFont(new java.awt.Font("Ubuntu", 1, 18)); // NOI18N jLabel17.setForeground(new java.awt.Color(1, 1, 1)); jLabel17.setText("DVD Details"); jLabel18.setFont(new java.awt.Font("Ubuntu", 1, 18)); // NOI18N jLabel18.setForeground(new java.awt.Color(1, 1, 1)); jLabel18.setText("DVD Location"); jLabel19.setText("Number of copies"); copyTable.setForeground(new java.awt.Color(1, 1, 1)); copyTable.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[] { "Copy Number", "Isle Number", "Shelf Number", "isAvailable" }) { Class[] types = new Class[] { java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class }; public Class getColumnClass(int columnIndex) { return types[columnIndex]; } }); jScrollPane2.setViewportView(copyTable); jLabel16.setText("Definition Format"); javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2); jPanel2.setLayout(jPanel2Layout); jPanel2Layout.setHorizontalGroup(jPanel2Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel2Layout.createSequentialGroup().addContainerGap().addComponent(jLabel17).addGap(0, 0, Short.MAX_VALUE)) .addGroup(jPanel2Layout.createSequentialGroup().addContainerGap() .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel2Layout.createSequentialGroup().addGroup(jPanel2Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jLabel18) .addGroup(jPanel2Layout.createSequentialGroup().addComponent(jLabel19) .addGap(29, 29, 29).addComponent(jLabelCopies, javax.swing.GroupLayout.PREFERRED_SIZE, 36, javax.swing.GroupLayout.PREFERRED_SIZE))) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 338, Short.MAX_VALUE)) .addComponent(jScrollPane2)) .addContainerGap()) .addGroup(jPanel2Layout.createSequentialGroup().addGap(62, 62, 62) .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jLabel3).addComponent(jLabel5).addComponent(jLabel11) .addComponent(jLabel13).addComponent(jLabel15).addComponent(jLabel16)) .addGap(30, 30, 30) .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jLabelFormat).addComponent(jLabelActors).addComponent(jLabelImdb) .addComponent(jLabelYear).addComponent(jLabelDVDTitle).addComponent(jLabelDVDCode)) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))); jPanel2Layout.setVerticalGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel2Layout.createSequentialGroup().addGap(6, 6, 6).addComponent(jLabel17) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jLabelDVDCode).addComponent(jLabel3)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jLabelDVDTitle).addComponent(jLabel5)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jLabelYear).addComponent(jLabel11)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jLabelImdb) .addComponent(jLabel13, javax.swing.GroupLayout.Alignment.TRAILING)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jLabelActors).addComponent(jLabel15)) .addGap(7, 7, 7) .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel16).addComponent(jLabelFormat)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addComponent(jLabel18) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jLabelCopies) .addComponent(jLabel19, javax.swing.GroupLayout.Alignment.TRAILING)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 102, javax.swing.GroupLayout.PREFERRED_SIZE) .addContainerGap(108, Short.MAX_VALUE))); bookinPanel.setBackground(new java.awt.Color(246, 235, 224)); bookinPanel.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0), 2)); jLabel21.setFont(new java.awt.Font("Ubuntu", 1, 18)); // NOI18N jLabel21.setForeground(new java.awt.Color(1, 1, 1)); jLabel21.setText("Book DVD"); jLabel22.setText("DVD Code"); jLabel24.setText("Title"); jLabel26.setText("Copy Number"); copyNumberTxt.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { copyNumberTxtActionPerformed(evt); } }); jLabel27.setText("Member ID"); userIDTxt.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { userIDTxtActionPerformed(evt); } }); bookDVD.setText("Book DVD"); bookDVD.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { bookDVDActionPerformed(evt); } }); jLabel28.setFont(new java.awt.Font("Ubuntu", 1, 18)); // NOI18N jLabel28.setForeground(new java.awt.Color(1, 1, 1)); jLabel28.setText("Booking Result"); resultLabel.setFont(new java.awt.Font("Ubuntu", 1, 16)); // NOI18N resultLabel.setForeground(new java.awt.Color(38, 86, 39)); javax.swing.GroupLayout bookinPanelLayout = new javax.swing.GroupLayout(bookinPanel); bookinPanel.setLayout(bookinPanelLayout); bookinPanelLayout.setHorizontalGroup(bookinPanelLayout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(bookinPanelLayout.createSequentialGroup().addGap(98, 98, 98).addComponent(bookDVD) .addGap(0, 0, Short.MAX_VALUE)) .addGroup(bookinPanelLayout.createSequentialGroup().addGroup(bookinPanelLayout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(bookinPanelLayout.createSequentialGroup().addContainerGap() .addGroup(bookinPanelLayout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(bookinPanelLayout.createSequentialGroup() .addGroup(bookinPanelLayout .createParallelGroup( javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jLabel24).addComponent(jLabel21) .addComponent(jLabel22)) .addGap(26, 26, 26) .addGroup(bookinPanelLayout .createParallelGroup( javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jLabelDVDTitle1) .addComponent(jLabelDVDCode1))) .addGroup(bookinPanelLayout.createSequentialGroup() .addGroup(bookinPanelLayout .createParallelGroup( javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jLabel26).addComponent(jLabel27)) .addGap(18, 18, 18) .addGroup(bookinPanelLayout .createParallelGroup( javax.swing.GroupLayout.Alignment.LEADING, false) .addComponent(userIDTxt, javax.swing.GroupLayout.DEFAULT_SIZE, 169, Short.MAX_VALUE) .addComponent(copyNumberTxt))) .addComponent(jLabel28))) .addGroup(bookinPanelLayout.createSequentialGroup().addGap(85, 85, 85) .addComponent(resultLabel))) .addContainerGap(24, Short.MAX_VALUE))); bookinPanelLayout.setVerticalGroup(bookinPanelLayout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(bookinPanelLayout.createSequentialGroup().addContainerGap().addComponent(jLabel21) .addGap(18, 18, 18) .addGroup(bookinPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel22).addComponent(jLabelDVDCode1)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(bookinPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel24).addComponent(jLabelDVDTitle1)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(bookinPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel26).addComponent(copyNumberTxt, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(bookinPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(userIDTxt, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel27)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED).addComponent(bookDVD) .addGap(28, 28, 28).addComponent(jLabel28).addGap(18, 18, 18).addComponent(resultLabel) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))); errorLabelReserve.setFont(new java.awt.Font("Ubuntu", 1, 15)); // NOI18N errorLabelReserve.setForeground(new java.awt.Color(139, 2, 2)); 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) .addGroup(jPanel1Layout.createSequentialGroup() .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(bookinPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addGroup(jPanel1Layout.createSequentialGroup().addComponent(jLabel1) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(dvdCodeTxt, javax.swing.GroupLayout.PREFERRED_SIZE, 148, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(getDvdBtn).addGap(55, 55, 55) .addComponent(errorLabelReserve, javax.swing.GroupLayout.PREFERRED_SIZE, 376, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(0, 81, Short.MAX_VALUE))) .addGap(20, 20, 20))); jPanel1Layout.setVerticalGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel1Layout.createSequentialGroup().addContainerGap().addGroup(jPanel1Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE).addComponent(jLabel1) .addComponent(dvdCodeTxt, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(getDvdBtn).addComponent(errorLabelReserve)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup( jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addComponent(bookinPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addContainerGap(21, Short.MAX_VALUE))); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup().addGroup(layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup().addGap(291, 291, 291).addComponent(label2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGroup(layout.createSequentialGroup().addContainerGap().addGroup(layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup().addGroup(layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup().addComponent(jLabel6) .addGap(44, 44, 44).addComponent(keyword, javax.swing.GroupLayout.PREFERRED_SIZE, 337, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGroup(layout.createSequentialGroup().addComponent(jLabel7) .addGap(18, 18, 18) .addComponent(definition, javax.swing.GroupLayout.PREFERRED_SIZE, 93, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(41, 41, 41).addComponent(jLabel9) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(rating, javax.swing.GroupLayout.PREFERRED_SIZE, 70, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(29, 29, 29).addComponent(jLabel8) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(year, javax.swing.GroupLayout.PREFERRED_SIZE, 70, javax.swing.GroupLayout.PREFERRED_SIZE))) .addGap(29, 29, 29).addComponent(search)) .addGroup(layout.createSequentialGroup().addGap(239, 239, 239).addComponent( errorTag, javax.swing.GroupLayout.PREFERRED_SIZE, 444, javax.swing.GroupLayout.PREFERRED_SIZE))))) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jLabel2).addGap(49, 49, 49)) .addGroup(layout.createSequentialGroup().addContainerGap().addComponent(jScrollPane1) .addContainerGap()) .addGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup().addGap(290, 290, 290).addComponent( label1, javax.swing.GroupLayout.PREFERRED_SIZE, 223, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGroup(layout.createSequentialGroup().addContainerGap().addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))); layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup().addGroup(layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup().addGap(13, 13, 13) .addComponent(label2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout .createParallelGroup( javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel6).addComponent(keyword, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap( javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addGroup(layout .createParallelGroup( javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel7, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(definition, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(rating, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel8, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel9, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(year, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))) .addGroup(layout.createSequentialGroup().addGap(16, 16, 16).addComponent( search, javax.swing.GroupLayout.PREFERRED_SIZE, 54, javax.swing.GroupLayout.PREFERRED_SIZE)))) .addGroup(layout.createSequentialGroup().addContainerGap().addComponent(jLabel2))) .addGap(9, 9, 9).addComponent(errorTag).addGap(12, 12, 12) .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 139, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(label1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(37, 37, 37))); label2.getAccessibleContext().setAccessibleName("Search"); pack(); }// </editor-fold>//GEN-END:initComponents private void definitionActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_definitionActionPerformed // TODO add your handling code here: }// GEN-LAST:event_definitionActionPerformed private void ratingActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_ratingActionPerformed // TODO add your handling code here: }// GEN-LAST:event_ratingActionPerformed private void searchActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_searchActionPerformed errorTag.setVisible(false); searchTable.setModel(new DefaultTableModel()); String searchTerm = keyword.getText().toLowerCase(); String ratingTerm = rating.getSelectedItem().toString(); String yearTerm = year.getSelectedItem().toString(); String definitionTerm = definition.getSelectedItem().toString(); boolean isResultFound = false; DefaultTableModel model = new DefaultTableModel(); model.setColumnIdentifiers( new String[] { "Code", "Title", "Year", "Rating ", "Definition", "Actors", "Book" }); if (searchTerm != null && !searchTerm.isEmpty()) { for (Dvd dvd_item : searchDVDList) { if (dvd_item.getTitle().toLowerCase().contains(searchTerm)) { model.addRow(new String[] { String.valueOf(dvd_item.getCode()), dvd_item.getTitle(), String.valueOf(dvd_item.getYear()), String.valueOf(dvd_item.getRating()), dvd_item.getDefiniiton(), dvd_item.getActors() }); } } isResultFound = true; if (isResultFound) { searchTable.setVisible(true); searchTable.setModel(model); } else { errorTag.setVisible(true); searchTable.setModel(new DefaultTableModel()); // errorTag.setText("No Result Found"); } } else { if (!ratingTerm.equals("Any")) { for (Dvd dvd_item : searchDVDList) { if (dvd_item.getRating() == Integer.parseInt(ratingTerm)) { model.addRow(new String[] { String.valueOf(dvd_item.getCode()), dvd_item.getTitle(), String.valueOf(dvd_item.getYear()), String.valueOf(dvd_item.getRating()), dvd_item.getDefiniiton(), dvd_item.getActors() }); } } isResultFound = true; if (isResultFound) { searchTable.setVisible(true); searchTable.setModel(model); } else { errorTag.setVisible(true); searchTable.setModel(new DefaultTableModel()); errorTag.setText("No Result Found"); } } else if (!yearTerm.equals("Any")) { for (Dvd dvd_item : searchDVDList) { if (dvd_item.getYear().equals(yearTerm)) { model.addRow(new String[] { String.valueOf(dvd_item.getCode()), dvd_item.getTitle(), String.valueOf(dvd_item.getYear()), String.valueOf(dvd_item.getRating()), dvd_item.getDefiniiton(), dvd_item.getActors() }); } } isResultFound = true; if (isResultFound) { searchTable.setVisible(true); searchTable.setModel(model); } else { errorTag.setVisible(true); searchTable.setModel(new DefaultTableModel()); errorTag.setText("No Result Found"); } } else if (!definitionTerm.equals("Any")) { for (Dvd dvd_item : searchDVDList) { if (dvd_item.getDefiniiton().equals(definitionTerm)) { model.addRow(new String[] { String.valueOf(dvd_item.getCode()), dvd_item.getTitle(), String.valueOf(dvd_item.getYear()), String.valueOf(dvd_item.getRating()), dvd_item.getDefiniiton(), dvd_item.getActors() }); } } isResultFound = true; if (isResultFound) { searchTable.setVisible(true); searchTable.setModel(model); } else { errorTag.setVisible(true); searchTable.setModel(new DefaultTableModel()); errorTag.setText("No Result Found"); } } else { errorTag.setText("Please enter more specific search criteria"); errorTag.setVisible(true); } // errorTag.setText("No Result Found"); } }// GEN-LAST:event_searchActionPerformed private void yearActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_yearActionPerformed // TODO add your handling code here: }// GEN-LAST:event_yearActionPerformed private void getDvdBtnActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_getDvdBtnActionPerformed String dvdCodeStr = dvdCodeTxt.getText(); errorLabelReserve.setVisible(false); copyTable.setVisible(false); copyTable.setModel(new DefaultTableModel()); boolean isMatched = false; DefaultTableModel model = new DefaultTableModel(); model.setColumnIdentifiers(new String[] { "Copy Number", "ISLE Number", "Shelf Number", "is Available " }); if (dvdCodeStr != null && !dvdCodeStr.isEmpty()) { int dvdCodeInt = 0; try { dvdCodeInt = Integer.parseInt(dvdCodeStr); // Get DVD Service for (Dvd dvd : searchDVDList) { if (dvd.getCode() == dvdCodeInt) { isMatched = true; jLabelDVDCode.setText(String.valueOf(dvd.getCode())); jLabelDVDCode1.setText(String.valueOf(dvd.getCode())); jLabelDVDTitle.setText(dvd.getTitle()); jLabelDVDTitle1.setText(dvd.getTitle()); jLabelYear.setText(String.valueOf(dvd.getYear())); jLabelImdb.setText(String.valueOf(dvd.getRating())); jLabelActors.setText(dvd.getActors()); jLabelFormat.setText(dvd.getDefiniiton()); // Get Copies from DVD code - Service DVDRepository dVDRepository = new DVDRepository(); try { if (isServiceOn) { searchCopyDVDList = new ArrayList<DvdCopy>(); searchCopyDVDList = dVDRepository.getCopyDVDList(dvdCodeInt); } else { com.dvd.hibernate.repo.DVDRepository repository = new com.dvd.hibernate.repo.DVDRepository(); searchCopyDVDList = new ArrayList<DvdCopy>(); List<DVDCopyDao> s = repository.getCopyDVDList(dvdCodeInt); if (s != null) { for (DVDCopyDao dvdCopyDao : s) { searchCopyDVDList.add(new DvdCopy(dvdCopyDao.getIsleNumber(), String.valueOf(dvdCopyDao.getCopyNumber()), dvdCopyDao.getShelfNumber(), dvd, dvdCopyDao.isAvailable())); } } } } catch (Exception ex) { Logger.getLogger(SearchDVD.class.getName()).log(Level.SEVERE, null, ex); } for (DvdCopy copy : searchCopyDVDList) { model.addRow(new String[] { copy.getCopyNumber(), copy.getIsleNumber(), copy.getShelfNumber(), String.valueOf(copy.isIsAvailable()) }); } jLabelCopies.setText(String.valueOf(searchCopyDVDList.size())); copyTable.setVisible(true); copyTable.setModel(model); } } if (!isMatched) { errorLabelReserve.setVisible(true); errorLabelReserve.setText("No DVD match"); } } catch (Exception e) { errorLabelReserve.setText(""); errorLabelReserve.setVisible(true); errorLabelReserve.setText("Please enter a valid DVD Code"); resetData(); } } else { resetData(); errorLabelReserve.setVisible(true); errorLabelReserve.setText("Please enter a valid DVD Code"); } }// GEN-LAST:event_getDvdBtnActionPerformed private void resetData() { jLabelDVDCode.setText(""); jLabelDVDCode1.setText(""); jLabelDVDTitle.setText(""); jLabelDVDTitle1.setText(""); jLabelYear.setText(""); jLabelImdb.setText(""); jLabelActors.setText(""); jLabelFormat.setText(""); } private void copyNumberTxtActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_copyNumberTxtActionPerformed // TODO add your handling code here: }// GEN-LAST:event_copyNumberTxtActionPerformed private void userIDTxtActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_userIDTxtActionPerformed // TODO add your handling code here: }// GEN-LAST:event_userIDTxtActionPerformed private void bookDVDActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_bookDVDActionPerformed errorLabelReserve.setText(""); errorLabelReserve.setVisible(false); String t = jLabelDVDTitle1.getText(); String cn = copyNumberTxt.getText(); String ui = userIDTxt.getText(); if (t != null && !t.isEmpty() && cn != null && !cn.isEmpty() && ui != null && !ui.isEmpty()) { try { int copyNumber = Integer.parseInt(cn); int userID = Integer.parseInt(ui); if (isServiceOn) { // Call Service String result = ""; String url1 = "http://localhost:8080/addBooking?copyNumber=" + copyNumber + "&userID=" + userID; // String q = URLEncoder.encode(original, "UTF-8"); URL url = new URL(url1); URL obj = url; HttpURLConnection con = (HttpURLConnection) obj.openConnection(); // optional default is GET con.setRequestMethod("POST"); // add request header con.setRequestProperty("User-Agent", "Mozilla/5.0"); int responseCode = con.getResponseCode(); System.out.println("\nSending 'GET' request to URL : " + url); System.out.println("Response Code : " + responseCode); BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream())); String inputLine; StringBuffer response = new StringBuffer(); while ((inputLine = in.readLine()) != null) { response.append(inputLine); } in.close(); // print result result = response.toString(); // Parse to get translated text JSONObject jsonObject = new JSONObject(result); int code = jsonObject.getJSONObject("responseCode").getInt("code"); if (code == 201) { resultLabel.setForeground(Color.GREEN); resultLabel.setText("Booking Successful for " + ui + "/" + cn); resultLabel.setVisible(true); } else { resultLabel.setForeground(Color.RED); resultLabel.setText("Booking failed"); resultLabel.setVisible(true); } } else { BookingRepository repository = new BookingRepository(); BookingDao bookingDao = new BookingDao(copyNumber, userID); repository.addBooking(bookingDao); resultLabel.setForeground(Color.GREEN); resultLabel.setText("Booking Successful for " + ui + "/" + cn); resultLabel.setVisible(true); } } catch (Exception e) { resultLabel.setForeground(Color.RED); resultLabel.setText("Booking failed"); resultLabel.setVisible(true); } } else { resultLabel.setForeground(Color.RED); resultLabel.setText("Please enter valid IDs"); resultLabel.setVisible(true); } }// GEN-LAST:event_bookDVDActionPerformed /** * @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(SearchDVD.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (InstantiationException ex) { java.util.logging.Logger.getLogger(SearchDVD.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (IllegalAccessException ex) { java.util.logging.Logger.getLogger(SearchDVD.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (javax.swing.UnsupportedLookAndFeelException ex) { java.util.logging.Logger.getLogger(SearchDVD.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() { // new SearchDVD().setVisible(true); } }); } // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton bookDVD; private javax.swing.JPanel bookinPanel; private javax.swing.JTextField copyNumberTxt; private javax.swing.JTable copyTable; private javax.swing.JComboBox definition; private javax.swing.JTextField dvdCodeTxt; private javax.swing.JLabel errorLabelReserve; private javax.swing.JLabel errorTag; private javax.swing.JButton getDvdBtn; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel11; private javax.swing.JLabel jLabel13; private javax.swing.JLabel jLabel15; private javax.swing.JLabel jLabel16; private javax.swing.JLabel jLabel17; private javax.swing.JLabel jLabel18; private javax.swing.JLabel jLabel19; private javax.swing.JLabel jLabel2; private javax.swing.JLabel jLabel21; private javax.swing.JLabel jLabel22; private javax.swing.JLabel jLabel24; private javax.swing.JLabel jLabel26; private javax.swing.JLabel jLabel27; private javax.swing.JLabel jLabel28; private javax.swing.JLabel jLabel3; 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.JLabel jLabelActors; private javax.swing.JLabel jLabelCopies; private javax.swing.JLabel jLabelDVDCode; private javax.swing.JLabel jLabelDVDCode1; private javax.swing.JLabel jLabelDVDTitle; private javax.swing.JLabel jLabelDVDTitle1; private javax.swing.JLabel jLabelFormat; private javax.swing.JLabel jLabelImdb; private javax.swing.JLabel jLabelYear; private javax.swing.JPanel jPanel1; private javax.swing.JPanel jPanel2; private javax.swing.JScrollPane jScrollPane1; private javax.swing.JScrollPane jScrollPane2; private javax.swing.JTextField keyword; private java.awt.Label label1; private java.awt.Label label2; private javax.swing.JComboBox rating; private javax.swing.JLabel resultLabel; private javax.swing.JButton search; private javax.swing.JTable searchTable; private javax.swing.JTextField userIDTxt; private javax.swing.JComboBox year; // End of variables declaration//GEN-END:variables private void myinitcomponent() { // jComboBox2.setModel(new DefaultComboBoxModel(comboType.toArray())); } }