[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

How to refresh JTable after adding one row?

Posted on 2011-10-28
106
Medium Priority
?
881 Views
Last Modified: 2012-05-12
I want to redraw my JTable automatically after one row is added. I need the entire source code and please - since I am a newbie, I need some kind of explanation.
0
Comment
Question by:octoberqueen
  • 54
  • 50
  • 2
106 Comments
 
LVL 41

Expert Comment

by:HonorGod
ID: 37050100
Can you show us what you have, and how you "add a row"?
0
 
LVL 41

Expert Comment

by:HonorGod
ID: 37050107
Maybe I should also ask if you are talking about a Swing JTable: http://download.oracle.com/javase/7/docs/api/javax/swing/JTable.html
0
 
LVL 47

Expert Comment

by:for_yan
ID: 37051564
Tkae a look at this code based on
http://www.exampledepot.com/egs/javax.swing.table/InsertRow.html

Compile and execute it.

You'll see the table - wait for 5 seconds and you'll see two more rows added
to this table.

In this case just adding the rwos to  the model works all by itself.
In some more sop[histicated cases if it does not work in this straight forward way - after you
modify the model - repaint the Jtable or the component which contains your JTable

 Theer are also different listeners buty usually I didn't need those
Let me know if ou have questions.

import javax.swing.*;
import javax.swing.table.DefaultTableModel;

public class AppendARow {
    public static void main(String[] args) {
        DefaultTableModel model = new DefaultTableModel();
JTable table = new JTable(model);

// Create a couple of columns
model.addColumn("Col1");
model.addColumn("Col2");

// Append a row
model.addRow(new Object[]{"v1", "v2"});
// there are now 2 rows with 2 columns
        JFrame jf = new JFrame();
        jf.getContentPane().add(table);
        jf.setSize(300,300);
        jf.setVisible(true);
              try{
        Thread.currentThread().sleep(5000);
              }catch(Exception ex){
                  ex.printStackTrace();
              }


// Append a row with fewer values than columns.
// The left-most fields in the new row are populated
// with the supplied values (left-to-right) and fields
// without values are set to null.
model.addRow(new Object[]{"v1"});
// there are now 3 rows with 2 columns

// Append a row with more values than columns.
// The extra values are ignored.
model.addRow(new Object[]{"v1", "v2", "v3"});

    }


}

Open in new window

0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:octoberqueen
ID: 37143112
Sorry I was very busy.

I add rows in this way

After pressing ADD RECORDS Button in this window
 mayajaal-first frame
The following dialog will popup
 add-movie
When I press the OK Button, the data inputted in TextBoxes should be passed to table in mysql database and simultaneously a new row with these details should appear below my JTable. The processor should be automatic.

What I wrote till now in OK Button
 private void addBtnActionPerformed(java.awt.event.ActionEvent evt) {                                       
String movie = movTF.getText();
String screen = screenTF.getText();
String showTime = stTF.getText();
String endTime = etTF.getText();
    
 if (movie.equals(""))
    JOptionPane.showMessageDialog(this,"Movie Not Entered");
  
else if(screen.equals(""))
    JOptionPane.showMessageDialog(this,"Language Not Entered");

else if(showTime.equals(""))
    JOptionPane.showMessageDialog(this,"ShowTime Not Entered");

   
   

else{

try
{
    
        
Class.forName("java.sql.DriverManager");

Connection con = (Connection)
        
DriverManager.getConnection ("jdbc:mysql://localhost:3306/cbse","root", "tiger");

Statement stmt = (Statement) con.createStatement();

String query="INSERT INTO singlemayajaal VALUES ('"+showTime+"','"+endTime+"','"+screen+"','"+movie+"');";
stmt.executeUpdate(query);

JOptionPane.showMessageDialog (this,"Movie Added Successfully");  




movTF.setText("");
screenTF.setText("");
stTF.setText("");
etTF.setText("");

    
    }


catch(Exception e)

{
JOptionPane.showMessageDialog (null,"Something is Wrong.Please check whether all fields are filled properly");
}

}     
    }                                      

Open in new window




I need only the code to be written in OK Button.
0
 
LVL 47

Expert Comment

by:for_yan
ID: 37143124
But where is your JTable?
0
 

Author Comment

by:octoberqueen
ID: 37143150
mayajaal-frame
In this image, the highlighted orange is my JTable.
0
 
LVL 47

Expert Comment

by:for_yan
ID: 37143171
I'm not talking about the image.
I'm talking about the code.
In your code you are updating the database.
But there is no sign of any JTable there.

When the row is deleted or added - you should update the
model under your JTable and that would lead to the update of your JTable
(see for example the code I posted above).
But you need to have JTable created and need to create model and populate it with
the data for eaxmple win the way it is shown in the code.
0
 

Author Comment

by:octoberqueen
ID: 37143183
How to modify my existing code? Using JTable and tablemodel to add row so that instant updation can take place.
0
 
LVL 47

Expert Comment

by:for_yan
ID: 37143190
Do you have the code which creates this screen which you show -  SinglePlexTheatre ?
0
 

Author Comment

by:octoberqueen
ID: 37143198
This is my entire source code(Note: I didn't create most of it. Majority was auto generated).

package sample_3_multi;

import java.sql.*;
import javax.swing.table.DefaultTableModel;
import javax.swing.JOptionPane;


import java.awt.*;  
import java.awt.event.*;  
 


import java.util.Date;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;


import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.text.SimpleDateFormat;



import java.sql.DriverManager;
import com.mysql.jdbc.Connection;
import com.mysql.jdbc.Statement;


import javax.swing.*;



/**
 *
 * @author Octoberqueen
 */
public class Single_Plex_1_Copy extends javax.swing.JFrame {

    /** Creates new form Single_Plex_1 */
    public Single_Plex_1_Copy() {
        initComponents();
    }




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

        successDialog = new javax.swing.JDialog();
        titleLab1 = new javax.swing.JLabel();
        sumMovLab = new javax.swing.JLabel();
        sumShowTimeLab = new javax.swing.JLabel();
        sumDateLab = new javax.swing.JLabel();
        sumScreenLab = new javax.swing.JLabel();
        sumClassLab = new javax.swing.JLabel();
        sumNoFTicketsLab = new javax.swing.JLabel();
        sumGrandLab = new javax.swing.JLabel();
        jLabel25 = new javax.swing.JLabel();
        jLabel26 = new javax.swing.JLabel();
        jLabel27 = new javax.swing.JLabel();
        jLabel31 = new javax.swing.JLabel();
        jLabel32 = new javax.swing.JLabel();
        jLabel33 = new javax.swing.JLabel();
        jLabel34 = new javax.swing.JLabel();
        SeatNosLabel = new javax.swing.JLabel();
        jLabel30 = new javax.swing.JLabel();
        cancel1 = new javax.swing.JButton();
        jLabel17 = new javax.swing.JLabel();
        dateLab = new javax.swing.JLabel();
        passDialog = new javax.swing.JDialog();
        jLabel18 = new javax.swing.JLabel();
        passField = new javax.swing.JPasswordField();
        passSubmit = new javax.swing.JButton();
        addDialog = new javax.swing.JDialog();
        jLabel14 = new javax.swing.JLabel();
        jLabel16 = new javax.swing.JLabel();
        jLabel15 = new javax.swing.JLabel();
        stTF = new javax.swing.JTextField();
        etTF = new javax.swing.JTextField();
        movTF = new javax.swing.JTextField();
        screenTF = new javax.swing.JTextField();
        titleLab2 = new javax.swing.JLabel();
        jLabel13 = new javax.swing.JLabel();
        addBtn = new javax.swing.JButton();
        statDialog = new javax.swing.JDialog();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jScrollPane2 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        classCB = new javax.swing.JComboBox();
        jLabel9 = new javax.swing.JLabel();
        stLab = new javax.swing.JLabel();
        movLab = new javax.swing.JLabel();
        title = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        movTable = new javax.swing.JTable();
        delRecord = new javax.swing.JButton();
        screenLab = new javax.swing.JLabel();
        addRecord = new javax.swing.JButton();
        bookNowBtn = new javax.swing.JButton();
        jLabel8 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        LastSeatNoLabel = new javax.swing.JLabel();
        LastSeatRowLabel = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        jLabel12 = new javax.swing.JLabel();
        jLabel24 = new javax.swing.JLabel();
        SeatsCB = new javax.swing.JComboBox();
        jLabel28 = new javax.swing.JLabel();
        jLabel29 = new javax.swing.JLabel();
        s1Lab = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        costLab = new javax.swing.JLabel();
        statBtn = new javax.swing.JButton();

        successDialog.setMinimumSize(new java.awt.Dimension(448, 424));

        titleLab1.setFont(new java.awt.Font("Tahoma", 1, 18));
        titleLab1.setText("                          Booking Summary");

        sumMovLab.setBorder

(javax.swing.BorderFactory.createEtchedBorder());

        sumShowTimeLab.setBorder

(javax.swing.BorderFactory.createEtchedBorder());

        sumDateLab.setBorder

(javax.swing.BorderFactory.createEtchedBorder());

        sumScreenLab.setBorder

(javax.swing.BorderFactory.createEtchedBorder());

        sumClassLab.setBorder

(javax.swing.BorderFactory.createEtchedBorder());

        sumNoFTicketsLab.setBorder

(javax.swing.BorderFactory.createEtchedBorder());

        sumGrandLab.setFont(new java.awt.Font("Tahoma", 1, 14));
        sumGrandLab.setForeground(new java.awt.Color(255, 51, 0));
        sumGrandLab.setBorder

(javax.swing.BorderFactory.createEtchedBorder());

        jLabel25.setFont(new java.awt.Font("Tahoma", 1, 14));
        jLabel25.setText("Grand Total:");

        jLabel26.setText("Screen:");

        jLabel27.setText("ShowTime:");

        jLabel31.setText("Movie:");

        jLabel32.setText("Date:");

        jLabel33.setText("Class:");

        jLabel34.setText("No. of  Tickets:");

        SeatNosLabel.setFont(new java.awt.Font("Tahoma", 1, 10));
        SeatNosLabel.setBorder

(javax.swing.BorderFactory.createEtchedBorder());

        jLabel30.setFont(new java.awt.Font("Tahoma", 1, 14));
        jLabel30.setText("Seat Number(s):");

        cancel1.setText("OK");
        cancel1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) 

{
                cancel1ActionPerformed(evt);
            }
        });

        jLabel17.setFont(new java.awt.Font("Tahoma", 1, 10));
        jLabel17.setText("Time:");

        dateLab.setFont(new java.awt.Font("Tahoma", 0, 10));
        dateLab.setBorder(javax.swing.BorderFactory.createEtchedBorder

());

        javax.swing.GroupLayout successDialogLayout = new 

javax.swing.GroupLayout(successDialog.getContentPane());
        successDialog.getContentPane().setLayout(successDialogLayout);
        successDialogLayout.setHorizontalGroup(
            successDialogLayout.createParallelGroup

(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(successDialogLayout.createSequentialGroup()
                .addGap(108, 108, 108)
                .addComponent(cancel1, 

javax.swing.GroupLayout.PREFERRED_SIZE, 205, 

javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(135, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, 

successDialogLayout.createSequentialGroup()
                .addGroup(successDialogLayout.createParallelGroup

(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(successDialogLayout.createSequentialGroup

()
                        .addContainerGap()
                        .addGroup

(successDialogLayout.createParallelGroup

(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup

(successDialogLayout.createSequentialGroup()
                                .addComponent(jLabel17)
                                .addPreferredGap

(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(dateLab, 

javax.swing.GroupLayout.PREFERRED_SIZE, 50, 

javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup

(javax.swing.GroupLayout.Alignment.LEADING, 

successDialogLayout.createSequentialGroup()
                                .addGroup

(successDialogLayout.createParallelGroup

(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel32, 

javax.swing.GroupLayout.PREFERRED_SIZE, 50, 

javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jLabel26)
                                    .addComponent(jLabel33)
                                    .addComponent(jLabel34)
                                    .addComponent(jLabel27)
                                    .addComponent(jLabel31, 

javax.swing.GroupLayout.PREFERRED_SIZE, 50, 

javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addPreferredGap

(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 103, 

Short.MAX_VALUE)
                                .addGroup

(successDialogLayout.createParallelGroup

(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup

(javax.swing.GroupLayout.Alignment.TRAILING, 

successDialogLayout.createParallelGroup

(javax.swing.GroupLayout.Alignment.LEADING, false)
                                        .addComponent(sumShowTimeLab, 

javax.swing.GroupLayout.DEFAULT_SIZE, 234, Short.MAX_VALUE)
                                        .addComponent(sumDateLab, 

javax.swing.GroupLayout.DEFAULT_SIZE, 234, Short.MAX_VALUE)
                                        .addComponent(sumScreenLab, 

javax.swing.GroupLayout.DEFAULT_SIZE, 234, Short.MAX_VALUE)
                                        .addComponent(sumClassLab, 

javax.swing.GroupLayout.Alignment.TRAILING, 

javax.swing.GroupLayout.PREFERRED_SIZE, 234, 

javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(sumNoFTicketsLab, 

javax.swing.GroupLayout.Alignment.TRAILING, 

javax.swing.GroupLayout.PREFERRED_SIZE, 234, 

javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addComponent(sumMovLab, 

javax.swing.GroupLayout.Alignment.TRAILING, 

javax.swing.GroupLayout.PREFERRED_SIZE, 234, 

javax.swing.GroupLayout.PREFERRED_SIZE)))
                            .addGroup

(successDialogLayout.createSequentialGroup()
                                .addGroup

(successDialogLayout.createParallelGroup

(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel25)
                                    .addComponent(jLabel30))
                                .addGap(18, 18, 18)
                                .addGroup

(successDialogLayout.createParallelGroup

(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addComponent(sumGrandLab, 

javax.swing.GroupLayout.PREFERRED_SIZE, 234, 

javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(SeatNosLabel, 

javax.swing.GroupLayout.DEFAULT_SIZE, 277, Short.MAX_VALUE)))))
                    .addComponent(titleLab1, 

javax.swing.GroupLayout.DEFAULT_SIZE, 420, Short.MAX_VALUE))
                .addGap(28, 28, 28))
        );
        successDialogLayout.setVerticalGroup(
            successDialogLayout.createParallelGroup

(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(successDialogLayout.createSequentialGroup()
                .addComponent(titleLab1)
                .addGap(15, 15, 15)
                .addGroup(successDialogLayout.createParallelGroup

(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(dateLab, 

javax.swing.GroupLayout.PREFERRED_SIZE, 18, 

javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel17))
                .addPreferredGap

(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(successDialogLayout.createParallelGroup

(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(sumMovLab, 

javax.swing.GroupLayout.DEFAULT_SIZE, 32, Short.MAX_VALUE)
                    .addComponent(jLabel31, 

javax.swing.GroupLayout.PREFERRED_SIZE, 27, 

javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap

(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(successDialogLayout.createParallelGroup

(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(sumShowTimeLab, 

javax.swing.GroupLayout.DEFAULT_SIZE, 32, Short.MAX_VALUE)
                    .addComponent(jLabel27, 

javax.swing.GroupLayout.DEFAULT_SIZE, 32, Short.MAX_VALUE))
                .addPreferredGap

(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(successDialogLayout.createParallelGroup

(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(sumDateLab, 

javax.swing.GroupLayout.DEFAULT_SIZE, 32, Short.MAX_VALUE)
                    .addComponent(jLabel32, 

javax.swing.GroupLayout.DEFAULT_SIZE, 32, Short.MAX_VALUE))
                .addPreferredGap

(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(successDialogLayout.createParallelGroup

(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(sumScreenLab, 

javax.swing.GroupLayout.DEFAULT_SIZE, 32, Short.MAX_VALUE)
                    .addComponent(jLabel26, 

javax.swing.GroupLayout.DEFAULT_SIZE, 32, Short.MAX_VALUE))
                .addPreferredGap

(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(successDialogLayout.createParallelGroup

(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(sumClassLab, 

javax.swing.GroupLayout.DEFAULT_SIZE, 34, Short.MAX_VALUE)
                    .addComponent(jLabel33, 

javax.swing.GroupLayout.DEFAULT_SIZE, 34, Short.MAX_VALUE))
                .addGap(5, 5, 5)
                .addGroup(successDialogLayout.createParallelGroup

(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(sumNoFTicketsLab, 

javax.swing.GroupLayout.DEFAULT_SIZE, 32, Short.MAX_VALUE)
                    .addComponent(jLabel34, 

javax.swing.GroupLayout.DEFAULT_SIZE, 32, Short.MAX_VALUE))
                .addPreferredGap

(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(successDialogLayout.createParallelGroup

(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(SeatNosLabel, 

javax.swing.GroupLayout.DEFAULT_SIZE, 34, Short.MAX_VALUE)
                    .addComponent(jLabel30, 

javax.swing.GroupLayout.DEFAULT_SIZE, 34, Short.MAX_VALUE))
                .addPreferredGap

(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(successDialogLayout.createParallelGroup

(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(sumGrandLab, 

javax.swing.GroupLayout.DEFAULT_SIZE, 34, Short.MAX_VALUE)
                    .addComponent(jLabel25, 

javax.swing.GroupLayout.DEFAULT_SIZE, 34, Short.MAX_VALUE))
                .addGap(11, 11, 11)
                .addComponent(cancel1, 

javax.swing.GroupLayout.PREFERRED_SIZE, 43, 

javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        passDialog.setDefaultCloseOperation

(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        passDialog.setTitle("Password");
        passDialog.setMinimumSize(new java.awt.Dimension(281, 201));

        jLabel18.setFont(new java.awt.Font("Tahoma", 1, 12));
        jLabel18.setText("Enter Password to Continue:");

        passField.addActionListener(new java.awt.event.ActionListener() 

{
            public void actionPerformed(java.awt.event.ActionEvent evt) 

{
                passFieldActionPerformed(evt);
            }
        });

        passSubmit.setText("Submit");
        passSubmit.addActionListener(new java.awt.event.ActionListener() 

{
            public void actionPerformed(java.awt.event.ActionEvent evt) 

{
                passSubmitActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout passDialogLayout = new 

javax.swing.GroupLayout(passDialog.getContentPane());
        passDialog.getContentPane().setLayout(passDialogLayout);
        passDialogLayout.setHorizontalGroup(
            passDialogLayout.createParallelGroup

(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(passDialogLayout.createSequentialGroup()
                .addGap(53, 53, 53)
                .addGroup(passDialogLayout.createParallelGroup

(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(passSubmit, 

javax.swing.GroupLayout.PREFERRED_SIZE, 178, 

javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(passDialogLayout.createParallelGroup

(javax.swing.GroupLayout.Alignment.LEADING, false)
                        .addComponent(passField, 

javax.swing.GroupLayout.Alignment.TRAILING)
                        .addComponent(jLabel18, 

javax.swing.GroupLayout.Alignment.TRAILING)))
                .addContainerGap(50, Short.MAX_VALUE))
        );
        passDialogLayout.setVerticalGroup(
            passDialogLayout.createParallelGroup

(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(passDialogLayout.createSequentialGroup()
                .addGap(39, 39, 39)
                .addComponent(jLabel18)
                .addGap(18, 18, 18)
                .addComponent(passField, 

javax.swing.GroupLayout.PREFERRED_SIZE, 

javax.swing.GroupLayout.DEFAULT_SIZE, 

javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(passSubmit, 

javax.swing.GroupLayout.PREFERRED_SIZE, 34, 

javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(41, Short.MAX_VALUE))
        );

        addDialog.setMinimumSize(new java.awt.Dimension(315, 300));

        jLabel14.setText("Screen:");

        jLabel16.setText("EndTime:");

        jLabel15.setText("Showtime:");

        stTF.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) 

{
                stTFActionPerformed(evt);
            }
        });

        etTF.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) 

{
                etTFActionPerformed(evt);
            }
        });

        movTF.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) 

{
                movTFActionPerformed(evt);
            }
        });

        screenTF.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) 

{
                screenTFActionPerformed(evt);
            }
        });

        titleLab2.setFont(new java.awt.Font("Tahoma", 1, 18));
        titleLab2.setText("                      Add Movie");

        jLabel13.setText("Movie:");

        addBtn.setText("OK");
        addBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) 

{
                addBtnActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout addDialogLayout = new 

javax.swing.GroupLayout(addDialog.getContentPane());
        addDialog.getContentPane().setLayout(addDialogLayout);
        addDialogLayout.setHorizontalGroup(
            addDialogLayout.createParallelGroup

(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(addDialogLayout.createSequentialGroup()
                .addGroup(addDialogLayout.createParallelGroup

(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(titleLab2, 

javax.swing.GroupLayout.PREFERRED_SIZE, 281, 

javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(addDialogLayout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(addDialogLayout.createParallelGroup

(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel16)
                            .addComponent(jLabel15)
                            .addComponent(jLabel14)
                            .addComponent(jLabel13))
                        .addGap(38, 38, 38)
                        .addGroup(addDialogLayout.createParallelGroup

(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(addBtn, 

javax.swing.GroupLayout.PREFERRED_SIZE, 86, 

javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(movTF, 

javax.swing.GroupLayout.PREFERRED_SIZE, 163, 

javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(screenTF, 

javax.swing.GroupLayout.PREFERRED_SIZE, 163, 

javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(stTF, 

javax.swing.GroupLayout.PREFERRED_SIZE, 163, 

javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(etTF, 

javax.swing.GroupLayout.PREFERRED_SIZE, 163, 

javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(20, 20, 20)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, 

Short.MAX_VALUE))
        );
        addDialogLayout.setVerticalGroup(
            addDialogLayout.createParallelGroup

(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(addDialogLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(titleLab2)
                .addGap(18, 18, 18)
                .addGroup(addDialogLayout.createParallelGroup

(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(movTF, 

javax.swing.GroupLayout.PREFERRED_SIZE, 

javax.swing.GroupLayout.DEFAULT_SIZE, 

javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel13))
                .addGap(18, 18, 18)
                .addGroup(addDialogLayout.createParallelGroup

(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel14)
                    .addComponent(screenTF, 

javax.swing.GroupLayout.PREFERRED_SIZE, 

javax.swing.GroupLayout.DEFAULT_SIZE, 

javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(addDialogLayout.createParallelGroup

(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel15)
                    .addComponent(stTF, 

javax.swing.GroupLayout.PREFERRED_SIZE, 

javax.swing.GroupLayout.DEFAULT_SIZE, 

javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(addDialogLayout.createParallelGroup

(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(etTF, 

javax.swing.GroupLayout.PREFERRED_SIZE, 

javax.swing.GroupLayout.DEFAULT_SIZE, 

javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel16))
                .addPreferredGap

(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 33, 

Short.MAX_VALUE)
                .addComponent(addBtn, 

javax.swing.GroupLayout.PREFERRED_SIZE, 36, 

javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        statDialog.setMinimumSize(new java.awt.Dimension(472, 300));

        jLabel1.setText("Daily Bookings");

        jLabel2.setText("Total Bookings:");

        jLabel3.setText("Total Bookings:");

        jLabel4.setText("Booking Log");

        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jScrollPane2.setViewportView(jTable1);

        javax.swing.GroupLayout statDialogLayout = new 

javax.swing.GroupLayout(statDialog.getContentPane());
        statDialog.getContentPane().setLayout(statDialogLayout);
        statDialogLayout.setHorizontalGroup(
            statDialogLayout.createParallelGroup

(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(statDialogLayout.createSequentialGroup()
                .addGroup(statDialogLayout.createParallelGroup

(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(statDialogLayout.createSequentialGroup()
                        .addGap(57, 57, 57)
                        .addGroup(statDialogLayout.createParallelGroup

(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel3)
                            .addComponent(jLabel2)
                            .addComponent(jLabel1)))
                    .addGroup(statDialogLayout.createSequentialGroup()
                        .addGap(83, 83, 83)
                        .addComponent(jLabel4)))
                .addGap(27, 27, 27)
                .addComponent(jScrollPane2, 

javax.swing.GroupLayout.PREFERRED_SIZE, 452, 

javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(66, Short.MAX_VALUE))
        );
        statDialogLayout.setVerticalGroup(
            statDialogLayout.createParallelGroup

(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(statDialogLayout.createSequentialGroup()
                .addGap(33, 33, 33)
                .addComponent(jLabel4)
                .addGap(33, 33, 33)
                .addComponent(jLabel1)
                .addGap(18, 18, 18)
                .addComponent(jLabel2)
                .addGap(18, 18, 18)
                .addComponent(jLabel3)
                .addContainerGap(142, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, 

statDialogLayout.createSequentialGroup()
                .addContainerGap(25, Short.MAX_VALUE)
                .addComponent(jScrollPane2, 

javax.swing.GroupLayout.PREFERRED_SIZE, 275, 

javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        setDefaultCloseOperation

(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Mayajaal SinglePlex");
        setMinimumSize(new java.awt.Dimension(817, 458));
        setResizable(false);

        classCB.setModel(new javax.swing.DefaultComboBoxModel(new 

String[] { "EXECUTIVE -  Rs.100" }));
        classCB.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) 

{
                classCBActionPerformed(evt);
            }
        });

        jLabel9.setFont(new java.awt.Font("Tahoma", 1, 11));
        jLabel9.setText("Class:");

        stLab.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        movLab.setBorder(javax.swing.BorderFactory.createEtchedBorder

());

        title.setFont(new java.awt.Font("Verdana", 1, 18));
        title.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        title.setText("Mayajaal SinglePlex Theatre");

        movTable.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {"9:00 AM", "12:00 PM", "A", "Ra.One"}
            },
            new String [] {
                "ShowTime", "EndTime", "Screen", "Movie"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false, false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) 

{
                return canEdit [columnIndex];
            }
        });
        movTable.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                movTableMouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(movTable);

        delRecord.setText("Delete Records");
        delRecord.addActionListener(new java.awt.event.ActionListener() 

{
            public void actionPerformed(java.awt.event.ActionEvent evt) 

{
                delRecordActionPerformed(evt);
            }
        });

        screenLab.setBorder

(javax.swing.BorderFactory.createEtchedBorder());

        addRecord.setText("Add Records");
        addRecord.setMaximumSize(new java.awt.Dimension(115, 23));
        addRecord.setMinimumSize(new java.awt.Dimension(115, 23));
        addRecord.setPreferredSize(new java.awt.Dimension(115, 23));
        addRecord.addActionListener(new java.awt.event.ActionListener() 

{
            public void actionPerformed(java.awt.event.ActionEvent evt) 

{
                addRecordActionPerformed(evt);
            }
        });

        bookNowBtn.setText("Book Now");
        bookNowBtn.addActionListener(new java.awt.event.ActionListener() 

{
            public void actionPerformed(java.awt.event.ActionEvent evt) 

{
                bookNowBtnActionPerformed(evt);
            }
        });

        jLabel8.setText("Movie");

        jLabel5.setText("Screen");

        jLabel6.setText("Showtime");

        jLabel7.setFont(new java.awt.Font("Tahoma", 1, 11));
        jLabel7.setText("Seats Filled");

        LastSeatNoLabel.setFont(new java.awt.Font("Tahoma", 0, 12));
        LastSeatNoLabel.setText("0");
        LastSeatNoLabel.setBorder

(javax.swing.BorderFactory.createEtchedBorder());

        LastSeatRowLabel.setFont(new java.awt.Font("Tahoma", 0, 12));
        LastSeatRowLabel.setText("-");
        LastSeatRowLabel.setBorder

(javax.swing.BorderFactory.createEtchedBorder());

        jLabel11.setFont(new java.awt.Font("Tahoma", 1, 12));
        jLabel11.setText("Number of Seats :-");

        jLabel12.setFont(new java.awt.Font("Tahoma", 1, 12));
        jLabel12.setText("Seats Occupied:");

        jLabel24.setFont(new java.awt.Font("Tahoma", 1, 11));
        jLabel24.setText("Row");

        SeatsCB.setModel(new javax.swing.DefaultComboBoxModel(new 

String[] { "-----No of Seats-----", "1", "2", "3", "4", "5", "6", "7", 

"8", "9", "10" }));
        SeatsCB.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) 

{
                SeatsCBActionPerformed(evt);
            }
        });

        jLabel28.setText("Booking Position(Remaining):");

        jLabel29.setText("Screen 1:");

        s1Lab.setText("234");
        s1Lab.setBorder(javax.swing.BorderFactory.createLineBorder(new 

java.awt.Color(0, 0, 0)));

        jLabel10.setFont(new java.awt.Font("Tahoma", 1, 12));
        jLabel10.setText("Total Cost:");

        costLab.setFont(new java.awt.Font("Tahoma", 1, 14));
        costLab.setText("Rs.");
        costLab.setBorder(javax.swing.BorderFactory.createEtchedBorder

());

        statBtn.setText("Statistics");
        statBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) 

{
                statBtnActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout

(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup

(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup

(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(addRecord, 

javax.swing.GroupLayout.PREFERRED_SIZE, 150, 

javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(delRecord, 

javax.swing.GroupLayout.DEFAULT_SIZE, 

javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addComponent(jScrollPane1, 

javax.swing.GroupLayout.PREFERRED_SIZE, 311, 

javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(10, 10, 10)
                .addGroup(layout.createParallelGroup

(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel9)
                    .addComponent(jLabel11)
                    .addGroup

(javax.swing.GroupLayout.Alignment.TRAILING, 

layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup

(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(bookNowBtn, 

javax.swing.GroupLayout.Alignment.LEADING, 

javax.swing.GroupLayout.DEFAULT_SIZE, 209, Short.MAX_VALUE)
                            .addGroup

(javax.swing.GroupLayout.Alignment.LEADING, 

layout.createSequentialGroup()
                                .addComponent(jLabel10)
                                .addGap(10, 10, 10)
                                .addComponent(costLab, 

javax.swing.GroupLayout.DEFAULT_SIZE, 132, Short.MAX_VALUE))
                            .addGroup

(javax.swing.GroupLayout.Alignment.LEADING, 

layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup

(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel8)
                                    .addComponent(jLabel5)
                                    .addComponent(jLabel6))
                                .addGap(43, 43, 43)
                                .addGroup(layout.createParallelGroup

(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(screenLab, 

javax.swing.GroupLayout.PREFERRED_SIZE, 120, 

javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(movLab, 

javax.swing.GroupLayout.Alignment.TRAILING, 

javax.swing.GroupLayout.PREFERRED_SIZE, 120, 

javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(stLab, 

javax.swing.GroupLayout.PREFERRED_SIZE, 120, 

javax.swing.GroupLayout.PREFERRED_SIZE)))
                            .addComponent(classCB, 

javax.swing.GroupLayout.Alignment.LEADING, 

javax.swing.GroupLayout.PREFERRED_SIZE, 

javax.swing.GroupLayout.DEFAULT_SIZE, 

javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(SeatsCB, 

javax.swing.GroupLayout.Alignment.LEADING, 

javax.swing.GroupLayout.PREFERRED_SIZE, 

javax.swing.GroupLayout.DEFAULT_SIZE, 

javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(37, 37, 37)
                        .addGroup(layout.createParallelGroup

(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel12)
                                .addGap(9, 9, 9)
                                .addGroup(layout.createParallelGroup

(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(LastSeatRowLabel, 

javax.swing.GroupLayout.PREFERRED_SIZE, 27, 

javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jLabel24))
                                .addGap(33, 33, 33)
                                .addGroup(layout.createParallelGroup

(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(LastSeatNoLabel, 

javax.swing.GroupLayout.PREFERRED_SIZE, 29, 

javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jLabel7, 

javax.swing.GroupLayout.Alignment.TRAILING)))
                            .addComponent(jLabel28)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel29)
                                .addGap(18, 18, 18)
                                .addComponent(s1Lab, 

javax.swing.GroupLayout.PREFERRED_SIZE, 62, 

javax.swing.GroupLayout.PREFERRED_SIZE)))))
                .addContainerGap())
            .addComponent(title, javax.swing.GroupLayout.DEFAULT_SIZE, 

817, Short.MAX_VALUE)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, 

layout.createSequentialGroup()
                .addContainerGap(732, Short.MAX_VALUE)
                .addComponent(statBtn)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup

(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(title)
                .addGap(12, 12, 12)
                .addComponent(statBtn)
                .addPreferredGap

(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup

(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel24)
                        .addPreferredGap

(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(LastSeatRowLabel, 

javax.swing.GroupLayout.PREFERRED_SIZE, 19, 

javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jLabel12)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel7)
                        .addPreferredGap

(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(LastSeatNoLabel))
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, 

layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup

(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(addRecord, 

javax.swing.GroupLayout.PREFERRED_SIZE, 28, 

javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(delRecord, 

javax.swing.GroupLayout.PREFERRED_SIZE, 28, 

javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap

(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jScrollPane1, 

javax.swing.GroupLayout.DEFAULT_SIZE, 349, Short.MAX_VALUE))
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, 

layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup

(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel8)
                                .addGap(32, 32, 32)
                                .addComponent(jLabel6)
                                .addGap(25, 25, 25)
                                .addComponent(jLabel5))
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup

(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addGroup

(layout.createSequentialGroup()
                                        .addComponent(jLabel28)
                                        .addGap(18, 18, 18)
                                        .addGroup

(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(s1Lab, 

javax.swing.GroupLayout.PREFERRED_SIZE, 14, 

javax.swing.GroupLayout.PREFERRED_SIZE)
                                            .addComponent(jLabel29)))
                                    .addGroup

(layout.createSequentialGroup()
                                        .addComponent(movLab, 

javax.swing.GroupLayout.PREFERRED_SIZE, 21, 

javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(18, 18, 18)
                                        .addComponent(stLab, 

javax.swing.GroupLayout.PREFERRED_SIZE, 21, 

javax.swing.GroupLayout.PREFERRED_SIZE)))
                                .addGap(18, 18, 18)
                                .addComponent(screenLab, 

javax.swing.GroupLayout.PREFERRED_SIZE, 21, 

javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addGap(32, 32, 32)
                        .addComponent(jLabel9)
                        .addPreferredGap

(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(classCB, 

javax.swing.GroupLayout.PREFERRED_SIZE, 

javax.swing.GroupLayout.DEFAULT_SIZE, 

javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jLabel11)
                        .addPreferredGap

(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(SeatsCB, 

javax.swing.GroupLayout.PREFERRED_SIZE, 

javax.swing.GroupLayout.DEFAULT_SIZE, 

javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap

(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 50, 

Short.MAX_VALUE)
                        .addGroup(layout.createParallelGroup

(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel10)
                            .addComponent(costLab, 

javax.swing.GroupLayout.PREFERRED_SIZE, 31, 

javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addComponent(bookNowBtn, 

javax.swing.GroupLayout.PREFERRED_SIZE, 54, 

javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>

    private void classCBActionPerformed(java.awt.event.ActionEvent evt) 

{                                        
    int cost =   classCB.getSelectedIndex();
    
    int costExecutive = (cost+1)*100;    
    
    
    costLab.setText("Rs. "+costExecutive);
        
        
        
        
        // TODO add your handling code here:
}                                       

    private void delRecordActionPerformed(java.awt.event.ActionEvent 

evt) {                                          
String mov  = movLab.getText();


    if (mov.equals(""))
    JOptionPane.showMessageDialog(null,"Please Select a Record to 

Delete","SELECT RECORD",JOptionPane.ERROR_MESSAGE);

    else    {
        
    try{

    
        
Class.forName("java.sql.DriverManager");

Connection con = (Connection)
        
DriverManager.getConnection ("jdbc:mysql://localhost:3306/cbse","root", 

"tiger");

Statement stmt = (Statement) con.createStatement();

String query="DELETE FROM singlemayajaal WHERE MOVIE ="+"'"+mov+"'"+";";

stmt.executeUpdate(query);

JOptionPane.showMessageDialog (this,"Movie Deleted Successfully");  



    
    }


catch(Exception e)

{
JOptionPane.showMessageDialog(null,"Something is Wrong.Please try 

again.","ERROR IN CONNECTIVITY",JOptionPane.ERROR_MESSAGE);
}
      
                                            
        
        
        
        
        
    }        
        
}                                         

    private void addRecordActionPerformed(java.awt.event.ActionEvent 

evt) {                                          
passDialog.setVisible(true);
         
        
}                                         

    
    
    
    
    private void bookNowBtnActionPerformed(java.awt.event.ActionEvent 

evt) {                                           

String movie = movLab.getText();
String sel = (String)SeatsCB.getSelectedItem();

if (movie.equals(""))
    JOptionPane.showMessageDialog(this,"Please select a Movie first");
  

else if(sel.equals("-----No of Seats-----"))
    JOptionPane.showMessageDialog(this,"Please select Number of Seats 

Required" );

          
else{

try
    
{   
   
 int num = Integer.parseInt(sel);
       
             
       int lastnum = Integer.parseInt(LastSeatNoLabel.getText());
       String lastrow = LastSeatRowLabel.getText()    ;
       SeatNosLabel.setText("");
       if ( lastrow.compareTo("-") == 0 )
            lastrow = "1";
       
       int x, seatrow;
       for (x=0; x<num; ++x){
           lastnum++;
           if (lastnum > 26){
                if ( lastrow.compareTo("9") == 0 ){
                    String text1= SeatNosLabel.getText();
                    SeatNosLabel.setText(text1+ "House Full!");
                    break;
                }
               else{
                  lastnum = 1;
                  seatrow = Integer.parseInt(lastrow)+1;
                  lastrow = (""+seatrow);
                }
            }
                String text1= SeatNosLabel.getText();
                if (lastnum<=9 ){
                  SeatNosLabel.setText(text1+lastrow+"0"+lastnum+", " );
                 
                }
                else
                    SeatNosLabel.setText(text1+lastrow+lastnum+", " );
       }         
           LastSeatRowLabel.setText(lastrow);
           LastSeatNoLabel.setText(""+lastnum);
      
        
            
        
        
String mov = movLab.getText();   
String st = stLab.getText();
String screen = screenLab.getText();
String executiveClass = (String) classCB.getSelectedItem();
String cost = costLab.getText();
String ticketno = (String)SeatsCB.getSelectedItem();
        
int res = JOptionPane.showConfirmDialog(null,"Are you sure want to book 

for this movie?"+
        "\n\nBooking Summary:"+"\n--------------------------------"+
        "\n"+"Movie: "+mov+
        "\n"+"ShowTime: "+st+
        "\n"+"Screen: "+screen+
        "\n"+"Class: "+executiveClass+
        "\n"+"No. of Tickets: "+ticketno+
        "\n"+"Grand Total: "+cost); 

int remSeat = Integer.parseInt(s1Lab.getText());

int newremSeat = remSeat-num;

if (res == JOptionPane.YES_OPTION)

    
s1Lab.setText(""+newremSeat);

successDialog.setVisible(true);

sumMovLab.setText(mov);
sumShowTimeLab.setText(st);
displayMonthDayYear();
sumScreenLab.setText(screen);
sumClassLab.setText(executiveClass);
sumNoFTicketsLab.setText(ticketno);
sumGrandLab.setText(cost);


if (res == JOptionPane.NO_OPTION)
    successDialog.setVisible(false);

if (res == JOptionPane.CANCEL_OPTION)
    successDialog.setVisible(false);     
         
        
if (res == JOptionPane.CLOSED_OPTION)        
 successDialog.setVisible(false);    
  
       
}                                          
catch(Exception e)


{JOptionPane.showMessageDialog (null,"Something is Wrong.Please check 

whether all fields are filled properly");}

}

    }
    private void movTableMouseClicked(java.awt.event.MouseEvent evt) {   

                                   
int row = movTable.getSelectedRow();
Object a = movTable.getValueAt(row, 0);
Object b = movTable.getValueAt(row, 1);
Object c = movTable.getValueAt(row, 2);
Object d = movTable.getValueAt(row, 3);
        
    
    movLab.setText(""+d);
        
    stLab.setText(""+a);
    
    screenLab.setText(""+c);


               
                                    // TODO add your handling code here:
    }                                     

    private void SeatsCBActionPerformed(java.awt.event.ActionEvent evt) 

{                                        

int cost = 100;

int x = SeatsCB.getSelectedIndex();

int i =0;

switch(x){
    
 case 1: i = 1 * cost; break;
 case 2: i = 2 * cost; break;
 case 3: i = 3 * cost; break;
 case 4: i = 4 * cost; break;
 case 5: i = 5 * cost; break;
 case 6: i = 6 * cost; break;
 case 7: i = 7 * cost; break;
 case 8: i = 8 * cost; break;
 case 9: i = 9 * cost; break;
 case 10: i = 10 * cost; break;
    
 
}

costLab.setText("Rs. "+i);   



// TODO add your handling code here:
}                                       

    private void etTFActionPerformed(java.awt.event.ActionEvent evt) {   

                                  
        // TODO add your handling code here:
}                                    

    private void stTFActionPerformed(java.awt.event.ActionEvent evt) {   

                                  
        // TODO add your handling code here:
}                                    

    private void screenTFActionPerformed(java.awt.event.ActionEvent evt) 

{                                         
        // TODO add your handling code here:
}                                        

    private void movTFActionPerformed(java.awt.event.ActionEvent evt) {  

                                    
        // TODO add your handling code here:
}                                     

    private void cancel1ActionPerformed(java.awt.event.ActionEvent evt) 

{                                        
       
        
successDialog.dispose(); 

// TODO add your handling code here:
    }                                       

    private void passFieldActionPerformed(java.awt.event.ActionEvent 

evt) {                                          
        // TODO add your handling code here:
    }                                         

    private void passSubmitActionPerformed(java.awt.event.ActionEvent 

evt) {                                           
String pass = new String(passField.getPassword());
int res=0;
if (pass.equals("tiger")){
    addDialog.setVisible(true);
    if (res == JOptionPane.OK_OPTION){
        passDialog.dispose();}
        }
else
  JOptionPane.showMessageDialog(null,"Wrong Password");
        
       
    }                                          

    private void addBtnActionPerformed(java.awt.event.ActionEvent evt) { 

                                      
String movie = movTF.getText();
String screen = screenTF.getText();
String showTime = stTF.getText();
String endTime = etTF.getText();
    
 if (movie.equals(""))
    JOptionPane.showMessageDialog(this,"Movie Not Entered");
  
else if(screen.equals(""))
    JOptionPane.showMessageDialog(this,"Language Not Entered");

else if(showTime.equals(""))
    JOptionPane.showMessageDialog(this,"ShowTime Not Entered");

   
   

else{

try
{
    
        
Class.forName("java.sql.DriverManager");

Connection con = (Connection)
        
DriverManager.getConnection ("jdbc:mysql://localhost:3306/cbse","root", 

"tiger");

Statement stmt = (Statement) con.createStatement();

String query="INSERT INTO singlemayajaal VALUES ('"+showTime

+"','"+endTime+"','"+screen+"','"+movie+"');";
stmt.executeUpdate(query);

JOptionPane.showMessageDialog (this,"Movie Added Successfully");  




movTF.setText("");
screenTF.setText("");
stTF.setText("");
etTF.setText("");

    
    }


catch(Exception e)

{
JOptionPane.showMessageDialog (null,"Something is Wrong.Please check 

whether all fields are filled properly");
}

}     
    }                                      

private void statBtnActionPerformed(java.awt.event.ActionEvent evt) {    

                                    

statDialog.setVisible(true);
    
}                                       

    
       
   

void displayMonthDayYear() {
        //
        // Display a date in month, day, year format
        //
        Date date = Calendar.getInstance().getTime();
        DateFormat formatter = new SimpleDateFormat("MM/dd/yyyy");
        String today = formatter.format(date);
        sumDateLab.setText(""+today);   
        
        
SimpleDateFormat sdf = new SimpleDateFormat("hh:mm a");
java.util.Date dd = new java.util.Date();
String s = sdf.format(dd);
dateLab.setText(s);    
}
              
         

    
    
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new Single_Plex_1_Copy().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify
    private javax.swing.JLabel LastSeatNoLabel;
    private javax.swing.JLabel LastSeatRowLabel;
    private javax.swing.JLabel SeatNosLabel;
    private javax.swing.JComboBox SeatsCB;
    private javax.swing.JButton addBtn;
    private javax.swing.JDialog addDialog;
    private javax.swing.JButton addRecord;
    private javax.swing.JButton bookNowBtn;
    private javax.swing.JButton cancel1;
    private javax.swing.JComboBox classCB;
    private javax.swing.JLabel costLab;
    private javax.swing.JLabel dateLab;
    private javax.swing.JButton delRecord;
    private javax.swing.JTextField etTF;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel18;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel24;
    private javax.swing.JLabel jLabel25;
    private javax.swing.JLabel jLabel26;
    private javax.swing.JLabel jLabel27;
    private javax.swing.JLabel jLabel28;
    private javax.swing.JLabel jLabel29;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel30;
    private javax.swing.JLabel jLabel31;
    private javax.swing.JLabel jLabel32;
    private javax.swing.JLabel jLabel33;
    private javax.swing.JLabel jLabel34;
    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.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JTable jTable1;
    private javax.swing.JLabel movLab;
    private javax.swing.JTextField movTF;
    private javax.swing.JTable movTable;
    private javax.swing.JDialog passDialog;
    private javax.swing.JPasswordField passField;
    private javax.swing.JButton passSubmit;
    private javax.swing.JLabel s1Lab;
    private javax.swing.JLabel screenLab;
    private javax.swing.JTextField screenTF;
    private javax.swing.JLabel stLab;
    private javax.swing.JTextField stTF;
    private javax.swing.JButton statBtn;
    private javax.swing.JDialog statDialog;
    private javax.swing.JDialog successDialog;
    private javax.swing.JLabel sumClassLab;
    private javax.swing.JLabel sumDateLab;
    private javax.swing.JLabel sumGrandLab;
    private javax.swing.JLabel sumMovLab;
    private javax.swing.JLabel sumNoFTicketsLab;
    private javax.swing.JLabel sumScreenLab;
    private javax.swing.JLabel sumShowTimeLab;
    private javax.swing.JLabel title;
    private javax.swing.JLabel titleLab1;
    private javax.swing.JLabel titleLab2;
    // End of variables declaration
}

Open in new window

0
 
LVL 47

Expert Comment

by:for_yan
ID: 37143262


So, when you'are processing the input, say before you go to database, something like that should be done:

----------------------------------------------------
else{
//addition
DefaultTableModel mdl = (DefaultTableModel)movTable.getModel();

Vector v = new Vector();
v.add(movie);
v.add(screen);
v.add(showTime);
v.add(endTime);


mdl.addRow(v);

movTable.setModel(mdl);  // actually I think you would not need to do this, but if the view does not cvhange then try this
// end addition
try
{
   
       
Class.forName("java.sql.DriverManager");

--------------------
give it a try
0
 

Author Comment

by:octoberqueen
ID: 37143349
since vector is obsolete and deprecated, I used arraylist

Instead of

else{
//addition
DefaultTableModel mdl = (DefaultTableModel)movTable.getModel();

Vector v = new Vector();
v.add(movie);
v.add(screen);
v.add(showTime);
v.add(endTime);

Like this:

DefaultTableModel mdl = (DefaultTableModel)movTable.getModel();

ArrayList arrayList = new ArrayList();

arrayList.add(movie);
arrayList.add(screen);
arrayList.add(showTime);
arrayList.add(endTime);

However I can't add row to tablemodel. I think there should be some conversion.
0
 
LVL 47

Expert Comment

by:for_yan
ID: 37143363
Vector is not deprected - you can absolutely use it
http://download.oracle.com/javase/1.5.0/docs/api/javax/swing/table/DefaultTableModel.html#addRow%28java.util.Vector%29

YOu can add array:
public void addRow(Object[] rowData)


Object [] oo = new Object[4];
oo[0] = movie;
oo[1] = screen;
...

mdl.addRow(oo);




0
 

Author Comment

by:octoberqueen
ID: 37143448
I am thinking of adding an update button to my window.
There will be no rows present in my visible jtable when the program is compiled and run.
When I click the jButton-UPDATE, all records should be obtained from mysql database table and gets filled in jTable.

I also want to add a simple percentage progress during this process.
The progress bar should get displayed when i click the button and when it finishes, the JTable should be updated with rows.
0
 
LVL 47

Expert Comment

by:for_yan
ID: 37143467
Did it add the row ?
0
 

Author Comment

by:octoberqueen
ID: 37143475
Yes, thank you friend for that.
0
 
LVL 47

Expert Comment

by:for_yan
ID: 37143480
Good!

There is no problem with having the button, retriving data from MySql and adding them
in this way, as we did with one row.
Unless you are going to load thousands, I don't think you need progress bar.
At least first implement the actual loading and then you'll see
if you need a progress bar.
0
 

Author Comment

by:octoberqueen
ID: 37143619
How to get table rows updated in JTable without providing an update button i.e at the moment program gets compiled and run, the rows from mysql database table should be present there.
0
 
LVL 47

Expert Comment

by:for_yan
ID: 37143629
You should do the same thing as we did but associated with the constructor of your frame (say, have  method, called from the constructor,
which would load the data and populate the model in the same way we did it, but eve before you set your whole frame conatining Jtable visible).
then at the moment when you setVisible(true), it will appear already populated.
This is actually how in majority of cases such application would be normally designed.
0
 

Author Comment

by:octoberqueen
ID: 37143715
How can do it? Where should I write the code?
Where is this frame constructor?
0
 
LVL 47

Expert Comment

by:for_yan
ID: 37143743

I am not familiar with this NetBeans weird stuff,
but I believe you can add it after initComponents() method:

   public Single_Plex_1_Copy() {
        initComponents();
   <--------- here you can add method which would read the data form database and populate table model the way we did it in event handler

    }

0
 
LVL 47

Expert Comment

by:for_yan
ID: 37143777
that's waht they write in netbeans Wiki:
http://wiki.netbeans.org/FaqFormEditingGuardedBlocks
------
However, please note that you can easily write your code out of the guarded block, typically into the constructor after the initComponents() method call, as additional setup code that should be performed. This option is often forgotten, but it is the most eficient and easiset way to add custom code, working in most situation (e.g. except custom instantiation code).
-------

So, I understand, my guess in the above posting was correct.
0
 

Author Comment

by:octoberqueen
ID: 37143796
Yes it worked. Thanks again.
0
 
LVL 47

Expert Comment

by:for_yan
ID: 37143798
Great!
0
 

Author Comment

by:octoberqueen
ID: 37143949
This is the source code of my main algorithm in book now button:

try
    
{   
   
 int num = Integer.parseInt(sel);
       
             
       int lastnum = Integer.parseInt(LastSeatNoLabel.getText());
       String lastrow = LastSeatRowLabel.getText()    ;
       SeatNosLabel.setText("");
       if ( lastrow.compareTo("-") == 0 )
            lastrow = "1";
       
       int x, seatrow;
       for (x=0; x<num; ++x){
           lastnum++;
           if (lastnum > 26){
                if ( lastrow.compareTo("9") == 0 ){
                    String text1= SeatNosLabel.getText();
                    SeatNosLabel.setText(text1+ "House Full!");
                    break;
                }
               else{
                  lastnum = 1;
                  seatrow = Integer.parseInt(lastrow)+1;
                  lastrow = (""+seatrow);
                }
            }
                String text1= SeatNosLabel.getText();
                if (lastnum<=9 ){
                  SeatNosLabel.setText(text1+lastrow+"0"+lastnum+", " );
                 
                }
                else
                    SeatNosLabel.setText(text1+lastrow+lastnum+", " );
       }         
           LastSeatRowLabel.setText(lastrow);
           LastSeatNoLabel.setText(""+lastnum);

Open in new window


I have a total of 234 seats for each show.

This is the dialog box showing booking confirmation:

String mov = movLab.getText();   
String st = stLab.getText();
String screen = screenLab.getText();
String executiveClass = (String) classCB.getSelectedItem();
String cost = costLab.getText();
String ticketno = (String)SeatsCB.getSelectedItem();
        
int res = JOptionPane.showConfirmDialog(null,"Are you sure want to book for this movie?"+
        "\n\nBooking Summary:"+"\n--------------------------------"+
        "\n"+"Movie: "+mov+
        "\n"+"ShowTime: "+st+
        "\n"+"Screen: "+screen+
        "\n"+"Class: "+executiveClass+
        "\n"+"No. of Tickets: "+ticketno+
        "\n"+"Grand Total: "+cost); 

int remSeat = Integer.parseInt(s1Lab.getText());

int newremSeat = remSeat-num;

if (res == JOptionPane.YES_OPTION)

    
s1Lab.setText(""+newremSeat);

successDialog.setVisible(true);

sumMovLab.setText(mov);
sumShowTimeLab.setText(st);
displayMonthDayYear();
sumScreenLab.setText(screen);
sumClassLab.setText(executiveClass);
sumNoFTicketsLab.setText(ticketno);
sumGrandLab.setText(cost);


if (res == JOptionPane.NO_OPTION)
    successDialog.setVisible(false);

if (res == JOptionPane.CANCEL_OPTION)
    successDialog.setVisible(false);     
         
        
if (res == JOptionPane.CLOSED_OPTION)        
 successDialog.setVisible(false);    
  
       
}                                          
catch(Exception e)


{JOptionPane.showMessageDialog (null,"Something is Wrong.Please check whether all fields are filled properly");}

}

    }
    private void movTableMouseClicked(java.awt.event.MouseEvent evt) {                                      
int row = movTable.getSelectedRow();
Object showTime = movTable.getValueAt(row, 0);
Object endTime = movTable.getValueAt(row, 1);
Object screen = movTable.getValueAt(row, 2);
Object movie = movTable.getValueAt(row, 3);
 
    
    movLab.setText(""+movie);
        
    stLab.setText(""+showTime);
    
    screenLab.setText(""+screen);

}

Open in new window


Note: LastSeatNoLabel and LastSeatRowLabel are used to display filled seats and rows respectively.
I think I messed up in this part because even if click no or cancel in confirmation dialog, the  LastSeatNoLabel aad LastSeatRowLabel  values gets incremented. How can I correct?
I don't want to change values in  LastSeatNoLabel and LastSeatRowLabel  if no booking takes place.
0
 
LVL 47

Expert Comment

by:for_yan
ID: 37143980
I don't understand your code;
 where is your dialog opened - I see method mouseClicked - it ends with nothing - can't understand
0
 

Author Comment

by:octoberqueen
ID: 37144053
This is my entire source code for book now button:

 
String movie = movLab.getText();
String sel = (String)SeatsCB.getSelectedItem();

if (movie.equals(""))
    JOptionPane.showMessageDialog(this,"Please select a Movie first");
  

else if(sel.equals("-----No of Seats-----"))
    JOptionPane.showMessageDialog(this,"Please select Number of Seats Required" );

          
else{

try
    
{   
   
 int num = Integer.parseInt(sel);
       
             
       int lastnum = Integer.parseInt(LastSeatNoLabel.getText());
       String lastrow = LastSeatRowLabel.getText()    ;
       SeatNosLabel.setText("");
       if ( lastrow.compareTo("-") == 0 )
            lastrow = "1";
       
       int x, seatrow;
       for (x=0; x<num; ++x){
           lastnum++;
           if (lastnum > 26){
                if ( lastrow.compareTo("9") == 0 ){
                    String text1= SeatNosLabel.getText();
                    SeatNosLabel.setText(text1+ "House Full!");
                    break;
                }
               else{
                  lastnum = 1;
                  seatrow = Integer.parseInt(lastrow)+1;
                  lastrow = (""+seatrow);
                }
            }
                String text1= SeatNosLabel.getText();
                if (lastnum<=9 ){
                  SeatNosLabel.setText(text1+lastrow+"0"+lastnum+", " );
                 
                }
                else
                    SeatNosLabel.setText(text1+lastrow+lastnum+", " );
       }         
           LastSeatRowLabel.setText(lastrow);
           LastSeatNoLabel.setText(""+lastnum);
      
        
            
        
        
String mov = movLab.getText();   
String st = stLab.getText();
String screen = screenLab.getText();
String executiveClass = (String) classCB.getSelectedItem();
String cost = costLab.getText();
String ticketno = (String)SeatsCB.getSelectedItem();
        
int res = JOptionPane.showConfirmDialog(null,"Are you sure want to book for this movie?"+
        "\n\nBooking Summary:"+"\n--------------------------------"+
        "\n"+"Movie: "+mov+
        "\n"+"ShowTime: "+st+
        "\n"+"Screen: "+screen+
        "\n"+"Class: "+executiveClass+
        "\n"+"No. of Tickets: "+ticketno+
        "\n"+"Grand Total: "+cost); 

int remSeat = Integer.parseInt(s1Lab.getText());

int newremSeat = remSeat-num;

if (res == JOptionPane.YES_OPTION)

    
s1Lab.setText(""+newremSeat);

successDialog.setVisible(true);

sumMovLab.setText(mov);
sumShowTimeLab.setText(st);
displayMonthDayYear();
sumScreenLab.setText(screen);
sumClassLab.setText(executiveClass);
sumNoFTicketsLab.setText(ticketno);
sumGrandLab.setText(cost);


if (res == JOptionPane.NO_OPTION)
    successDialog.setVisible(false);

if (res == JOptionPane.CANCEL_OPTION)
    successDialog.setVisible(false);     
         
        
if (res == JOptionPane.CLOSED_OPTION)        
 successDialog.setVisible(false);    
  
       
}                                          
catch(Exception e)


{JOptionPane.showMessageDialog (null,"Something is Wrong.Please check whether all fields are filled properly");}

}

    }
    private void movTableMouseClicked(java.awt.event.MouseEvent evt) {                                      
int row = movTable.getSelectedRow();
Object showTime = movTable.getValueAt(row, 0);
Object endTime = movTable.getValueAt(row, 1);
Object screen = movTable.getValueAt(row, 2);
Object movie = movTable.getValueAt(row, 3);
 
    
    movLab.setText(""+movie);
        
    stLab.setText(""+showTime);
    
    screenLab.setText(""+screen);
 
    }                             

Open in new window


Have you understood LastSeatNoLabel and LastSeatRowLabel Labels?
My theatre has 9 rows, each having 26 seats. Seats are allocated from 101 to 126(1st row), then 201 to 226(2nd row) and so on. Seats from a nex row can only be sold if previous row has been fully sold out. No seats can be sold beyond seat numbered 926.
0
 

Author Comment

by:octoberqueen
ID: 37144458
for_yan, are you there? I have been waiting for long.
0
 
LVL 47

Expert Comment

by:for_yan
ID: 37144494
I don't understand what you want there  - and don't understand what is the full picture of interaction
with the user and what event starts it, and don't see the code corresponding to this event handling
0
 
LVL 47

Expert Comment

by:for_yan
ID: 37144527
I don't think I need to know how many rows and seats.
I need to know who click what and what dialog pops up, and
which code corresponds to those events
 
0
 

Author Comment

by:octoberqueen
ID: 37144565
In this project window
 mayajaal-main-window
Under the Book Now Button, the following codes are written:

 private void bookNowBtnActionPerformed(java.awt.event.ActionEvent evt) {                                           

String movie = movLab.getText();
String sel = (String)SeatsCB.getSelectedItem();

if (movie.equals(""))
    JOptionPane.showMessageDialog(this,"Please select a Movie first");
  

else if(sel.equals("-----No of Seats-----"))
    JOptionPane.showMessageDialog(this,"Please select Number of Seats Required" );

          
else{

try
    
{   
   
 int num = Integer.parseInt(sel);
       
             
       int lastnum = Integer.parseInt(LastSeatNoLabel.getText());
       String lastrow = LastSeatRowLabel.getText()    ;
       SeatNosLabel.setText("");
       if ( lastrow.compareTo("-") == 0 )
            lastrow = "1";
       
       int x, seatrow;
       for (x=0; x<num; ++x){
           lastnum++;
           if (lastnum > 26){
                if ( lastrow.compareTo("9") == 0 ){
                    String text1= SeatNosLabel.getText();
                    SeatNosLabel.setText(text1+ "House Full!");
                    break;
                }
               else{
                  lastnum = 1;
                  seatrow = Integer.parseInt(lastrow)+1;
                  lastrow = (""+seatrow);
                }
            }
                String text1= SeatNosLabel.getText();
                if (lastnum<=9 ){
                  SeatNosLabel.setText(text1+lastrow+"0"+lastnum+", " );
                 
                }
                else
                    SeatNosLabel.setText(text1+lastrow+lastnum+", " );
       }         
           LastSeatRowLabel.setText(lastrow);
           LastSeatNoLabel.setText(""+lastnum);
      
        
            
        
        
String mov = movLab.getText();   
String st = stLab.getText();
String screen = screenLab.getText();
String executiveClass = (String) classCB.getSelectedItem();
String cost = costLab.getText();
String ticketno = (String)SeatsCB.getSelectedItem();
        
int res = JOptionPane.showConfirmDialog(null,"Are you sure want to book for this movie?"+
        "\n\nBooking Summary:"+"\n--------------------------------"+
        "\n"+"Movie: "+mov+
        "\n"+"ShowTime: "+st+
        "\n"+"Screen: "+screen+
        "\n"+"Class: "+executiveClass+
        "\n"+"No. of Tickets: "+ticketno+
        "\n"+"Grand Total: "+cost); 

int remSeat = Integer.parseInt(s1Lab.getText());

int newremSeat = remSeat-num;

if (res == JOptionPane.YES_OPTION)

    
s1Lab.setText(""+newremSeat);

successDialog.setVisible(true);

sumMovLab.setText(mov);
sumShowTimeLab.setText(st);
displayMonthDayYear();
sumScreenLab.setText(screen);
sumClassLab.setText(executiveClass);
sumNoFTicketsLab.setText(ticketno);
sumGrandLab.setText(cost);


if (res == JOptionPane.NO_OPTION)
    successDialog.setVisible(false);

if (res == JOptionPane.CANCEL_OPTION)
    successDialog.setVisible(false);     
         
        
if (res == JOptionPane.CLOSED_OPTION)        
 successDialog.setVisible(false);    
  
       
}                                          
catch(Exception e)


{JOptionPane.showMessageDialog (null,"Something is Wrong.Please check whether all fields are filled properly");}

}

    }
    private void movTableMouseClicked(java.awt.event.MouseEvent evt) {                                      
int row = movTable.getSelectedRow();
Object showTime = movTable.getValueAt(row, 0);
Object endTime = movTable.getValueAt(row, 1);
Object screen = movTable.getValueAt(row, 2);
Object movie = movTable.getValueAt(row, 3);
 
    
    movLab.setText(""+movie);
        
    stLab.setText(""+showTime);
    
    screenLab.setText(""+screen);
 
    }                        

Open in new window


I found the code to be wrong because even if no booking takes place i.e if I press NO or CANCEL option in confirmation dialog, the LastSeatNoLabel and LastSeatRowLabel Labels are getting incremented. It should happen only when the booking is done.
0
 

Author Comment

by:octoberqueen
ID: 37144648
I use this code
String showTime = stTF.getText();
String endTime = etTF.getText();
String movie = movTF.getText();
String screen = screenTF.getText();

SimpleDateFormat sdf = new SimpleDateFormat("hh:mm a");
java.util.Date stNew = sdf.parse(showTime, new ParsePosition(0));
java.util.Date etNew = sdf.parse(endTime, new ParsePosition(0));
        



 if (movie.equals(""))
    JOptionPane.showMessageDialog(this,"Movie Not Entered");
  
else if(screen.equals(""))
    JOptionPane.showMessageDialog(this,"Language Not Entered");

else if(showTime.equals(""))
    JOptionPane.showMessageDialog(this,"ShowTime Not Entered");

   
   

else{
 //addition
DefaultTableModel mdl = (DefaultTableModel)movTable.getModel();

//addition
Vector v = new Vector();
 
v.add(showTime);
v.add(endTime);
v.add(screen);
v.add(movie);

mdl.addRow(v);
movTable.setModel(mdl);
//end addition

Open in new window


and now I can successful insert time values into mysql database.

However I want to input time in 12:00 PM instead of 12:00:00 or 3:00 PM instead of 15:00:00. What should I do?
0
 

Author Comment

by:octoberqueen
ID: 37144654
Sorry I made a mistake. Actually the comment should be placed in my other question- "Dispaly current System time in Netbeans."

Also, don't forget to answer my last question(above previous comment) regarding wrong code.

0
 
LVL 47

Expert Comment

by:for_yan
ID: 37144658
when you insert date into database you not inserting eoither 3:00 PM or 15:00:00 - you are entering
date object - it is the matter how you formmat it later on when you retrieve it; the underlying object under 15:00 and 3:00 PM is the same
0
 
LVL 47

Expert Comment

by:for_yan
ID: 37144680
This is very strange pice:

if (res == JOptionPane.YES_OPTION)

   
s1Lab.setText(""+newremSeat);

Even though it is written in this starne way, in fact it is:

if (res == JOptionPane.YES_OPTION)s1Lab.setText(""+newremSeat);

so if it is yes it will execute this one instruction

and then we see a bunch of instructions below which will be executed no matter what you read YES or NO

This is strange logic.

I'd think - if response is NO or Cancel (why do you need both No and Cancel ?)
then it should just return and do nothing,
otherwise you ned to do some upodating

So I believe, these consditions should be managed
correctly.











0
 

Author Comment

by:octoberqueen
ID: 37145412
I got the above problem solved. Thank you friend.
-----

I am not achieving any success with time conversion.

I set my SHOWTIME & ENDTIME columns in MySQL to date format, which is in '00:00:00'

I understand that when I enter '3 PM' in showTime Texfield, it needs to get converted into '15:00:00'. How can I do it?
0
 
LVL 47

Expert Comment

by:for_yan
ID: 37145812
I showed you in that question.
>It needs to be converted to 15:00:00
This is incorrect.
What you really need is to be sure that the format of the string is predefined - aal the time the same - and then you need to convert the string into Date object using the simpole date format parser as I showed. Once you have Date object it does not have format - Date object produced from 3 PM and from 15:00 are two identical objects. Once you have Date object you can insert it into dataabse using prepared statement as I showed. When you later retrieve Date - again with JDbC you are retrieving Date object. Onle right before you need to show it using format method of simpledateformat you generate string out of that object in the format you want. You first need to understand this differnece between format of presenbtation as a printable string on the one hand and date object on the other hand. And then explin what piece of that process is not working for you.
0
 
LVL 47

Expert Comment

by:for_yan
ID: 37145961
Understand this:

String dateString1 = "3:00 PM";

SimpleDateFormat sdf1 = new SimpleDateFormat("hh:mm a");

java.util.Date dd1 = sdf1.parse(dateString1, new ParsePosition(0));


and


String dateString2 = "15:00:00";

SimpleDateFormat sdf2 = new SimpleDateFormat("HH:mm:ss");

java.util.Date dd2 = sdf2.parse(dateString2, new ParsePosition(0));

  now dd1 and dd2 are identical objects

dd1.equals(dd2)  is true

they represent the same date

you store them in any database - see my isntruction with PreparedStatement - they are sitting in databse
and representing the same date

then you retrive them from database

ResultSet rs = stamement.execueQuqry("select show_date from..."

java.util.Date dd = rs.getDate("show_date");

dd is again Date object - it will be the same if you stored the dd1 or dd2 object initially, as those are the same
objects.

Only when you want to show you format it


String s1 = sdf1.format(dd);

String s2 = sdf2.fromat(dd);

Now s1 will be "3:00 PM" and s2 will be "15:00:00" - so s1 and s2 will be different strings because we formatted the same Date
object in different ways using different uinstances of SimleDateFormat class created with different constructors (see above).

So why do we need fro m user that the user follows strictly format when they eneter ths date?

Because we need to know how to construct the SimpoleDateFormat object which we'll use for parsing the input
to obtain date object which we can store .etc.

Once we got to that object it is already irrelevant which was the format that it was represented initially and we can store retriev it and again format
it in any way we want, no matter what was initil format this object was communicated to us by the user.








0
 

Author Comment

by:octoberqueen
ID: 37149519
This is a part of mycode written in ADD Button:

addBtnActionPerformed(java.awt.event.ActionEvent evt) {                                      
String showTime = stTF.getText();
String endTime = etTF.getText();
String movie = movTF.getText();
String screen = screenTF.getText();

SimpleDateFormat sdf = new SimpleDateFormat("hh:mm:ss");
try{Date stNew = sdf.parse(showTime);
 }
   
catch(Exception e)

{
JOptionPane.showMessageDialog (null,"Something is Wrong.Please check whether all fields are filled properly");
}

I can't write the code without writing a try & catch exception. Why?
0
 
LVL 47

Expert Comment

by:for_yan
ID: 37149531

Because there may be format exeception method parse throws exeception,
so compiler requires you to tae care of the possible exception
0
 

Author Comment

by:octoberqueen
ID: 37149550
This will my needed code to be written:

 
String showTime = stTF.getText();
String endTime = etTF.getText();
String movie = movTF.getText();
String screen = screenTF.getText();


SimpleDateFormat sdf = new SimpleDateFormat("hh:mm:ss");
try{Date stNew = sdf.parse(showTime);
 }
    
catch(Exception e)

{
JOptionPane.showMessageDialog (null,"Something is Wrong.Please check whether all fields are filled properly");
}



 if (movie.equals(""))
    JOptionPane.showMessageDialog(this,"Movie Not Entered");
  
else if(screen.equals(""))
    JOptionPane.showMessageDialog(this,"Language Not Entered");

else if(newSt.equals(""))
    JOptionPane.showMessageDialog(this,"ShowTime Not Entered");

      

else{
 //addition
DefaultTableModel mdl = (DefaultTableModel)movTable.getModel();

Vector v = new Vector();
 
v.add(stNew);
v.add(stNew);
v.add(screen);
v.add(movie);

mdl.addRow(v);
movTable.setModel(mdl);
//end addition
try
{
   
Class.forName("java.sql.DriverManager");

Connection con = (Connection)
        
DriverManager.getConnection ("jdbc:mysql://localhost:3306/cbse","root", "tiger");

Statement stmt = (Statement) con.createStatement();

String query="INSERT INTO singlemayajaal VALUES ('"+stNew+"','"+stNew+"','"+screen+"','"+movie+"');";
stmt.executeUpdate(query);

JOptionPane.showMessageDialog (this,"Movie Added Successfully");  




movTF.setText("");
screenTF.setText("");
stTF.setText("");
etTF.setText("");


    
    }


catch(Exception e)

{
JOptionPane.showMessageDialog (null,"Something is Wrong.Please check whether all fields are filled properly");
}

}

Open in new window


I didn't complete it yet. Please rectify the mistakes.
0
 
LVL 47

Expert Comment

by:for_yan
ID: 37149563
You are not inserting date as Date object into Date field - look, I wrote you several times - that you should do it with PreparedStatement
- it is I guess, in that question -which is about time - find it and make it so that you store it as Date,
otherwise what was the point of parsing the string to date
0
 
LVL 47

Expert Comment

by:for_yan
ID: 37149566
You also need to set up the table in adatabse correspondingly - with date filelds not varchar
0
 
LVL 47

Expert Comment

by:for_yan
ID: 37149579
This is how it should be done in general - modify sql to fit your details

SimpleDateFormat is just a Java class used to transform strings into Date object
Your filed in MySql should be Date.

Should be something like that - but needs debugging:

SimpleDateFormat sdf = new SimpleDateFormat("hh:mm a");
String text = txtField.getText();

java.util.Date dd = sdf.parse(text, new ParsePosition(0));

java.sql.Date dsql = new java.sql.Date(dd.getTime());

PreparedStement pstmt = conn.prepareStatement("insert into table (movie_name, show_date) values (?,?)");

pstmt.setString(1,movie);

pstmt.setString(2,dsql);


pstmt.execute();
0
 
LVL 47

Expert Comment

by:for_yan
ID: 37149585
correction - put String insteadd of Date in the previous posting there



SimpleDateFormat is just a Java class used to transform strings into Date object
Your filed in MySql should be Date.

Should be something like that - but needs debugging:

SimpleDateFormat sdf = new SimpleDateFormat("hh:mm a");
String text = txtField.getText();

java.util.Date dd = sdf.parse(text, new ParsePosition(0));

java.sql.Date dsql = new java.sql.Date(dd.getTime());

PreparedStement pstmt = conn.prepareStatement("insert into table (movie_name, show_date) values (?,?)");

pstmt.setString(1,movie);

pstmt.setDate(2,dsql);


pstmt.execute();
0
 

Author Comment

by:octoberqueen
ID: 37150361
can you tell me any method to print (just for my information) java.sql.Date dsql or   java.util.Date dd   variable in  a textfield or label?
0
 
LVL 47

Expert Comment

by:for_yan
ID: 37150481
you do the same thing with SimpleDateFormat:

SimpleDateFormat sdf = new SimpleDateFormat("hh:mm a");

textfield.setText(sdf.format(dd));

0
 

Author Comment

by:octoberqueen
ID: 37153381
How to refresh Jtable after specified time?
0
 
LVL 47

Expert Comment

by:for_yan
ID: 37154205
you need to make a method refresh() which would analyze contents of your model and modify it based ion the current time
then you shoul open a new thread in constructor or from the same method where you do initial populatioon of your data
and in that thread you should have a loop, like
while(true){
Thread.currentThread().sleep(60000);
refresh();
}

Something like that, I guess, should work
0
 
LVL 47

Expert Comment

by:for_yan
ID: 37154371
To create a new thread you can write a simple class like that:

class BasicThread1 extends Thread {
      Single_Plex_1_Copy  spc;
    public BasicThread1(Single_Plex_1_Copy  spc){
        this.spc = spc;

    }
    // This method is called when the thread runs
    public void run() {
        try{
        while(true){
             Thread.currentThread().sleep(60000);
            spc.refresh();
        }
        }catch(Exception ex){
            ex.printStackTrace();
        }
    }
}

Open in new window


and then in constructor, sa after the method which populates
the data you would write:

       BasicThread1 bt = new BasicThread1(this);
        bt.start();



 
0
 

Author Comment

by:octoberqueen
ID: 37157023
So I should create a new class first. In that I need to write

class BasicThread1 extends Thread {
      Single_Plex_1_Copy  spc;
    public BasicThread1(Single_Plex_1_Copy  spc){
        this.spc = spc;

    }
    // This method is called when the thread runs
    public void run() {
        try{
        while(true){
             Thread.currentThread().sleep(60000);
            spc.refresh();
        }
        }catch(Exception ex){
            ex.printStackTrace();
        }
    }
}

Open in new window


In the source of Single_Plex_1_Copy form, what should I write?

Not realted: How can we find name of a form? So that formname.setvisible(true) method might make it available.
0
 

Author Comment

by:octoberqueen
ID: 37157066
Few errors:
cannot find symbol- error Method Refresh

I believe it is a import problem.

printStackTrace()- What is this? Netbeans is warning that  they should be removed.
0
 
LVL 47

Expert Comment

by:for_yan
ID: 37157091
>cannot find symbol- error Method Refresh
>I believe it is a import problem.

it has nothing to do with any import
read my posting above.

You need to write a method in your
Single_Plex_1_Copy  
which should do waht you want to do when you referesh your table - check the system time and remove
the movies which already started or do whatever you need in order to refresh your table properly - otherwise
why to refresh?
Adfter you write such method this
 spc.refresh();
would not cause any errors

printStackTrace() is amthod of class Exception
to print the whole history of waht happened.
Very useful thing to print about any exception
It is not important what warnings NetBenas may have about that


0
 

Author Comment

by:octoberqueen
ID: 37157108
How to write refresh method? Please give from starting onwards:
"void refresh()...
0
 
LVL 47

Expert Comment

by:for_yan
ID: 37157124
I don't know why you want to refresh,
I was thinking you want to do siomething like that:

public void refresh() {

java.util.Date dd = new java.util.Date(); // this finds the current time

// then you should get DefaultTableModel from your JTable, like we already once did  with you
// and go through all  the rows of your Model - compare dates from the model with the current
//time and remove those rows which you don't want to show any more



}

Open in new window

0
 

Author Comment

by:octoberqueen
ID: 37157296
I am not having any success with entering time in 00:00 PM/AM format. So I decided to enter time in 00:00:00 format(24hours). But I want to limit the input entered by user to a range 00:00:00 to 23:59:59. MySQL allows us to enter even 99:99:99. So I need to catch these exceptions and display an error message. How can I do that?
----
Thanks friend, the above comment really worked.
0
 
LVL 47

Expert Comment

by:for_yan
ID: 37157302
if you specify
SimpledateFormat sdf = new SimpleDateFormat("HH:mm:ss");

sdf.setLenient(false);

then sdf.parse() will throw exception when the string is 99:99:99
and will check for 00:00:00 - 23:59:59
0
 

Author Comment

by:octoberqueen
ID: 37157350
As per your last comment, I modified my displayTime() method to:

String displayTime() {      
// Display a time in 00:00:00 format  
SimpleDateFormat sdf = new SimpleDateFormat("hh:mm:ss");
java.util.Date dd = new java.util.Date();
sdf.setLenient(false);
String time = sdf.format(dd);
return time;
 }    

In ADD Dialog, showTime and endTime are obtained in string datatype. Is there any way to check entered time in those textfields  and popup an error message when entered time is out of range(not in00:00:00 - 23:59:59) or is in invalid format?
0
 
LVL 47

Expert Comment

by:for_yan
ID: 37157377


No,
 When you format the time retrned by the system to make a string - there may be no error

I wrote it for the opposite situation when you read the string enteered by user - then you PARSE string into a date - find it - we did it many times

then

SimpleDateFormat sdf = new SimpleDateFormat("hh:mm:ss");
sdf.setLenient(false);

Striung ss =  textbox.getText();

java.util.Date dd1 = sdf.parse(ss, new ParsePosition(0));  <---- this will throw exception when ss is in the wrong foramt or has wriong numbers

so enclose this part (in the place where you read date from user, not from system) in try/catch loop
and if it thows exception pop-up error message





0
 

Author Comment

by:octoberqueen
ID: 37157457
I decided to revamp my ADD Dialog Box.

Earlier:
 Old_AddDialog
New:
 New_AddDialog
It might be better in functionality. Now I have to enter showTime and Duration of the Movie. TextField near endTime will be uneditable and will be used to automatically display endtime when the user inputs showTime and duration. Egs: If the user ends 12:00 PM as showTime and the total duration of the movie is 2:30 (2:30 hours). then the end time should display 14:30. How can I do that?
0
 
LVL 47

Expert Comment

by:for_yan
ID: 37157464
you convert String to Date d1

Date d2 = new Date(d1.getTime() + 150L*60L*1000L);

then convert d2 back to String
0
 

Author Comment

by:octoberqueen
ID: 37157556
I am confused

First I will obtain showTime

String movie = movTF.getText();
String screen = screenTF.getText();
String duration = durationTF.getText();//this is my duration. this should be added with showtime

SimpleDateFormat sdf = new SimpleDateFormat("hh:mm:ss");
sdf.setLenient(false);
String showTime = stTF.getText();

try
{
java.util.Date st = sdf.parse(showTime, new ParsePosition(0));

Date showt = new Date(st.getTime() +... //here what should I do? How can I add duration to showt?Do I need to convert duration too?

And, how to convert showt back to string?

0
 
LVL 47

Expert Comment

by:for_yan
ID: 37157567


you should add number of milliseconds, i.e. number of seconds multiplied by 1000 (in long numbers, so L in the end)
2:30 - 150 min - so number of seconds by 1000 is 150L*60L*1000L

we already many times transformed back and forth

Date showt = new Date(st.getTime() + 150L*60L*1000L);
so showt is variable of type Date, so

sdf.format(showt); ---> will be string that corresponds to that date

0
 

Author Comment

by:octoberqueen
ID: 37157675
How to compare two times?- Time present in showTime Label(showtime displayed in this label when a row is clicked) and  current system time. When system time exceeds showtime, the row should get deleted or disabled or unselectable. How can I do it?
0
 

Author Comment

by:octoberqueen
ID: 37157719
this is my refresh method
public void refresh() {

 
DefaultTableModel mdl = (DefaultTableModel)movTable.getModel();    

String showTime = stLab.getText();

try{
SimpleDateFormat sdf = new SimpleDateFormat("hh:mm:ss");
sdf.setLenient(false);
 
java.util.Date d1 = sdf.parse(showTime, new ParsePosition(0));
java.util.Date d2 = new java.util.Date();
String time = sdf.format(d2);
java.util.Date systemdate = sdf.parse(time);

if(d1.before(systemdate))
 
mdl.removeRow(movTable.getSelectedRow());
movTable.setModel(mdl);

}
catch(Exception e){
    JOptionPane.showMessageDialog(null,"Cannot Load Database","ERROR IN CONNECTIVITY",JOptionPane.ERROR_MESSAGE);
}
 
    

Open in new window


However I am persistenty getting the error message "Cannot Load Database".( I set refresh time to 100 milliseconds). What should I do?(sorry to trouble you everytime. My logic and IQ is no that much. Moreover basic java is not still clear to me.)
0
 
LVL 47

Expert Comment

by:for_yan
ID: 37157737
Don't know why you are recieving error, but you definitely should not do anything every 100 ms - maybe once a minute.

chacnge this way - at least you'll have information what is going on with your Exception:

catch(Exception e){
e.printStackTrace();
    JOptionPane.showMessageDialog(null,"Cannot Load Database","ERROR IN CONNECTIVITY",JOptionPane.ERROR_MESSAGE);
}
 


0
 

Author Comment

by:octoberqueen
ID: 37157952
I'm stuck:

This is my ADD Button Code:

String movie = movTF.getText();
String screen = screenTF.getText();
String showTime = stTF.getText();
String duration = durationTF.getText();

String newEndTime = etLab.getText();

SimpleDateFormat sdf = new SimpleDateFormat("hh:mm:ss");
sdf.setLenient(false); 




if (movie.equals(""))
    JOptionPane.showMessageDialog(null,"Movie Not Entered");
  
else if(screen.equals(""))
    JOptionPane.showMessageDialog(null,"Screen Not Entered");

else if(showTime.equals(""))
    JOptionPane.showMessageDialog(null,"ShowTime Not Entered");

else if(duration.equals(""))
    JOptionPane.showMessageDialog(null,"Movie Duration Not Entered");   
 
else{
    
//addition
DefaultTableModel mdl = (DefaultTableModel)movTable.getModel();

Vector v = new Vector();
 
v.add(showTime);
v.add(newEndTime);
v.add(screen);
v.add(movie);

mdl.addRow(v);
movTable.setModel(mdl);
//end addition    
try
{
java.util.Date sTime = sdf.parse(showTime, new ParsePosition(0));
java.util.Date dTime = sdf.parse(duration, new ParsePosition(0));

int t = decodeTime(duration);

Date eTime = new Date(sTime.getTime() + t);

sdf.format(eTime);
sdf.format(sTime);



Class.forName("java.sql.DriverManager");

Connection con = (Connection)
        
DriverManager.getConnection ("jdbc:mysql://localhost:3306/cbse","root", "tiger");

Statement stmt = (Statement) con.createStatement();

String query="INSERT INTO singlemayajaal VALUES ('"+sTime+"','"+eTime+"','"+screen+"','"+movie+"');";
stmt.executeUpdate(query);

JOptionPane.showMessageDialog (this,"Movie Added Successfully");  


movTF.setText("");
screenTF.setText("");
stTF.setText("");

    
    }


catch(Exception e)

{
JOptionPane.showMessageDialog (null,"Something is Wrong.Please check whether all fields are filled properly");
}

} 
 
    }                                      
]

Open in new window


When I press OK Button, I am only getting exception error message.

I wrote a method decodeTime

public static synchronized int decodeTime (String s) {
   SimpleDateFormat f = new SimpleDateFormat("HH:mm:ss");
   f.setLenient (false);
   ParsePosition p = new ParsePosition(0);
   Date d = f.parse(s,p);
   return (int)d.getTime(); }

Is it a wise idea. I am using this method to convert time to integer.


Please help me to rectify my mistakes.
0
 
LVL 47

Expert Comment

by:for_yan
ID: 37157965
You shouldn't throw yourself from one point to another - I cannot understand what you are doing.

Why Add button? We were doing refresh.

>Is it a wise idea.

Absolutely not wise.

Returning to refresh:

what was th exception?

Post output of this:

e.printStackTrace();







0
 

Author Comment

by:octoberqueen
ID: 37158096
Now I decided to implement refresh() method in a simpler and easy way.
When the user clicks a row from JTable, the details like movie name, showtime, screen will be displayed in appropriate labels.

When the user selects a row and if the showtime of that movie is before the current system time, then only the booking should take place. Otherwise the BOOK NOW Button should be disabled(setEnabled(false).

I think in order to implement this functionality, code should be written in mouse click event.
And I need a new refresh method.

This refresh() method, after checking whether the selected movie is bookable, or not bookable due to time exceed, should disable BOOK NOW Button accordingly.

I hope it's clear.
0
 
LVL 47

Expert Comment

by:for_yan
ID: 37158105
I thought you wanted to remove those lines which are already in the past when certain time passed.
That should be done indepndent of user clicking - and that's why we wanted this refresh to run say every minute?
Wasn't that right?
0
 

Author Comment

by:octoberqueen
ID: 37158115
I felt that will be very complicated and beyond my logic. Since I don't have much time to complete my project, I need to do it very simple. I can't handle further sophistication that could happen due to row removal after a certain time passed. I believe it's better to disable BOOK NOW Button or show a popup message when the user tries to book a movie that exceeded the showtime. I will be very thankful if you can show me the code for that.
 
0
 
LVL 47

Expert Comment

by:for_yan
ID: 37158130
But I wrote you many times evberything which is necessary for that - you read the time
of the move when user cicks Book Now and then you compare it with the current time using nethods of java.util.Date
before() or after() and then you pop-up the window is start time of the move happend before the cyrrent time - where is the problem ?
0
 

Author Comment

by:octoberqueen
ID: 37158309
No, But this time it need to start from JTable onwards.
When the user clicks a row in JTable, the following will happen:

private void movTableMouseClicked(java.awt.event.MouseEvent evt) {                                      
int row = movTable.getSelectedRow();
Object showTime = movTable.getValueAt(row, 0);
Object endTime = movTable.getValueAt(row, 1);
Object screen = movTable.getValueAt(row, 2);
Object movie = movTable.getValueAt(row, 3);
 
    movLab.setText(""+movie);
       
    stLab.setText(""+showTime);
   
    screenLab.setText(""+screen);
   
refresh();//Method to disable/enable BOOK NOW Button. any problem if method comes last?



My Refresh() Method(It's not correct)

public void refresh() {

DefaultTableModel mdl = (DefaultTableModel)movTable.getModel();    

int row = movTable.getSelectedRow();
String showTime = (String)movTable.getValueAt(row, 0);

try{
SimpleDateFormat sdf = new SimpleDateFormat("hh:mm:ss");
sdf.setLenient(false);
java.util.Date timetoCompare = sdf.parse(showTime, new ParsePosition(0));

java.util.Date d2 = new java.util.Date();
String time = sdf.format(d2);
java.util.Date systemtime = sdf.parse(time);

if(timetoCompare.after(systemtime))
 
bookNowBtn.setEnabled(false);


}
catch(Exception e){
    e.printStackTrace();
}
   

}
   

Please help me to tweak this method. My only condition the BOOK NOW Button should get disabled when the selected  showtime exceeds current system time.

0
 
LVL 47

Expert Comment

by:for_yan
ID: 37158329
You don't need any refresh method for that.
Just when user clicks the row you determine
the time compare it with the currwent time and disable the button.

The problem with that is that setEnabled(false) does not disable the button
You need to remove listener form the button to disable it.
Then when the user clicks another line tyou need to add the listener back.
 
In general, given your situation and all that stuff with netbeans
 I think to disable/enable button woul be more difficult than to update model when time expires
the way we wanted to do initially by checking time every 30 seconds.
It was almost working - why you suddenly switched ?
0
 

Author Comment

by:octoberqueen
ID: 37158362
Why is it difficult to disable a button based on time comparison? I didn't understand this part "You need to remove listener form the button to disable it.
Then when the user clicks another line tyou need to add the listener back."

I found disabling the button would be nice and simple. Do I have to write the code in BOOK NOW Button.?
0
 
LVL 47

Expert Comment

by:for_yan
ID: 37158365

bookNowBtn.setEnabled(false); only changes appearance of the button , it does not diasable its action
 
0
 
LVL 47

Expert Comment

by:for_yan
ID: 37158366
It changes only the look of the button, you still can click and it will stil fire event and your window, etc.
0
 

Author Comment

by:octoberqueen
ID: 37158378
No, believe me I can't click the button when I tried with a sample data.
I would be grateful if you can tell me any mistake or nonsense logic in my refresh() method. Is that method algorithm correct? Will it work in every situation? I didn't test it with more values.
0
 
LVL 47

Expert Comment

by:for_yan
ID: 37158394
But you also will need to enable button when they click on another line - otherwise it will be disabled forever.
I don't understand what you want from me. I am not a compiler - I do not do any checking looking at the code. It is thwe worst possible thing. Execute it and if it works - it works, if not - report the probkem and debug it - it makes no sense to stare at the code.
0
 

Author Comment

by:octoberqueen
ID: 37158420
Sorry Friend.
I troubled you a lot.

Are you meaning this type of error message? These were reported when clicked rows with showtime values 16:00:00, 13:00:00. The enabling/disabling worked but only to some extent.

run:
java.lang.NullPointerException
      at sample_3_multi.Single_Plex_1_Copy.refresh(Single_Plex_1_Copy.java:1280)
      at sample_3_multi.Single_Plex_1_Copy.movTableMouseClicked(Single_Plex_1_Copy.java:1026)
      at sample_3_multi.Single_Plex_1_Copy.access$1000(Single_Plex_1_Copy.java:50)
      at sample_3_multi.Single_Plex_1_Copy$12.mouseClicked(Single_Plex_1_Copy.java:613)
      at java.awt.AWTEventMulticaster.mouseClicked(AWTEventMulticaster.java:253)
      at java.awt.Component.processMouseEvent(Component.java:6291)
      at javax.swing.JComponent.processMouseEvent(JComponent.java:3267)
      at java.awt.Component.processEvent(Component.java:6053)
      at java.awt.Container.processEvent(Container.java:2041)
      at java.awt.Component.dispatchEventImpl(Component.java:4651)
      at java.awt.Container.dispatchEventImpl(Container.java:2099)
      at java.awt.Component.dispatchEvent(Component.java:4481)
      at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4577)
      at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4247)
      at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4168)
      at java.awt.Container.dispatchEventImpl(Container.java:2085)
      at java.awt.Window.dispatchEventImpl(Window.java:2478)
      at java.awt.Component.dispatchEvent(Component.java:4481)
      at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:643)
      at java.awt.EventQueue.access$000(EventQueue.java:84)
      at java.awt.EventQueue$1.run(EventQueue.java:602)
      at java.awt.EventQueue$1.run(EventQueue.java:600)
      at java.security.AccessController.doPrivileged(Native Method)
      at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
      at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:98)
      at java.awt.EventQueue$2.run(EventQueue.java:616)
      at java.awt.EventQueue$2.run(EventQueue.java:614)
      at java.security.AccessController.doPrivileged(Native Method)
      at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
      at java.awt.EventQueue.dispatchEvent(EventQueue.java:613)
      at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
      at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
      at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
      at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
      at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
      at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
java.lang.NullPointerException
      at sample_3_multi.Single_Plex_1_Copy.refresh(Single_Plex_1_Copy.java:1280)
      at sample_3_multi.Single_Plex_1_Copy.movTableMouseClicked(Single_Plex_1_Copy.java:1026)
      at sample_3_multi.Single_Plex_1_Copy.access$1000(Single_Plex_1_Copy.java:50)
      at sample_3_multi.Single_Plex_1_Copy$12.mouseClicked(Single_Plex_1_Copy.java:613)
      at java.awt.AWTEventMulticaster.mouseClicked(AWTEventMulticaster.java:253)
      at java.awt.Component.processMouseEvent(Component.java:6291)
      at javax.swing.JComponent.processMouseEvent(JComponent.java:3267)
      at java.awt.Component.processEvent(Component.java:6053)
      at java.awt.Container.processEvent(Container.java:2041)
      at java.awt.Component.dispatchEventImpl(Component.java:4651)
      at java.awt.Container.dispatchEventImpl(Container.java:2099)
      at java.awt.Component.dispatchEvent(Component.java:4481)
      at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4577)
      at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4247)
      at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4168)
      at java.awt.Container.dispatchEventImpl(Container.java:2085)
      at java.awt.Window.dispatchEventImpl(Window.java:2478)
      at java.awt.Component.dispatchEvent(Component.java:4481)
      at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:643)
      at java.awt.EventQueue.access$000(EventQueue.java:84)
      at java.awt.EventQueue$1.run(EventQueue.java:602)
      at java.awt.EventQueue$1.run(EventQueue.java:600)
      at java.security.AccessController.doPrivileged(Native Method)
      at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
      at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:98)
      at java.awt.EventQueue$2.run(EventQueue.java:616)
      at java.awt.EventQueue$2.run(EventQueue.java:614)
      at java.security.AccessController.doPrivileged(Native Method)
      at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
      at java.awt.EventQueue.dispatchEvent(EventQueue.java:613)
      at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
      at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
      at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
      at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
      at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
      at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
java.lang.NullPointerException
      at sample_3_multi.Single_Plex_1_Copy.refresh(Single_Plex_1_Copy.java:1280)
      at sample_3_multi.Single_Plex_1_Copy.movTableMouseClicked(Single_Plex_1_Copy.java:1026)
      at sample_3_multi.Single_Plex_1_Copy.access$1000(Single_Plex_1_Copy.java:50)
      at sample_3_multi.Single_Plex_1_Copy$12.mouseClicked(Single_Plex_1_Copy.java:613)
      at java.awt.AWTEventMulticaster.mouseClicked(AWTEventMulticaster.java:253)
      at java.awt.Component.processMouseEvent(Component.java:6291)
      at javax.swing.JComponent.processMouseEvent(JComponent.java:3267)
      at java.awt.Component.processEvent(Component.java:6053)
      at java.awt.Container.processEvent(Container.java:2041)
      at java.awt.Component.dispatchEventImpl(Component.java:4651)
      at java.awt.Container.dispatchEventImpl(Container.java:2099)
      at java.awt.Component.dispatchEvent(Component.java:4481)
      at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4577)
      at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4247)
      at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4168)
      at java.awt.Container.dispatchEventImpl(Container.java:2085)
      at java.awt.Window.dispatchEventImpl(Window.java:2478)
      at java.awt.Component.dispatchEvent(Component.java:4481)
      at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:643)
      at java.awt.EventQueue.access$000(EventQueue.java:84)
      at java.awt.EventQueue$1.run(EventQueue.java:602)
      at java.awt.EventQueue$1.run(EventQueue.java:600)
      at java.security.AccessController.doPrivileged(Native Method)
      at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
      at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:98)
      at java.awt.EventQueue$2.run(EventQueue.java:616)
      at java.awt.EventQueue$2.run(EventQueue.java:614)
      at java.security.AccessController.doPrivileged(Native Method)
      at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
      at java.awt.EventQueue.dispatchEvent(EventQueue.java:613)
      at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
      at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
      at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
      at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
      at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
      at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
BUILD SUCCESSFUL (total time: 21 seconds)
0
 
LVL 47

Expert Comment

by:for_yan
ID: 37158451
which is line 1280 in your file Single_Plex_1_Copy.java ?
0
 

Author Comment

by:octoberqueen
ID: 37158458
if(timetoCompare.after(systemtime))
0
 
LVL 47

Expert Comment

by:for_yan
ID: 37158464


java.util.Date d2 = new java.util.Date();
String time = sdf.format(d2);     ---- you don't need this line
java.util.Date systemtime = sdf.parse(time);  --- and this line; d2 is Date - uyou don't need to make string and then again date form it

if(timetoCompare.after(d2)) bookNowBtn.setEnabled(false);

why "after"  - if your starting time is before current time - then you need to disable - that's at least my uinderstanding


0
 
LVL 47

Expert Comment

by:for_yan
ID: 37158472
erhaps this line is offending:
java.util.Date systemtime = sdf.parse(time);

anyway, as I wrote above - you don't need any amnipulatiosn with the system time - you got it as a Data objkect
- uou don't need to do anything with it

The show time - you got form your string, thats why you convert it to Date object

Then you comare two dates, so remove those two lines, and think abiut after and before
0
 

Author Comment

by:octoberqueen
ID: 37158486
Do I have to change the code to this

if(timetoCompare.before(d2))
 
bookNowBtn.setEnabled(false);

else
bookNowBtn.setEnabled(true);

0
 
LVL 47

Expert Comment

by:for_yan
ID: 37158505
yes, change this way, and try again.
0
 

Author Comment

by:octoberqueen
ID: 37158506
My new list of errors(this happened after including the code in above comment). The button was disabled when I pressed rows with 01:00:00 & 09:21:31. However the error occurred  when I clicked 16:00:00 & 13:00:00

run:
java.lang.NullPointerException
      at sample_3_multi.Single_Plex_1_Copy.refresh(Single_Plex_1_Copy.java:1280)
      at sample_3_multi.Single_Plex_1_Copy.movTableMouseClicked(Single_Plex_1_Copy.java:1026)
      at sample_3_multi.Single_Plex_1_Copy.access$1000(Single_Plex_1_Copy.java:50)
      at sample_3_multi.Single_Plex_1_Copy$12.mouseClicked(Single_Plex_1_Copy.java:613)
      at java.awt.AWTEventMulticaster.mouseClicked(AWTEventMulticaster.java:253)
      at java.awt.Component.processMouseEvent(Component.java:6291)
      at javax.swing.JComponent.processMouseEvent(JComponent.java:3267)
      at java.awt.Component.processEvent(Component.java:6053)
      at java.awt.Container.processEvent(Container.java:2041)
      at java.awt.Component.dispatchEventImpl(Component.java:4651)
      at java.awt.Container.dispatchEventImpl(Container.java:2099)
      at java.awt.Component.dispatchEvent(Component.java:4481)
      at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4577)
      at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4247)
      at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4168)
      at java.awt.Container.dispatchEventImpl(Container.java:2085)
      at java.awt.Window.dispatchEventImpl(Window.java:2478)
      at java.awt.Component.dispatchEvent(Component.java:4481)
      at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:643)
      at java.awt.EventQueue.access$000(EventQueue.java:84)
      at java.awt.EventQueue$1.run(EventQueue.java:602)
      at java.awt.EventQueue$1.run(EventQueue.java:600)
      at java.security.AccessController.doPrivileged(Native Method)
      at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
      at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:98)
      at java.awt.EventQueue$2.run(EventQueue.java:616)
      at java.awt.EventQueue$2.run(EventQueue.java:614)
      at java.security.AccessController.doPrivileged(Native Method)
      at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
      at java.awt.EventQueue.dispatchEvent(EventQueue.java:613)
      at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
      at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
      at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
      at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
      at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
      at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
BUILD SUCCESSFUL (total time: 7 seconds)
0
 
LVL 47

Expert Comment

by:for_yan
ID: 37158537
change this
SimpleDateFormat sdf = new SimpleDateFormat("hh:mm:ss");

to
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");  <--- upper case HH instead of hh


0
 

Author Comment

by:octoberqueen
ID: 37158556
Now no error messages are coming.
However the button is not getting even when I click 17:00:00, 21:00:00. This is the same situation when I click 03:00:00, 01:00:00
0
 
LVL 47

Expert Comment

by:for_yan
ID: 37158652

>the button is not getting

is not getting what ?
0
 

Author Comment

by:octoberqueen
ID: 37158694
sorry
the button is not getting acvitvated/enabled.
0
 
LVL 47

Expert Comment

by:for_yan
ID: 37158710
Add these two line just before the comparison - exactly like that - without any foraatting - and post what it prints
in case when it works as expected and in case when it works not as expected

System.out.println("show time: " + timetoCompare);
System.out.println("current time: " + d2);

if(timetoCompare.before(d2))
 
bookNowBtn.setEnabled(false);

else
bookNowBtn.setEnabled(true);


0
 

Author Comment

by:octoberqueen
ID: 37158734
show time: Thu Jan 01 01:00:00 IST 1970
current time: Fri Nov 18 17:11:42 IST 2011

Same throught ever row click (except second changes)
0
 
LVL 47

Expert Comment

by:for_yan
ID: 37158743
did you click on the time which was saying 01:00:00 ?
0
 

Author Comment

by:octoberqueen
ID: 37158759
Yes and the result on NON-GUI Front was same

show time: Thu Jan 01 01:00:00 IST 1970
current time: Fri Nov 18 17:19:45 IST 2011

The Book Now Button was also disabled.
0
 
LVL 47

Expert Comment

by:for_yan
ID: 37158783
I don't understand what is non-gui front but I think that does not matter


So you need to modify how you create timeToCompare object in this way:

SimpleDateFormat sdf2 = new SimpleDateFormat ("mm-dd-yyyy HH:mm:ss");
sdf2.setLenient(false);


String curDate = sdf2.format(d2);

String day = curDate.substring(0, curDate.indexOf(" "));

String showDateTimeString = day + " " + showTime;

java.util.Date timetoCompare = sdf2.parse(showDateTimeString, new ParsePosition(0));

then you compare  as before timeToCompare and d2




0
 
LVL 47

Expert Comment

by:for_yan
ID: 37158787
I will probably not respond for the next several hours
0
 
LVL 47

Expert Comment

by:for_yan
ID: 37158797

this line shiould be corrected - upper case MM for months:
SimpleDateFormat sdf2 = new SimpleDateFormat ("MM-dd-yyyy HH:mm:ss");
0
 

Author Comment

by:octoberqueen
ID: 37158812
Like this:

public void refresh() {

DefaultTableModel mdl = (DefaultTableModel)movTable.getModel();    

int row = movTable.getSelectedRow();
String showTime = (String)movTable.getValueAt(row, 0);


try{
SimpleDateFormat sdf2 = new SimpleDateFormat ("mm-dd-yyyy HH:mm:ss");
sdf2.setLenient(false);
java.util.Date timetoCompare = sdf2.parse(showTime, new ParsePosition(0));

java.util.Date d2 = new java.util.Date();

String curDate = sdf2.format(d2);
String day = curDate.substring(0, curDate.indexOf(" "));

String showDateTimeString = day + " " + showTime;



System.out.println("show time: " + timetoCompare);
System.out.println("current time: " + d2);

if(timetoCompare.before(d2))
 
bookNowBtn.setEnabled(false);

else
bookNowBtn.setEnabled(true);
}
catch(Exception e){
    e.printStackTrace();
}
   
Please edit the code if mistakes are found.
0
 

Author Comment

by:octoberqueen
ID: 37158830
sorry I posted the above comment without reading your last comment.

And Non-Gui Front, I called is the area where output of system.out.println is displayed
0
 
LVL 47

Accepted Solution

by:
for_yan earned 2000 total points
ID: 37158849




public void refresh() {

DefaultTableModel mdl = (DefaultTableModel)movTable.getModel();    

int row = movTable.getSelectedRow();
String showTime = (String)movTable.getValueAt(row, 0);


try{
SimpleDateFormat sdf2 = new SimpleDateFormat ("MM-dd-yyyy HH:mm:ss");
sdf2.setLenient(false); 


java.util.Date d2 = new java.util.Date();

String curDate = sdf2.format(d2);
String day = curDate.substring(0, curDate.indexOf(" "));

String showDateTimeString = day + " " + showTime;


java.util.Date timetoCompare = sdf2.parse(showDateTimeString, new ParsePosition(0));
System.out.println("full show time: " + timetoCompare);
System.out.println("current time: " + d2);

if(timetoCompare.before(d2)) 
 
bookNowBtn.setEnabled(false);

else
bookNowBtn.setEnabled(true);
}
catch(Exception e){
    e.printStackTrace();
}
   

Open in new window

0
 

Author Comment

by:octoberqueen
ID: 37158880
Thank you friend.
It really worked.


P.S: My project is not over yet.
0
 

Author Comment

by:octoberqueen
ID: 37158907
Now the next problem is during adding movie to JTable and MySQL. As usual, the ADD Dialog will popup when I press ADD Button.
 

The last Text Field-Endtime is disabled(it can be a level). The source code for Add(OK) BTN
String movie = movTF.getText();
String screen = screenTF.getText();
String showTime = stTF.getText();
String duration = durationTF.getText();

String newEndTime = etLab.getText();

SimpleDateFormat sdf = new SimpleDateFormat("hh:mm:ss");
sdf.setLenient(false);




if (movie.equals(""))
    JOptionPane.showMessageDialog(null,"Movie Not Entered");
 
else if(screen.equals(""))
    JOptionPane.showMessageDialog(null,"Screen Not Entered");

else if(showTime.equals(""))
    JOptionPane.showMessageDialog(null,"ShowTime Not Entered");

else if(duration.equals(""))
    JOptionPane.showMessageDialog(null,"Movie Duration Not Entered");  
 
else{
   
//addition
DefaultTableModel mdl = (DefaultTableModel)movTable.getModel();

Vector v = new Vector();
 
v.add(showTime);
v.add(newEndTime);
v.add(screen);
v.add(movie);

mdl.addRow(v);
movTable.setModel(mdl);
//end addition    
try
{
java.util.Date sTime = sdf.parse(showTime, new ParsePosition(0));
java.util.Date dTime = sdf.parse(duration, new ParsePosition(0));

int t = decodeTime(duration);

Date eTime = new Date(sTime.getTime() + t);

sdf.format(eTime);
sdf.format(sTime);



Class.forName("java.sql.DriverManager");

Connection con = (Connection)
       
DriverManager.getConnection ("jdbc:mysql://localhost:3306/cbse","root", "tiger");

Statement stmt = (Statement) con.createStatement();

String query="INSERT INTO singlemayajaal VALUES ('"+sTime+"','"+eTime+"','"+screen+"','"+movie+"');";
stmt.executeUpdate(query);

JOptionPane.showMessageDialog (this,"Movie Added Successfully");  


movTF.setText("");
screenTF.setText("");
stTF.setText("");

   
    }


catch(Exception e)

{
JOptionPane.showMessageDialog (null,"Something is Wrong.Please check whether all fields are filled properly");
e.printStackTrace();
}

}
 
    }                                      

And the error I got :

run:
java.lang.NullPointerException
      at sample_3_multi.Single_Plex_1_Copy.decodeTime(Single_Plex_1_Copy.java:1242)
      at sample_3_multi.Single_Plex_1_Copy.addBtnActionPerformed(Single_Plex_1_Copy.java:1154)
      at sample_3_multi.Single_Plex_1_Copy.access$600(Single_Plex_1_Copy.java:50)
      at sample_3_multi.Single_Plex_1_Copy$7.actionPerformed(Single_Plex_1_Copy.java:405)
      at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
      at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318)
      at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
      at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
      at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
      at java.awt.Component.processMouseEvent(Component.java:6288)
      at javax.swing.JComponent.processMouseEvent(JComponent.java:3267)
      at java.awt.Component.processEvent(Component.java:6053)
      at java.awt.Container.processEvent(Container.java:2041)
      at java.awt.Component.dispatchEventImpl(Component.java:4651)
      at java.awt.Container.dispatchEventImpl(Container.java:2099)
      at java.awt.Component.dispatchEvent(Component.java:4481)
      at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4577)
      at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4238)
      at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4168)
      at java.awt.Container.dispatchEventImpl(Container.java:2085)
      at java.awt.Window.dispatchEventImpl(Window.java:2478)
      at java.awt.Component.dispatchEvent(Component.java:4481)
      at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:643)
      at java.awt.EventQueue.access$000(EventQueue.java:84)
      at java.awt.EventQueue$1.run(EventQueue.java:602)
      at java.awt.EventQueue$1.run(EventQueue.java:600)
      at java.security.AccessController.doPrivileged(Native Method)
      at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
      at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:98)
      at java.awt.EventQueue$2.run(EventQueue.java:616)
      at java.awt.EventQueue$2.run(EventQueue.java:614)
      at java.security.AccessController.doPrivileged(Native Method)
      at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
      at java.awt.EventQueue.dispatchEvent(EventQueue.java:613)
      at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
      at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
      at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
      at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
      at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
      at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)

 
0
 

Author Comment

by:octoberqueen
ID: 37159395
I believe you are very busy at the moment, so I wish you to answer these questions along with my last question.
- How to make sure that showtime and endtime values for each movie are unique and not repeated?

- Whenever a row is added, it should be ordered based on time. Like ShowTime- 9:00:00 , 12:00:00 , 3:00:00, 6:00:00.
0
 

Author Closing Comment

by:octoberqueen
ID: 37165480
Thank you Friend.
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
In this post we will learn different types of Android Layout and some basics of an Android App.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses
Course of the Month19 days, 9 hours left to enroll

873 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question