Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 7 of 7

Thread: flight reservation code problem...

  1. #1
    Junior Member
    Join Date
    Feb 2012
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default flight reservation code problem...

    the time wont change, its always 4:00:00. can u help me?



     import javax.swing.*;
    import javax.swing.event.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.sql.*;
    import java.io.*;
    import java.text.*;
    class Frame1 extends JFrame implements ActionListener
    {
     
     
           JLabel lbl=new JLabel("FLIGHT RESERVATION SYSTEM");
     
           Font f=new Font("Broadway",Font.BOLD,45);
           Font f1=new Font("Comic Sans",Font.BOLD,15);
           Font f2=new Font("Bradley Hand",Font.BOLD,24);
     
           JLabel lblticket,lblseat,lblclass,lbldestination,lbldepart,lblarrival,lbltotal,lbln,lblusa,lblcanada,lbls,lbla,lblae,lblbr,lblp;
           JTextField txtticket,txtseat,txtclass,txtdestination,txtdepart,txtarrival,txttotal;
           JRadioButton rbFirst,rbeco, rbbus,rbw,rbo,rbh,rbm,rbar,rbmo,rbva,rbto,rbot,rbq,rbb,rbs,rbf,rbca,rbboa,rbp,rbtac,rbpe,rbpu,rbtr,rbri,rbha,rbtab,rbji,rbasir;
           JButton btncompute, btnadd,btnedit,btnsearch,btndelete;
           JButton btnnext,btnprev,btnlast,btnfirst,btnexit;
           String gen;
           ResultSet rs=null;
           Connection con=null;
           Statement stmt=null;
     
           Frame1()
           {
     
           super("FLIGHT RESERVATION DETAILS");
           addWindowListener(new WindowAdapter(){
                    public void windowClosing(WindowEvent we)
                    {
                    System.exit(0);
                    }
     
           });
     
           setLayout(null);
     
           add(lbl);
     
           lbl.setBounds(50,60,860,40);
     
           // set the font of lbl label
           lbl.setFont(f);
     
     
           // initializa all the label which are declared in the example above with its caption name
           lblticket=new JLabel("TICKETNO:");
           lblseat=new JLabel("SEATNO:");
           lblclass=new JLabel("CLASS");
           lbldestination=new JLabel("DESTINATION");
           lbln=new JLabel ("NORTH AMERICA");
           lblusa=new JLabel("USA");
           lblcanada= new JLabel("Canada");
           lbls=new JLabel("SOUTH AMERICA");
           lblbr=new JLabel("Brazil");
           lblp= new JLabel("Peru");
           lbla=new JLabel("ASIA");
           lblae=new JLabel("UAE");
           lbldepart=new JLabel("DEPART TIME");
           lblarrival=new JLabel ("ARRIVAL TIME");
           lbltotal=new JLabel("TOTAL:");
     
           lblticket.setBounds(30,120,100,20);
           lblseat.setBounds(30,160,100,20);
           lblclass.setBounds(500,120,100,20);
           lbldestination.setBounds(500,170,300,20);
           lbln.setBounds(350,190,200,20);
           lblusa.setBounds(320,220,200,20);
           lblcanada.setBounds(430,220,200,20);
           lblbr.setBounds(560,220,200,20);
           lblp.setBounds(710,220,200,20);
           lbls.setBounds(580,190,200,20);
           lbla.setBounds(850,190,200,20);
           lblae.setBounds(870,220,200,20);
           lbldepart.setBounds(20,200,100,20);
           lblarrival.setBounds(20,220,100,20);
           lbltotal.setBounds(30,250,100,20);
     
           add(lblticket);
           add(lblseat);
           add(lblclass);
           add(lbldestination);
           add(lbldepart);
           add(lblarrival);
           add(lbltotal);
           add(lbln);
           add(lblusa);
           add(lblcanada);
           add(lbls);
           add(lblbr);
           add(lblp);
           add(lbla);
           add(lblae);
     
     
           lblticket.setFont(f1);
           lblseat.setFont(f1);
           lblclass.setFont(f2);
           lbldestination.setFont(f2);
           lbldepart.setFont(f1);
           lblarrival.setFont(f1);
           lbltotal.setFont(f1);
           lbln.setFont(f1);
           lbls.setFont(f1);
           lblbr.setFont(f1);
           lblp.setFont(f1);
           lbla.setFont(f1);
           lblae.setFont(f1);
           lblusa.setFont(f1);
           lblcanada.setFont(f1);
     
           txtticket=new JTextField(10);
           txtseat=new JTextField (10);
           txtdepart=new JTextField(10);
           txtarrival=new JTextField(10);
           txttotal= new JTextField(10);
     
     
           txtticket.setBounds(120,120,150,20);
           txtseat.setBounds(120,160,150,20);
           txtdepart.setBounds(120,200,150,20);
           txtarrival.setBounds(120,220,150,20);
           txttotal.setBounds(120,250,150,20);
     
     
           add(txtticket);
           add(txtseat);
           add(txtdepart);
           add(txtarrival);
           add(txttotal);
     
     
           rbFirst= new JRadioButton("First");
           rbeco= new JRadioButton("Economy");
           rbbus=new JRadioButton("Business");
           rbw= new JRadioButton("Washington D.C");
           rbo= new JRadioButton("Oklahama");
           rbh= new JRadioButton("Honolulu");
           rbar=new JRadioButton("Phoenix");
           rbm=new JRadioButton("New Mexico");
     
           rbmo=new JRadioButton("Montreal");
           rbva=new JRadioButton("Vancouver");
           rbto=new JRadioButton("Toronto");
           rbot=new JRadioButton("Ottawa");
           rbq=new JRadioButton("Quebec");
     
           rbb=new JRadioButton("Brasilia");
           rbs= new JRadioButton("Salvador");
           rbf= new JRadioButton("Fortaleza");
           rbca= new JRadioButton("Campo Grande");
           rbboa=new JRadioButton("Boa Vista");
     
           rbp=new JRadioButton("Lima");
           rbtac =new JRadioButton("Tacha");
           rbpu =new JRadioButton("Pucallpa");
           rbpe =new JRadioButton("Peura");
           rbtr =new JRadioButton("Trujillo");
     
           rbri=new JRadioButton("Riyadh");
           rbha =new JRadioButton("Hail");
           rbtab =new JRadioButton("Tabuk");
           rbji =new JRadioButton("Jizan");
           rbasir =new JRadioButton("Asir");
     
     
           rbFirst.setBounds(400,140,50,30);
           rbeco.setBounds(500,140,100,30);
           rbbus.setBounds(600,140,100,30);
     
           rbw.setBounds(280,240,130,20);
           rbo.setBounds(280,260,100,20);
           rbh.setBounds(280,280,100,20);
           rbar.setBounds(280,300,100,20);
           rbm.setBounds(280,320,100,20);
     
           rbmo.setBounds(420,240,100,20);
           rbva.setBounds(420,260,100,20);
           rbto.setBounds(420,280,100,20);
           rbot.setBounds(420,300,100,20);
           rbq.setBounds(420,320,100,20);
     
           rbb.setBounds(550,240,100,20);
           rbs.setBounds(550,260,100,20);
           rbf.setBounds(550,280,100,20);
           rbca.setBounds(550,300,130,20);
           rbboa.setBounds(550,320,130,20);
     
           rbp.setBounds(700,240,100,20);
           rbtac.setBounds(700,260,130,20);
           rbpu.setBounds(700,280,130,20);
           rbpe.setBounds(700,300,130,20);
           rbtr.setBounds(700,320,100,20);
     
           rbri.setBounds(850,240,130,20);
           rbha.setBounds(850,260,230,20);
           rbtab.setBounds(850,280,230,20);
           rbji.setBounds(850,300,230,20);
           rbasir.setBounds(850,320,230,20);
     
           add(rbFirst);
           add(rbeco);
           add(rbbus);
           add(rbw);
           add(rbo);
           add(rbh);
           add(rbar);
           add(rbm);
     
           add(rbb);
           add(rbs);
           add(rbf);
           add(rbca);
           add(rbboa);
     
           add(rbp);
           add(rbtac);
           add(rbpe);
           add(rbpu);
           add(rbtr);
     
    add(rbmo);
    add(rbva);
    add(rbto);
    add(rbot);
    add(rbq);
     
    add(rbri);
    add(rbha);
    add(rbtab);
    add(rbji);
    add(rbasir);
     
           rbFirst.addActionListener(this);
           rbeco.addActionListener(this);
           rbbus.addActionListener(this);
     
           rbw.addActionListener(this);
           rbo.addActionListener(this);
           rbh.addActionListener(this);
           rbm.addActionListener(this);
           rbar.addActionListener(this);
     
           rbmo.addActionListener(this);
           rbot.addActionListener(this);
           rbto.addActionListener(this);
           rbva.addActionListener(this);
           rbq.addActionListener(this);
     
           rbb.addActionListener(this);
           rbs.addActionListener(this);
           rbf.addActionListener(this);
           rbca.addActionListener(this);
           rbboa.addActionListener(this);
     
           rbp.addActionListener(this);
           rbtac.addActionListener(this);
           rbpe.addActionListener(this);
           rbpu.addActionListener(this);
           rbtr.addActionListener(this);
     
           rbri.addActionListener(this);
           rbha.addActionListener(this);
           rbtab.addActionListener(this);
           rbji.addActionListener(this);
           rbasir.addActionListener(this);
     
           btnadd=new JButton("Add");
           btnedit=new JButton("Edit");
           btnsearch=new JButton("Search");
           btndelete=new JButton("Delete");
     
     
           btnadd.setBounds(200,410,100,30);
           btnedit.setBounds(310,410,100,30);
           btnsearch.setBounds(420,410,100,30);
           btndelete.setBounds(530,410,100,30);
     
     
           add(btnadd);
           add(btnedit);
           add(btnsearch);
           add(btndelete);
     
     
           btnadd.addActionListener(this);
           btnedit.addActionListener(this);
           btnsearch.addActionListener(this);
           btndelete.addActionListener(this);
     
     
     
           btnfirst=new JButton("First");
           btnnext=new JButton("Next");
           btnprev=new JButton("Previous");
           btnlast=new JButton("Last");
     
     
           btnfirst.setBounds(200,450,100,30);
           btnnext.setBounds(310,450,100,30);
           btnprev.setBounds(420,450,100,30);
           btnlast.setBounds(530,450,100,30);
     
     
           add(btnfirst);
           add(btnnext);
           add(btnprev);
           add(btnlast);
     
     
           btnfirst.addActionListener(this);
           btnnext.addActionListener(this);
           btnprev.addActionListener(this);
           btnlast.addActionListener(this);
     
           btnexit=new JButton("EXIT");
           btnexit.setBounds(360,510,100,30);
           add(btnexit);
           btnexit.addActionListener(this);
     
           btncompute=new JButton("Compute");
           btncompute.setToolTipText("Click this button to compute the total");
           btncompute.setBounds(80,275,100,30);
           add(btncompute);
           btncompute.addActionListener(this);
     
           dbOpen();
           }
           public void actionPerformed(ActionEvent ae)
    	{
    		try
    		{
    		if(ae.getActionCommand()=="Compute"){
     
    		double total = 0.0;
    		double date=;
     
    			if(rbFirst.isSelected()){
    				total +=5000;
    			}
    			if(rbeco.isSelected()){
    				total+=2500;
     
    			}
    			if(rbbus.isSelected()){
    				total+=1000;
    			}
    			if(rbw.isSelected()){
    				total+=38274;
    				date +=23;
    			}
    			if(rbo.isSelected()){
    				total+=52782;
    				date +=11;
    			}
    			if(rbb.isSelected()){
    				total+=93117;
    				date +=11;
    			}
    			if(rbs.isSelected()){
    				total+=104537;
    				date +=11;
    			}
    			if(rbf.isSelected()){
    				total+=40450;
    				date +=11;
     
    			}
    			if(rbmo.isSelected()){
                	total+=71610;
                    date +=23;
                }
                if(rbva.isSelected()){
                total+=55440;
                	date +=30;
                }
                if(rbto.isSelected()){
                	total+=62920;
                    date +=24;
                }
                if(rbot.isSelected()){
                	total+=73850;
                	date +=24;
                }
                if(rbq.isSelected()){
                	total+=70660;
                	date +=23;
                }
                if(rbri.isSelected()){
                	total+=51790;
                	date +=19;
                }
                if(rbha.isSelected()){
                	total+=80720;
                		date +=24;
                }
                if(rbtab.isSelected()){
                	total+=63950;
                		date +=29;
                }
                if(rbji.isSelected()){
                	total+=102800;
                		date +=25;
                }
                if(rbasir.isSelected()){
                	total+=52480;
                		date +=23;
                }
                if(rbb.isSelected()){
                    total+=93117;
                    	date +=33;
                }
                if(rbs.isSelected()){
                    total+=104537;
                    	date +=39;
                }
                if(rbf.isSelected()){
                    total+=40450;
                    	date +=41;
                }
                if(rbp.isSelected()){
    			   total+=144100;
    			   	date +=27;
    			}
    			if(rbtac.isSelected()){
    				total+=125778;
    					date +=28;
    			}
                if(rbpe.isSelected()){
                	total+=142662;
                		date +=48;
                }
                if(rbtr.isSelected()){
                	total+=144427;
                		date +=45;
                }
                if(rbb.isSelected()){
                	total+=139122;
                		date +=39;
                }
                if(rbs.isSelected()){
                	total+=144727;
                		date +=33;
                }
                if(rbf.isSelected()){
                	total+=152505;
                		date +=41;
                }
                if(rbboa.isSelected()){
                 	total+=139122;
                 		date +=56;
                }
                 if(rbca.isSelected()){
                 	total+=158319;
                 		date +=42;
                }
    			DecimalFormat dollars = new DecimalFormat("Php0.00");
    			txttotal.setText(dollars.format(total));
    			DateFormat sdf = new SimpleDateFormat("K:mm:ss a,z");
    			txtarrival.setText(sdf.format(date));
     
     
    		}
     
    	 		if(ae.getActionCommand()=="Add")
    			{
    				txtticket.setText("");
    				txtseat.setText("");
    				txtclass.setText("");
    				txtdestination.setText("");
    				txtdepart.setText("");
    				txtarrival.setText("");
     
    			}
     
    			if(ae.getActionCommand()=="Save")
    			{
    				stmt.executeUpdate("INSERT INTO STUDENTINFO VALUES('" + txtticket.getText() + "','" + txtseat.getText() + "','" + txtclass.getText() + "'," + txtdestination.getText() + "'," + txtarrival.getText() + "')");
    				dbClose();
    				dbOpen();
    			}
    			if(ae.getActionCommand()=="Delete")
    			{
    				stmt.executeUpdate("DELETE FROM STUDENTINFO WHERE ticket=" + txtticket.getText() + "");
    				dbClose();
    				dbOpen();
    			}
    			if(ae.getActionCommand()=="Search")
     
    			{
    				stmt.executeUpdate("SEARCH * FROM STUDENTINFO WHERE ticket=" + txtticket.getText() + "");
    				dbClose();
    				dbOpen();
    			}
    			if(ae.getActionCommand()=="Next")
    			{
    				if(rs.next())
    				{
    					setText();
    				}
    				else
    				{
    					JOptionPane.showMessageDialog(null, "You are already at Last Record", "Messarrival", JOptionPane.ERROR_MESSAGE);
                      		}
    			}
    			if(ae.getActionCommand()=="Previous")
    			{
    				if(rs.previous())
    				{
                      			setText();
    				}
    				else
    				{
    					JOptionPane.showMessageDialog(null, "You Are Already At First Record", "Messarrival", JOptionPane.ERROR_MESSAGE);
                      		}
    			}
    			if (ae.getActionCommand()=="First")
    			{
    				if(rs.first())
    				{
    					setText();
    				}
    			}
    			if (ae.getActionCommand()=="Last")
    			{
    				if(rs.last())
    				{
    					setText();
    				}
    			}
    			if(ae.getActionCommand()=="EXIT")
    			{
    			System.exit(0);
    			}
    		}
    		catch(Exception e)
    		{
    			e.printStackTrace();
    		}
    	}
     
     
    	public void dbOpen()
    	{
    		try
    		{
    			Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
     
     
                            con = DriverManager.getConnection("jdbc:odbc:mydsn");
    			stmt=con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
    			rs = stmt.executeQuery("Select * from STUDENTINFO");
    			if(rs.next())
    			setText();
    		}catch(Exception e){}
    	}
    	public void dbClose()
    	{
    		try{stmt.close();
    		rs.close();
    		con.close();
    		}catch(Exception e){}
    	}
    	public void setText(){
    		try{
    			txtticket.setText(rs.getString(1));
    			txtseat.setText(rs.getString(2));
    			txtclass.setText(rs.getString(3));
    			txtdestination.setText(rs.getString(4));
    			txtarrival.setText(rs.getString(5));
    			txtdepart.setText(rs.getString(6));
    	    	}catch(Exception ex){}
    	    	}
    }
     
     class Frame
    {
            public static void main(String arg[])throws Exception
            {
     
     
            Frame1 f1=new Frame1();
     
     
            f1.setSize(1000,600);
     
     
            f1.setVisible(true);
     
    	UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
            }
    }
    Last edited by ricaclaire16; March 4th, 2012 at 05:23 AM.


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: flight reservation code problem...

    Please Edit your post and wrap your code with[code=java]<YOUR CODE HERE>[/code] to get highlighting

    the time wont change, its always 4:00:00.
    Can you explain? Where is this happening? What lines of code show this?

  3. #3
    Junior Member
    Join Date
    Feb 2012
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: flight reservation code problem...

    Norm the 4:00:00 happens in this line:
    DateFormat sdf = new SimpleDateFormat("K:mm:ss a,z");

    and here's d full code:
    import javax.swing.*;
    import javax.swing.event.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.sql.*;
    import java.io.*;
    import java.text.*;
    class Frame1 extends JFrame implements ActionListener
    {
     
     
    JLabel lbl=new JLabel("FLIGHT RESERVATION SYSTEM");
     
    Font f=new Font("Broadway",Font.BOLD,45);
    Font f1=new Font("Comic Sans",Font.BOLD,15);
    Font f2=new Font("Bradley Hand",Font.BOLD,24);
     
    JLabel lblticket,lblseat,lblclass,lbldestination,lbldepar t,lblarrival,lbltotal,lbln,lblusa,lblcanada,lbls,l bla,lblae,lblbr,lblp;
    JTextField txtticket,txtseat,txtclass,txtdestination,txtdepar t,txtarrival,txttotal;
    JRadioButton rbFirst,rbeco, rbbus,rbw,rbo,rbh,rbm,rbar,rbmo,rbva,rbto,rbot,rbq ,rbb,rbs,rbf,rbca,rbboa,rbp,rbtac,rbpe,rbpu,rbtr,r bri,rbha,rbtab,rbji,rbasir;
    JButton btncompute, btnadd,btnedit,btnsearch,btndelete;
    JButton btnnext,btnprev,btnlast,btnfirst,btnexit;
    String gen;
    ResultSet rs=null;
    Connection con=null;
    Statement stmt=null;
     
    Frame1()
    {
     
    super("FLIGHT RESERVATION DETAILS");
    addWindowListener(new WindowAdapter(){
    public void windowClosing(WindowEvent we)
    {
    System.exit(0);
    }
     
    });
     
    setLayout(null);
     
    add(lbl);
     
    lbl.setBounds(50,60,860,40);
     
    // set the font of lbl label
    lbl.setFont(f);
     
     
    // initializa all the label which are declared in the example above with its caption name
    lblticket=new JLabel("TICKETNO:");
    lblseat=new JLabel("SEATNO:");
    lblclass=new JLabel("CLASS");
    lbldestination=new JLabel("DESTINATION");
    lbln=new JLabel ("NORTH AMERICA");
    lblusa=new JLabel("USA");
    lblcanada= new JLabel("Canada");
    lbls=new JLabel("SOUTH AMERICA");
    lblbr=new JLabel("Brazil");
    lblp= new JLabel("Peru");
    lbla=new JLabel("ASIA");
    lblae=new JLabel("UAE");
    lbldepart=new JLabel("DEPART TIME");
    lblarrival=new JLabel ("ARRIVAL TIME");
    lbltotal=new JLabel("TOTAL:");
     
    lblticket.setBounds(30,120,100,20);
    lblseat.setBounds(30,160,100,20);
    lblclass.setBounds(500,120,100,20);
    lbldestination.setBounds(500,170,300,20);
    lbln.setBounds(350,190,200,20);
    lblusa.setBounds(320,220,200,20);
    lblcanada.setBounds(430,220,200,20);
    lblbr.setBounds(560,220,200,20);
    lblp.setBounds(710,220,200,20);
    lbls.setBounds(580,190,200,20);
    lbla.setBounds(850,190,200,20);
    lblae.setBounds(870,220,200,20);
    lbldepart.setBounds(20,200,100,20);
    lblarrival.setBounds(20,220,100,20);
    lbltotal.setBounds(30,250,100,20);
     
    add(lblticket);
    add(lblseat);
    add(lblclass);
    add(lbldestination);
    add(lbldepart);
    add(lblarrival);
    add(lbltotal);
    add(lbln);
    add(lblusa);
    add(lblcanada);
    add(lbls);
    add(lblbr);
    add(lblp);
    add(lbla);
    add(lblae);
     
     
    lblticket.setFont(f1);
    lblseat.setFont(f1);
    lblclass.setFont(f2);
    lbldestination.setFont(f2);
    lbldepart.setFont(f1);
    lblarrival.setFont(f1);
    lbltotal.setFont(f1);
    lbln.setFont(f1);
    lbls.setFont(f1);
    lblbr.setFont(f1);
    lblp.setFont(f1);
    lbla.setFont(f1);
    lblae.setFont(f1);
    lblusa.setFont(f1);
    lblcanada.setFont(f1);
     
    txtticket=new JTextField(10);
    txtseat=new JTextField (10);
    txtdepart=new JTextField(10);
    txtarrival=new JTextField(10);
    txttotal= new JTextField(10);
     
     
    txtticket.setBounds(120,120,150,20);
    txtseat.setBounds(120,160,150,20);
    txtdepart.setBounds(120,200,150,20);
    txtarrival.setBounds(120,220,150,20);
    txttotal.setBounds(120,250,150,20);
     
     
    add(txtticket);
    add(txtseat);
    add(txtdepart);
    add(txtarrival);
    add(txttotal);
     
     
    rbFirst= new JRadioButton("First");
    rbeco= new JRadioButton("Economy");
    rbbus=new JRadioButton("Business");
    rbw= new JRadioButton("Washington D.C");
    rbo= new JRadioButton("Oklahama");
    rbh= new JRadioButton("Honolulu");
    rbar=new JRadioButton("Phoenix");
    rbm=new JRadioButton("New Mexico");
     
    rbmo=new JRadioButton("Montreal");
    rbva=new JRadioButton("Vancouver");
    rbto=new JRadioButton("Toronto");
    rbot=new JRadioButton("Ottawa");
    rbq=new JRadioButton("Quebec");
     
    rbb=new JRadioButton("Brasilia");
    rbs= new JRadioButton("Salvador");
    rbf= new JRadioButton("Fortaleza");
    rbca= new JRadioButton("Campo Grande");
    rbboa=new JRadioButton("Boa Vista");
     
    rbp=new JRadioButton("Lima");
    rbtac =new JRadioButton("Tacha");
    rbpu =new JRadioButton("Pucallpa");
    rbpe =new JRadioButton("Peura");
    rbtr =new JRadioButton("Trujillo");
     
    rbri=new JRadioButton("Riyadh");
    rbha =new JRadioButton("Hail");
    rbtab =new JRadioButton("Tabuk");
    rbji =new JRadioButton("Jizan");
    rbasir =new JRadioButton("Asir");
     
     
    rbFirst.setBounds(400,140,50,30);
    rbeco.setBounds(500,140,100,30);
    rbbus.setBounds(600,140,100,30);
     
    rbw.setBounds(280,240,130,20);
    rbo.setBounds(280,260,100,20);
    rbh.setBounds(280,280,100,20);
    rbar.setBounds(280,300,100,20);
    rbm.setBounds(280,320,100,20);
     
    rbmo.setBounds(420,240,100,20);
    rbva.setBounds(420,260,100,20);
    rbto.setBounds(420,280,100,20);
    rbot.setBounds(420,300,100,20);
    rbq.setBounds(420,320,100,20);
     
    rbb.setBounds(550,240,100,20);
    rbs.setBounds(550,260,100,20);
    rbf.setBounds(550,280,100,20);
    rbca.setBounds(550,300,130,20);
    rbboa.setBounds(550,320,130,20);
     
    rbp.setBounds(700,240,100,20);
    rbtac.setBounds(700,260,130,20);
    rbpu.setBounds(700,280,130,20);
    rbpe.setBounds(700,300,130,20);
    rbtr.setBounds(700,320,100,20);
     
    rbri.setBounds(850,240,130,20);
    rbha.setBounds(850,260,230,20);
    rbtab.setBounds(850,280,230,20);
    rbji.setBounds(850,300,230,20);
    rbasir.setBounds(850,320,230,20);
     
    add(rbFirst);
    add(rbeco);
    add(rbbus);
    add(rbw);
    add(rbo);
    add(rbh);
    add(rbar);
    add(rbm);
     
    add(rbb);
    add(rbs);
    add(rbf);
    add(rbca);
    add(rbboa);
     
    add(rbp);
    add(rbtac);
    add(rbpe);
    add(rbpu);
    add(rbtr);
     
    add(rbmo);
    add(rbva);
    add(rbto);
    add(rbot);
    add(rbq);
     
    add(rbri);
    add(rbha);
    add(rbtab);
    add(rbji);
    add(rbasir);
     
    rbFirst.addActionListener(this);
    rbeco.addActionListener(this);
    rbbus.addActionListener(this);
     
    rbw.addActionListener(this);
    rbo.addActionListener(this);
    rbh.addActionListener(this);
    rbm.addActionListener(this);
    rbar.addActionListener(this);
     
    rbmo.addActionListener(this);
    rbot.addActionListener(this);
    rbto.addActionListener(this);
    rbva.addActionListener(this);
    rbq.addActionListener(this);
     
    rbb.addActionListener(this);
    rbs.addActionListener(this);
    rbf.addActionListener(this);
    rbca.addActionListener(this);
    rbboa.addActionListener(this);
     
    rbp.addActionListener(this);
    rbtac.addActionListener(this);
    rbpe.addActionListener(this);
    rbpu.addActionListener(this);
    rbtr.addActionListener(this);
     
    rbri.addActionListener(this);
    rbha.addActionListener(this);
    rbtab.addActionListener(this);
    rbji.addActionListener(this);
    rbasir.addActionListener(this);
     
    btnadd=new JButton("Add");
    btnedit=new JButton("Edit");
    btnsearch=new JButton("Search");
    btndelete=new JButton("Delete");
     
     
    btnadd.setBounds(200,410,100,30);
    btnedit.setBounds(310,410,100,30);
    btnsearch.setBounds(420,410,100,30);
    btndelete.setBounds(530,410,100,30);
     
     
    add(btnadd);
    add(btnedit);
    add(btnsearch);
    add(btndelete);
     
     
    btnadd.addActionListener(this);
    btnedit.addActionListener(this);
    btnsearch.addActionListener(this);
    btndelete.addActionListener(this);
     
     
     
    btnfirst=new JButton("First");
    btnnext=new JButton("Next");
    btnprev=new JButton("Previous");
    btnlast=new JButton("Last");
     
     
    btnfirst.setBounds(200,450,100,30);
    btnnext.setBounds(310,450,100,30);
    btnprev.setBounds(420,450,100,30);
    btnlast.setBounds(530,450,100,30);
     
     
    add(btnfirst);
    add(btnnext);
    add(btnprev);
    add(btnlast);
     
     
    btnfirst.addActionListener(this);
    btnnext.addActionListener(this);
    btnprev.addActionListener(this);
    btnlast.addActionListener(this);
     
    btnexit=new JButton("EXIT");
    btnexit.setBounds(360,510,100,30);
    add(btnexit);
    btnexit.addActionListener(this);
     
    btncompute=new JButton("Compute");
    btncompute.setToolTipText("Click this button to compute the total");
    btncompute.setBounds(80,275,100,30);
    add(btncompute);
    btncompute.addActionListener(this);
     
    dbOpen();
    }
    public void actionPerformed(ActionEvent ae)
    {
    try
    {
    if(ae.getActionCommand()=="Compute"){
     
    double total = 0.0;
    double date
     
    if(rbFirst.isSelected()){
    total +=5000;
    }
    if(rbeco.isSelected()){
    total+=2500;
     
    }
    if(rbbus.isSelected()){
    total+=1000;
    }
    if(rbw.isSelected()){
    total+=38274;
    date +=23;
    }
    if(rbo.isSelected()){
    total+=52782;
    date +=11;
    }
    if(rbb.isSelected()){
    total+=93117;
    date +=11;
    }
    if(rbs.isSelected()){
    total+=104537;
    date +=11;
    }
    if(rbf.isSelected()){
    total+=40450;
    date +=11;
     
    }
    if(rbmo.isSelected()){
    total+=71610;
    date +=23;
    }
    if(rbva.isSelected()){
    total+=55440;
    date +=30;
    }
    if(rbto.isSelected()){
    total+=62920;
    date +=24;
    }
    if(rbot.isSelected()){
    total+=73850;
    date +=24;
    }
    if(rbq.isSelected()){
    total+=70660;
    date +=23;
    }
    if(rbri.isSelected()){
    total+=51790;
    date +=19;
    }
    if(rbha.isSelected()){
    total+=80720;
    date +=24;
    }
    if(rbtab.isSelected()){
    total+=63950;
    date +=29;
    }
    if(rbji.isSelected()){
    total+=102800;
    date +=25;
    }
    if(rbasir.isSelected()){
    total+=52480;
    date +=23;
    }
    if(rbb.isSelected()){
    total+=93117;
    date +=33;
    }
    if(rbs.isSelected()){
    total+=104537;
    date +=39;
    }
    if(rbf.isSelected()){
    total+=40450;
    date +=41;
    }
    if(rbp.isSelected()){
    total+=144100;
    date +=27;
    }
    if(rbtac.isSelected()){
    total+=125778;
    date +=28;
    }
    if(rbpe.isSelected()){
    total+=142662;
    date +=48;
    }
    if(rbtr.isSelected()){
    total+=144427;
    date +=45;
    }
    if(rbb.isSelected()){
    total+=139122;
    date +=39;
    }
    if(rbs.isSelected()){
    total+=144727;
    date +=33;
    }
    if(rbf.isSelected()){
    total+=152505;
    date +=41;
    }
    if(rbboa.isSelected()){
    total+=139122;
    date +=56;
    }
    if(rbca.isSelected()){
    total+=158319;
    date +=42;
    }
    DecimalFormat dollars = new DecimalFormat("Php0.00");
    txttotal.setText(dollars.format(total));
    DateFormat sdf = new SimpleDateFormat("K:mm:ss a,z");
    txtarrival.setText(sdf.format(date));
     
     
    }
     
    if(ae.getActionCommand()=="Add")
    {
    txtticket.setText("");
    txtseat.setText("");
    txtclass.setText("");
    txtdestination.setText("");
    txtdepart.setText("");
    txtarrival.setText("");
     
    }
     
    if(ae.getActionCommand()=="Save")
    {
    stmt.executeUpdate("INSERT INTO STUDENTINFO VALUES('" + txtticket.getText() + "','" + txtseat.getText() + "','" + txtclass.getText() + "'," + txtdestination.getText() + "'," + txtarrival.getText() + "')");
    dbClose();
    dbOpen();
    }
    if(ae.getActionCommand()=="Delete")
    {
    stmt.executeUpdate("DELETE FROM STUDENTINFO WHERE ticket=" + txtticket.getText() + "");
    dbClose();
    dbOpen();
    }
    if(ae.getActionCommand()=="Search")
     
    {
    stmt.executeUpdate("SEARCH * FROM STUDENTINFO WHERE ticket=" + txtticket.getText() + "");
    dbClose();
    dbOpen();
    }
    if(ae.getActionCommand()=="Next")
    {
    if(rs.next())
    {
    setText();
    }
    else
    {
    JOptionPane.showMessageDialog(null, "You are already at Last Record", "Messarrival", JOptionPane.ERROR_MESSAGE);
    }
    }
    if(ae.getActionCommand()=="Previous")
    {
    if(rs.previous())
    {
    setText();
    }
    else
    {
    JOptionPane.showMessageDialog(null, "You Are Already At First Record", "Messarrival", JOptionPane.ERROR_MESSAGE);
    }
    }
    if (ae.getActionCommand()=="First")
    {
    if(rs.first())
    {
    setText();
    }
    }
    if (ae.getActionCommand()=="Last")
    {
    if(rs.last())
    {
    setText();
    }
    }
    if(ae.getActionCommand()=="EXIT")
    {
    System.exit(0);
    }
    }
    catch(Exception e)
    {
    e.printStackTrace();
    }
    }
     
     
    public void dbOpen()
    {
    try
    {
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
     
     
    con = DriverManager.getConnection("jdbcdbc:mydsn");
    stmt=con.createStatement(ResultSet.TYPE_SCROLL_SEN SITIVE,ResultSet.CONCUR_UPDATABLE);
    rs = stmt.executeQuery("Select * from STUDENTINFO");
    if(rs.next())
    setText();
    }catch(Exception e){}
    }
    public void dbClose()
    {
    try{stmt.close();
    rs.close();
    con.close();
    }catch(Exception e){}
    }
    public void setText(){
    try{
    txtticket.setText(rs.getString(1));
    txtseat.setText(rs.getString(2));
    txtclass.setText(rs.getString(3));
    txtdestination.setText(rs.getString(4));
    txtarrival.setText(rs.getString(5));
    txtdepart.setText(rs.getString(6));
    }catch(Exception ex){}
    }
    }
     
    class Frame
    {
    public static void main(String arg[])throws Exception
    {
     
     
    Frame1 f1=new Frame1();
     
     
    f1.setSize(1000,600);
     
     
    f1.setVisible(true);
     
    UIManager.setLookAndFeel("javax.swing.plaf.metal.M etalLookAndFeel");
    }
    }

  4. #4
    Junior Member
    Join Date
    Feb 2012
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: flight reservation code problem...

    Norm the 4:00:00 happens in this line:
    DateFormat sdf = new SimpleDateFormat("K:mm:ss a,z");

    and here's d full code:
    import javax.swing.*;
    import javax.swing.event.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.sql.*;
    import java.io.*;
    import java.text.*;
    class Frame1 extends JFrame implements ActionListener
    {
     
     
    JLabel lbl=new JLabel("FLIGHT RESERVATION SYSTEM");
     
    Font f=new Font("Broadway",Font.BOLD,45);
    Font f1=new Font("Comic Sans",Font.BOLD,15);
    Font f2=new Font("Bradley Hand",Font.BOLD,24);
     
    JLabel lblticket,lblseat,lblclass,lbldestination,lbldepar t,lblarrival,lbltotal,lbln,lblusa,lblcanada,lbls,l bla,lblae,lblbr,lblp;
    JTextField txtticket,txtseat,txtclass,txtdestination,txtdepar t,txtarrival,txttotal;
    JRadioButton rbFirst,rbeco, rbbus,rbw,rbo,rbh,rbm,rbar,rbmo,rbva,rbto,rbot,rbq ,rbb,rbs,rbf,rbca,rbboa,rbp,rbtac,rbpe,rbpu,rbtr,r bri,rbha,rbtab,rbji,rbasir;
    JButton btncompute, btnadd,btnedit,btnsearch,btndelete;
    JButton btnnext,btnprev,btnlast,btnfirst,btnexit;
    String gen;
    ResultSet rs=null;
    Connection con=null;
    Statement stmt=null;
     
    Frame1()
    {
     
    super("FLIGHT RESERVATION DETAILS");
    addWindowListener(new WindowAdapter(){
    public void windowClosing(WindowEvent we)
    {
    System.exit(0);
    }
     
    });
     
    setLayout(null);
     
    add(lbl);
     
    lbl.setBounds(50,60,860,40);
     
    // set the font of lbl label
    lbl.setFont(f);
     
     
    // initializa all the label which are declared in the example above with its caption name
    lblticket=new JLabel("TICKETNO:");
    lblseat=new JLabel("SEATNO:");
    lblclass=new JLabel("CLASS");
    lbldestination=new JLabel("DESTINATION");
    lbln=new JLabel ("NORTH AMERICA");
    lblusa=new JLabel("USA");
    lblcanada= new JLabel("Canada");
    lbls=new JLabel("SOUTH AMERICA");
    lblbr=new JLabel("Brazil");
    lblp= new JLabel("Peru");
    lbla=new JLabel("ASIA");
    lblae=new JLabel("UAE");
    lbldepart=new JLabel("DEPART TIME");
    lblarrival=new JLabel ("ARRIVAL TIME");
    lbltotal=new JLabel("TOTAL:");
     
    lblticket.setBounds(30,120,100,20);
    lblseat.setBounds(30,160,100,20);
    lblclass.setBounds(500,120,100,20);
    lbldestination.setBounds(500,170,300,20);
    lbln.setBounds(350,190,200,20);
    lblusa.setBounds(320,220,200,20);
    lblcanada.setBounds(430,220,200,20);
    lblbr.setBounds(560,220,200,20);
    lblp.setBounds(710,220,200,20);
    lbls.setBounds(580,190,200,20);
    lbla.setBounds(850,190,200,20);
    lblae.setBounds(870,220,200,20);
    lbldepart.setBounds(20,200,100,20);
    lblarrival.setBounds(20,220,100,20);
    lbltotal.setBounds(30,250,100,20);
     
    add(lblticket);
    add(lblseat);
    add(lblclass);
    add(lbldestination);
    add(lbldepart);
    add(lblarrival);
    add(lbltotal);
    add(lbln);
    add(lblusa);
    add(lblcanada);
    add(lbls);
    add(lblbr);
    add(lblp);
    add(lbla);
    add(lblae);
     
     
    lblticket.setFont(f1);
    lblseat.setFont(f1);
    lblclass.setFont(f2);
    lbldestination.setFont(f2);
    lbldepart.setFont(f1);
    lblarrival.setFont(f1);
    lbltotal.setFont(f1);
    lbln.setFont(f1);
    lbls.setFont(f1);
    lblbr.setFont(f1);
    lblp.setFont(f1);
    lbla.setFont(f1);
    lblae.setFont(f1);
    lblusa.setFont(f1);
    lblcanada.setFont(f1);
     
    txtticket=new JTextField(10);
    txtseat=new JTextField (10);
    txtdepart=new JTextField(10);
    txtarrival=new JTextField(10);
    txttotal= new JTextField(10);
     
     
    txtticket.setBounds(120,120,150,20);
    txtseat.setBounds(120,160,150,20);
    txtdepart.setBounds(120,200,150,20);
    txtarrival.setBounds(120,220,150,20);
    txttotal.setBounds(120,250,150,20);
     
     
    add(txtticket);
    add(txtseat);
    add(txtdepart);
    add(txtarrival);
    add(txttotal);
     
     
    rbFirst= new JRadioButton("First");
    rbeco= new JRadioButton("Economy");
    rbbus=new JRadioButton("Business");
    rbw= new JRadioButton("Washington D.C");
    rbo= new JRadioButton("Oklahama");
    rbh= new JRadioButton("Honolulu");
    rbar=new JRadioButton("Phoenix");
    rbm=new JRadioButton("New Mexico");
     
    rbmo=new JRadioButton("Montreal");
    rbva=new JRadioButton("Vancouver");
    rbto=new JRadioButton("Toronto");
    rbot=new JRadioButton("Ottawa");
    rbq=new JRadioButton("Quebec");
     
    rbb=new JRadioButton("Brasilia");
    rbs= new JRadioButton("Salvador");
    rbf= new JRadioButton("Fortaleza");
    rbca= new JRadioButton("Campo Grande");
    rbboa=new JRadioButton("Boa Vista");
     
    rbp=new JRadioButton("Lima");
    rbtac =new JRadioButton("Tacha");
    rbpu =new JRadioButton("Pucallpa");
    rbpe =new JRadioButton("Peura");
    rbtr =new JRadioButton("Trujillo");
     
    rbri=new JRadioButton("Riyadh");
    rbha =new JRadioButton("Hail");
    rbtab =new JRadioButton("Tabuk");
    rbji =new JRadioButton("Jizan");
    rbasir =new JRadioButton("Asir");
     
     
    rbFirst.setBounds(400,140,50,30);
    rbeco.setBounds(500,140,100,30);
    rbbus.setBounds(600,140,100,30);
     
    rbw.setBounds(280,240,130,20);
    rbo.setBounds(280,260,100,20);
    rbh.setBounds(280,280,100,20);
    rbar.setBounds(280,300,100,20);
    rbm.setBounds(280,320,100,20);
     
    rbmo.setBounds(420,240,100,20);
    rbva.setBounds(420,260,100,20);
    rbto.setBounds(420,280,100,20);
    rbot.setBounds(420,300,100,20);
    rbq.setBounds(420,320,100,20);
     
    rbb.setBounds(550,240,100,20);
    rbs.setBounds(550,260,100,20);
    rbf.setBounds(550,280,100,20);
    rbca.setBounds(550,300,130,20);
    rbboa.setBounds(550,320,130,20);
     
    rbp.setBounds(700,240,100,20);
    rbtac.setBounds(700,260,130,20);
    rbpu.setBounds(700,280,130,20);
    rbpe.setBounds(700,300,130,20);
    rbtr.setBounds(700,320,100,20);
     
    rbri.setBounds(850,240,130,20);
    rbha.setBounds(850,260,230,20);
    rbtab.setBounds(850,280,230,20);
    rbji.setBounds(850,300,230,20);
    rbasir.setBounds(850,320,230,20);
     
    add(rbFirst);
    add(rbeco);
    add(rbbus);
    add(rbw);
    add(rbo);
    add(rbh);
    add(rbar);
    add(rbm);
     
    add(rbb);
    add(rbs);
    add(rbf);
    add(rbca);
    add(rbboa);
     
    add(rbp);
    add(rbtac);
    add(rbpe);
    add(rbpu);
    add(rbtr);
     
    add(rbmo);
    add(rbva);
    add(rbto);
    add(rbot);
    add(rbq);
     
    add(rbri);
    add(rbha);
    add(rbtab);
    add(rbji);
    add(rbasir);
     
    rbFirst.addActionListener(this);
    rbeco.addActionListener(this);
    rbbus.addActionListener(this);
     
    rbw.addActionListener(this);
    rbo.addActionListener(this);
    rbh.addActionListener(this);
    rbm.addActionListener(this);
    rbar.addActionListener(this);
     
    rbmo.addActionListener(this);
    rbot.addActionListener(this);
    rbto.addActionListener(this);
    rbva.addActionListener(this);
    rbq.addActionListener(this);
     
    rbb.addActionListener(this);
    rbs.addActionListener(this);
    rbf.addActionListener(this);
    rbca.addActionListener(this);
    rbboa.addActionListener(this);
     
    rbp.addActionListener(this);
    rbtac.addActionListener(this);
    rbpe.addActionListener(this);
    rbpu.addActionListener(this);
    rbtr.addActionListener(this);
     
    rbri.addActionListener(this);
    rbha.addActionListener(this);
    rbtab.addActionListener(this);
    rbji.addActionListener(this);
    rbasir.addActionListener(this);
     
    btnadd=new JButton("Add");
    btnedit=new JButton("Edit");
    btnsearch=new JButton("Search");
    btndelete=new JButton("Delete");
     
     
    btnadd.setBounds(200,410,100,30);
    btnedit.setBounds(310,410,100,30);
    btnsearch.setBounds(420,410,100,30);
    btndelete.setBounds(530,410,100,30);
     
     
    add(btnadd);
    add(btnedit);
    add(btnsearch);
    add(btndelete);
     
     
    btnadd.addActionListener(this);
    btnedit.addActionListener(this);
    btnsearch.addActionListener(this);
    btndelete.addActionListener(this);
     
     
     
    btnfirst=new JButton("First");
    btnnext=new JButton("Next");
    btnprev=new JButton("Previous");
    btnlast=new JButton("Last");
     
     
    btnfirst.setBounds(200,450,100,30);
    btnnext.setBounds(310,450,100,30);
    btnprev.setBounds(420,450,100,30);
    btnlast.setBounds(530,450,100,30);
     
     
    add(btnfirst);
    add(btnnext);
    add(btnprev);
    add(btnlast);
     
     
    btnfirst.addActionListener(this);
    btnnext.addActionListener(this);
    btnprev.addActionListener(this);
    btnlast.addActionListener(this);
     
    btnexit=new JButton("EXIT");
    btnexit.setBounds(360,510,100,30);
    add(btnexit);
    btnexit.addActionListener(this);
     
    btncompute=new JButton("Compute");
    btncompute.setToolTipText("Click this button to compute the total");
    btncompute.setBounds(80,275,100,30);
    add(btncompute);
    btncompute.addActionListener(this);
     
    dbOpen();
    }
    public void actionPerformed(ActionEvent ae)
    {
    try
    {
    if(ae.getActionCommand()=="Compute"){
     
    double total = 0.0;
    double date
     
    if(rbFirst.isSelected()){
    total +=5000;
    }
    if(rbeco.isSelected()){
    total+=2500;
     
    }
    if(rbbus.isSelected()){
    total+=1000;
    }
    if(rbw.isSelected()){
    total+=38274;
    date +=23;
    }
    if(rbo.isSelected()){
    total+=52782;
    date +=11;
    }
    if(rbb.isSelected()){
    total+=93117;
    date +=11;
    }
    if(rbs.isSelected()){
    total+=104537;
    date +=11;
    }
    if(rbf.isSelected()){
    total+=40450;
    date +=11;
     
    }
    if(rbmo.isSelected()){
    total+=71610;
    date +=23;
    }
    if(rbva.isSelected()){
    total+=55440;
    date +=30;
    }
    if(rbto.isSelected()){
    total+=62920;
    date +=24;
    }
    if(rbot.isSelected()){
    total+=73850;
    date +=24;
    }
    if(rbq.isSelected()){
    total+=70660;
    date +=23;
    }
    if(rbri.isSelected()){
    total+=51790;
    date +=19;
    }
    if(rbha.isSelected()){
    total+=80720;
    date +=24;
    }
    if(rbtab.isSelected()){
    total+=63950;
    date +=29;
    }
    if(rbji.isSelected()){
    total+=102800;
    date +=25;
    }
    if(rbasir.isSelected()){
    total+=52480;
    date +=23;
    }
    if(rbb.isSelected()){
    total+=93117;
    date +=33;
    }
    if(rbs.isSelected()){
    total+=104537;
    date +=39;
    }
    if(rbf.isSelected()){
    total+=40450;
    date +=41;
    }
    if(rbp.isSelected()){
    total+=144100;
    date +=27;
    }
    if(rbtac.isSelected()){
    total+=125778;
    date +=28;
    }
    if(rbpe.isSelected()){
    total+=142662;
    date +=48;
    }
    if(rbtr.isSelected()){
    total+=144427;
    date +=45;
    }
    if(rbb.isSelected()){
    total+=139122;
    date +=39;
    }
    if(rbs.isSelected()){
    total+=144727;
    date +=33;
    }
    if(rbf.isSelected()){
    total+=152505;
    date +=41;
    }
    if(rbboa.isSelected()){
    total+=139122;
    date +=56;
    }
    if(rbca.isSelected()){
    total+=158319;
    date +=42;
    }
    DecimalFormat dollars = new DecimalFormat("Php0.00");
    txttotal.setText(dollars.format(total));
    DateFormat sdf = new SimpleDateFormat("K:mm:ss a,z");
    txtarrival.setText(sdf.format(date));
     
     
    }
     
    if(ae.getActionCommand()=="Add")
    {
    txtticket.setText("");
    txtseat.setText("");
    txtclass.setText("");
    txtdestination.setText("");
    txtdepart.setText("");
    txtarrival.setText("");
     
    }
     
    if(ae.getActionCommand()=="Save")
    {
    stmt.executeUpdate("INSERT INTO STUDENTINFO VALUES('" + txtticket.getText() + "','" + txtseat.getText() + "','" + txtclass.getText() + "'," + txtdestination.getText() + "'," + txtarrival.getText() + "')");
    dbClose();
    dbOpen();
    }
    if(ae.getActionCommand()=="Delete")
    {
    stmt.executeUpdate("DELETE FROM STUDENTINFO WHERE ticket=" + txtticket.getText() + "");
    dbClose();
    dbOpen();
    }
    if(ae.getActionCommand()=="Search")
     
    {
    stmt.executeUpdate("SEARCH * FROM STUDENTINFO WHERE ticket=" + txtticket.getText() + "");
    dbClose();
    dbOpen();
    }
    if(ae.getActionCommand()=="Next")
    {
    if(rs.next())
    {
    setText();
    }
    else
    {
    JOptionPane.showMessageDialog(null, "You are already at Last Record", "Messarrival", JOptionPane.ERROR_MESSAGE);
    }
    }
    if(ae.getActionCommand()=="Previous")
    {
    if(rs.previous())
    {
    setText();
    }
    else
    {
    JOptionPane.showMessageDialog(null, "You Are Already At First Record", "Messarrival", JOptionPane.ERROR_MESSAGE);
    }
    }
    if (ae.getActionCommand()=="First")
    {
    if(rs.first())
    {
    setText();
    }
    }
    if (ae.getActionCommand()=="Last")
    {
    if(rs.last())
    {
    setText();
    }
    }
    if(ae.getActionCommand()=="EXIT")
    {
    System.exit(0);
    }
    }
    catch(Exception e)
    {
    e.printStackTrace();
    }
    }
     
     
    public void dbOpen()
    {
    try
    {
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
     
     
    con = DriverManager.getConnection("jdbcdbc:mydsn");
    stmt=con.createStatement(ResultSet.TYPE_SCROLL_SEN SITIVE,ResultSet.CONCUR_UPDATABLE);
    rs = stmt.executeQuery("Select * from STUDENTINFO");
    if(rs.next())
    setText();
    }catch(Exception e){}
    }
    public void dbClose()
    {
    try{stmt.close();
    rs.close();
    con.close();
    }catch(Exception e){}
    }
    public void setText(){
    try{
    txtticket.setText(rs.getString(1));
    txtseat.setText(rs.getString(2));
    txtclass.setText(rs.getString(3));
    txtdestination.setText(rs.getString(4));
    txtarrival.setText(rs.getString(5));
    txtdepart.setText(rs.getString(6));
    }catch(Exception ex){}
    }
    }
     
    class Frame
    {
    public static void main(String arg[])throws Exception
    {
     
     
    Frame1 f1=new Frame1();
     
     
    f1.setSize(1000,600);
     
     
    f1.setVisible(true);
     
    UIManager.setLookAndFeel("javax.swing.plaf.metal.M etalLookAndFeel");
    }
    }

  5. #5
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: flight reservation code problem...

    This is the line that formats the date:
    txtarrival.setText(sdf.format(date));

    What is the value of the variable: date when that statement is executed? Is it always the same?

  6. #6
    Junior Member
    Join Date
    Feb 2012
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: flight reservation code problem...

    the value of the variable date should be d value of the (depart time) and then when the user choose a destination country, there's a time that will add to the depart time so d user will know how long is d flight

  7. #7
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: flight reservation code problem...

    the variable date should be
    Print out the value of the date variable so you can see what it really is. You want it to have some value, but what value does it really have?

Similar Threads

  1. problem in my code java code graph editeur
    By kisokiso in forum Java Theory & Questions
    Replies: 5
    Last Post: January 6th, 2012, 08:36 AM
  2. How to write a simple automated reservation JAVA application
    By thekongss in forum Java Theory & Questions
    Replies: 3
    Last Post: November 30th, 2011, 12:31 AM
  3. problem in my code
    By dhruvguys in forum What's Wrong With My Code?
    Replies: 1
    Last Post: April 11th, 2011, 05:18 AM
  4. problem with choice for airline reservation
    By chonch in forum What's Wrong With My Code?
    Replies: 1
    Last Post: April 6th, 2011, 10:30 PM
  5. Java Assignment 2011 - reservation
    By bs09it in forum Member Introductions
    Replies: 2
    Last Post: March 1st, 2011, 08:25 PM