pias
Posts: 1
Nickname: pias
Registered: Aug, 2003
jbutton problem
Posted: Aug 10, 2003 5:32 AM
Advertisement
please verify the code below, I just cant see button, Why? import java.awt.*; import java.applet.Applet; import java.awt.event.*; import javax.swing.*; import javax.swing.tree.*; import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.table.*; import java.sql.*; import java.sql.Date; import javax.swing.JOptionPane; import java.util.*; import javax.swing.border.*; import javax.swing.border.*; import java.awt.*; import java.awt.event.*; import java.lang.reflect.*; import java.util.*; import javax.swing.*; import javax.swing.event.*; import javax.swing.tree.*; import java.awt.font.*; import java.awt.geom.*; import java.awt.print.*; public class FinalResult05 { public static JFrame frame; public static void main(String arg[]) { frame=new TrainTree(); frame.setBounds(400,100,800,600); frame.show(); JDialog frame1=new InfoOfSeatEditDialog(FinalResult05.frame,"Ok",true); } } class TrainTree extends JFrame { public JSplitPane jSplitPane; public Component leftSide; public Component rightSide; public Component leftBottomSide; public Container contentPane; public TrainTree() { rightSide=new RightSide(); leftSide=new LeftSide(); jSplitPane=new JSplitPane(JSplitPane.HORIZONTAL_SPLIT); jSplitPane.setContinuousLayout(true); jSplitPane.setOneTouchExpandable(true); jSplitPane.setLeftComponent(new JScrollPane(leftSide, ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS)); jSplitPane.setRightComponent(rightSide); contentPane=getContentPane(); contentPane.add(jSplitPane,"Center"); } } class RightSide extends JPanel implements ActionListener,MouseListener { public static ArrayList arrListOfCompAndSeat; public static ArrayList arrListOfSeatStatus; public static ArrayList arrListOfPassComp; public static ArrayList arrListOfPassSeat; public static String selectedSeatName; public static String selectedSeatStatus; public static String selectedCompName; public static JButton selectedSeat; public static JPanel selectedCompartment; public ResultSet rs; public GridBagLayout gbl=new GridBagLayout(); public GridBagConstraints gbc=new GridBagConstraints(); public JPanel rightPanel; public static JComboBox comboTrain; public PopupMenu popupMenu; private void addComponent(Container container, Component c,int x, int y, int w, int h) { //gbc.insets=new Insets(5,5,5,5); gbc.gridx = x; gbc.gridy = y; gbc.gridwidth = w; gbc.gridheight = h; container.add(c, gbc); //gbl.setConstraints(c,gbc); //add(c); } private void addComponent(Component c,int x, int y, int w, int h) { //gbc.insets=new Insets(5,5,5,5); gbc.gridx = x; gbc.gridy = y; gbc.gridwidth = w; gbc.gridheight = h; add(c, gbc); //gbl.setConstraints(c,gbc); //add(c); } public RightSide() { setLayout(new BorderLayout()); rightPanel=new JPanel(); rightPanel.setLayout(gbl); comboTrain=new JComboBox(); comboTrain.setEditable(false); comboTrain.addItem(""); comboTrain.addActionListener(this); add(comboTrain,"North"); add(new JScrollPane(rightPanel, ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS),"Center"); gbl=new GridBagLayout(); gbc=new GridBagConstraints(); gbc.weightx = 0; gbc.weighty = 0; gbc.fill = GridBagConstraints.HORIZONTAL; gbc.anchor = GridBagConstraints.WEST; doLayout(); } Border etched=BorderFactory.createEtchedBorder(); Border raised=BorderFactory.createRaisedBevelBorder(); Border border; public void actionPerformed(ActionEvent ae) { if(ae.getSource()==comboTrain) { if(!LeftSide.arrOfPass_ApDesDaTiCompSeTickCoNaAdPhIDaIti.isEmpty()) LeftSide.arrOfPass_ApDesDaTiCompSeTickCoNaAdPhIDaIti.clear(); // ( 0) Passenger TrainTableName LeftSide.arrOfPass_ApDesDaTiCompSeTickCoNaAdPhIDaIti .add(0,comboTrain.getSelectedItem()); // ( 1) Passenger Train String tableName=(String)comboTrain.getSelectedItem(); int a=tableName.indexOf("Date"); LeftSide.arrOfPass_ApDesDaTiCompSeTickCoNaAdPhIDaIti .add(1,tableName.substring(0,a-1)); // ( 2) Passenger Aperture Station LeftSide.arrOfPass_ApDesDaTiCompSeTickCoNaAdPhIDaIti .add(2,LeftSide.comboAper.getSelectedItem()); // ( 3) Passenger Destination Station LeftSide.arrOfPass_ApDesDaTiCompSeTickCoNaAdPhIDaIti .add(3,LeftSide.comboDest.getSelectedItem()); // ( 4) Passenger Journey Date LeftSide.arrOfPass_ApDesDaTiCompSeTickCoNaAdPhIDaIti .add(4,LeftSide.comboDate.getSelectedItem()); // ( 5) Passenger Journey Time LeftSide.arrOfPass_ApDesDaTiCompSeTickCoNaAdPhIDaIti .add(5,LeftSide.comboTime.getSelectedItem()); // ( 6) Passenger Issue Date LeftSide.arrOfPass_ApDesDaTiCompSeTickCoNaAdPhIDaIti .add(6,"Date"); // ( 7) Passenger Issue Time LeftSide.arrOfPass_ApDesDaTiCompSeTickCoNaAdPhIDaIti .add(7,"Time"); // ( 8) Passenger Ticket Serial LeftSide.arrOfPass_ApDesDaTiCompSeTickCoNaAdPhIDaIti .add(8,"Ticket"); // ( 9) Passenger Cost LeftSide.arrOfPass_ApDesDaTiCompSeTickCoNaAdPhIDaIti .add(9,"Cost"); // (10) Passenger Name LeftSide.arrOfPass_ApDesDaTiCompSeTickCoNaAdPhIDaIti .add(10,"Name"); // (11) Passenger Address LeftSide.arrOfPass_ApDesDaTiCompSeTickCoNaAdPhIDaIti .add(11,"Address"); // (12) Passenger Phone LeftSide.arrOfPass_ApDesDaTiCompSeTickCoNaAdPhIDaIti .add(12,"Phone"); System.out.println(LeftSide.arrOfPass_ApDesDaTiCompSeTickCoNaAdPhIDaIti); //removeAll(); try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); // force loading of driver String url = "jdbc:odbc:sazib"; String user = "PUBLIC"; String password = "PUBLIC"; Connection conn = DriverManager.getConnection(url, user,password); Statement stat = conn.createStatement( ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); System.out.println("1"); if (rs != null) rs.close(); String query = "SELECT * FROM "+comboTrain.getSelectedItem(); System.out.println("2"); rs = stat.executeQuery(query); System.out.println("3"); arrListOfCompAndSeat=new ArrayList(10); arrListOfSeatStatus=new ArrayList(10); a=0; int count1=0; System.out.println("4"); while(rs.next()) { System.out.println("5"); if(rs.getInt(1)>a) { System.out.println("6"); a=rs.getInt(1); System.out.println("7"); JPanel p=new JPanel(); p.setName(""+a);// a = no. of Comp System.out.println("\t\t\t"+p.getName()); p.setToolTipText(""+a); arrListOfCompAndSeat.add(p); count1++; System.out.println("\t"+p.getToolTipText()); } System.out.println("8"); JButton b=new JButton(rs.getString("Seat")); count1++; b.setName(""+count1); // count = no. of (panel + button) // = no. of (Comp + Seat )) b.addActionListener(this); String str=rs.getString("SeatStatus"); if(str.compareTo("-1")==0) { ImageIcon img=new ImageIcon("rejected.gif"); b.setIcon(img); } if(str.compareTo("0")==0) { ImageIcon img=new ImageIcon("blank.gif"); b.setIcon(img); } if(str.compareTo("1")==0) { ImageIcon img=new ImageIcon("booked.gif"); b.setIcon(img); } System.out.println("9"); b.setToolTipText(str); // str = seat status System.out.println("9"); arrListOfCompAndSeat.add(b); arrListOfSeatStatus.add(rs.getString("SeatStatus")); } System.out.println("9"); if(rightPanel!=null) { rightPanel.removeAll(); } int count=0; String seatName="",compNo=""; for(int i=0,x=-1,y=-1,j=-1,p=-1,q=0;i<=arrListOfCompAndSeat.size()-1; i++) { if(arrListOfCompAndSeat.get(i) instanceof JPanel) { count++; x++; j=i; if(x%2==0){y++;x=0;} p++; ((JPanel)arrListOfCompAndSeat.get(i)).setLayout(gbl); border=BorderFactory.createTitledBorder(etched,"Compartment "+count); ((JPanel)arrListOfCompAndSeat.get(i)).setBorder(border); compNo=((JPanel)arrListOfCompAndSeat.get(i)) .getName(); addComponent(rightPanel,(JPanel)arrListOfCompAndSeat.get(i), x,y,1,1); i++; } seatName=((JButton)arrListOfCompAndSeat.get(i)) .getActionCommand(); String seatSerial=seatName.substring(1); int z=Integer.parseInt(seatSerial)%4; if(z==1)q=0; if(z==2)q=1; if(z==3)q=3; if(z==0)q=4; ((JButton)arrListOfCompAndSeat.get(i)).addMouseListener(this); addComponent((JPanel)arrListOfCompAndSeat.get(j), (JButton)arrListOfCompAndSeat.get(i),q,p,1,1); if(z==2) addComponent((JPanel)arrListOfCompAndSeat.get(j), new JLabel(" "),2,p,1,1); ((JPanel)arrListOfCompAndSeat.get(j)).doLayout(); if(z==0)p++; rightPanel.doLayout(); doLayout(); } rightPanel.doLayout(); doLayout(); } catch(ClassNotFoundException cnfe) { System.out.println("Error " + cnfe); } catch(SQLException sqle) { System.out.println("Error1 " + sqle); } rightPanel.doLayout(); doLayout(); } } public void mouseClicked(MouseEvent me) { } public void mouseReleased(MouseEvent me) { if(me.getSource() instanceof JButton && !me.isPopupTrigger()) { selectedSeat=(JButton)me.getSource(); selectedSeatName=selectedSeat.getActionCommand(); /* */ selectedCompName=""; System.out.println("\n\n\ns1"); int i; for(i=Integer.parseInt(selectedSeat.getName())-1;i>=0;i--) if(arrListOfCompAndSeat.get(i) instanceof JPanel) { selectedCompartment=(JPanel)arrListOfCompAndSeat.get(i); selectedCompName=(String)selectedCompartment.getName(); break; } System.out.println("s2"); int flag=0; for(i=13;i<LeftSide.arrOfPass_ApDesDaTiCompSeTickCoNaAdPhIDaIti.size();i=i+2 ) { if((JButton)LeftSide.arrOfPass_ApDesDaTiCompSeTickCoNaAdPhIDaIti.get(i+1)==sele ctedSeat) { if("0".compareTo(selectedSeat.getToolTipText())==0) { ImageIcon img=new ImageIcon("blank.gif"); selectedSeat.setIcon(img); } else if("1".compareTo(selectedSeat.getToolTipText())==0) { ImageIcon img=new ImageIcon("booked.gif"); selectedSeat.setIcon(img); } if("-1".compareTo(selectedSeat.getToolTipText())==0) { ImageIcon img=new ImageIcon("rejected.gif"); selectedSeat.setIcon(img); } LeftSide.arrOfPass_ApDesDaTiCompSeTickCoNaAdPhIDaIti.remove(i+1); LeftSide.arrOfPass_ApDesDaTiCompSeTickCoNaAdPhIDaIti.remove(i); LeftSide.arrOfPass_ApDesDaTiCompSeTickCoNaAdPhIDaIti.trimToSize(); flag=1; break; } } System.out.println("s3"); if(flag==0) { Icon prevImg=selectedSeat.getIcon(); ImageIcon img=new ImageIcon("selected.gif"); selectedSeat.setIcon(img); LeftSide.arrOfPass_ApDesDaTiCompSeTickCoNaAdPhIDaIti .add(selectedCompartment); LeftSide.arrOfPass_ApDesDaTiCompSeTickCoNaAdPhIDaIti .add(selectedSeat); } System.out.println("s4"); String selectedSeatStatus=selectedSeat.getToolTipText(); System.out.println("\n"+selectedCompName+"\t"+selectedSeatName+"\t"+selectedSea tStatus); for(i=13;i<LeftSide.arrOfPass_ApDesDaTiCompSeTickCoNaAdPhIDaIti.size();i=i+2 ) { System.out.print("[("+i+")"+((JPanel)LeftSide.arrOfPass_ApDesDaTiCompSeTickCoNa AdPhIDaIti.get(i)).getName()+", "); System.out.print("("+(i+1)+")"+((JButton)LeftSide.arrOfPass_ApDesDaTiCompSeTick CoNaAdPhIDaIti.get(i+1)).getActionCommand()+"]"); } } if(me.getSource() instanceof JButton && me.isPopupTrigger()) { System.out.println("\nok 1 "); popupMenu=new PopupMenuItem(); rightPanel.add(popupMenu); /* */ selectedSeat=(JButton)me.getSource(); selectedSeatName=selectedSeat.getActionCommand(); /* */ selectedCompName=""; int i; System.out.println("\nok 2"); for(i=Integer.parseInt(selectedSeat.getName())-1;i>=0;i--) if(arrListOfCompAndSeat.get(i) instanceof JPanel) { selectedCompartment=(JPanel)arrListOfCompAndSeat.get(i); selectedCompName=(String)selectedCompartment.getName(); break; } System.out.println("\nok 3"); int flag=0; for(int j=LeftSide.arrOfPass_ApDesDaTiCompSeTickCoNaAdPhIDaIti.size()-1;j>=13;j=j-2) if((JButton)LeftSide.arrOfPass_ApDesDaTiCompSeTickCoNaAdPhIDaIti.get(j)==me.get Source()) { flag=1; break; } System.out.println("\nok 4"); if(flag==0) { ImageIcon img=new ImageIcon("selected.gif"); selectedSeat.setIcon(img); LeftSide.arrOfPass_ApDesDaTiCompSeTickCoNaAdPhIDaIti .add(selectedCompartment); LeftSide.arrOfPass_ApDesDaTiCompSeTickCoNaAdPhIDaIti .add(selectedSeat); } String selectedSeatStatus=selectedSeat.getToolTipText(); System.out.println("\n"+selectedCompName+"\t"+selectedSeatName+"\t"+selectedSea tStatus); if(selectedSeatStatus.compareTo("0")==0) { PopupMenuItem.menuItemReserve.setEnabled(true); PopupMenuItem.menuItemEdit.setEnabled(false); PopupMenuItem.menuItemReturn.setEnabled(false); } else if(selectedSeatStatus.compareTo("1")==0) { PopupMenuItem.menuItemReserve.setEnabled(false); PopupMenuItem.menuItemEdit.setEnabled(true); PopupMenuItem.menuItemReturn.setEnabled(true); } else { PopupMenuItem.menuItemReserve.setEnabled(false); PopupMenuItem.menuItemEdit.setEnabled(false); PopupMenuItem.menuItemReturn.setEnabled(false); } popupMenu.show(me.getComponent(),me.getX(),me.getY()); } else if(me.getSource() instanceof JPanel) { selectedSeat=(JButton)me.getSource(); selectedSeatName=selectedSeat.getActionCommand(); /* */ selectedCompName=""; System.out.println("\n\n\ns1"); int i; int flag=0; for(i=13;i<LeftSide.arrOfPass_ApDesDaTiCompSeTickCoNaAdPhIDaIti.size();i=i+2 ) { JButton b =(JButton)LeftSide.arrOfPass_ApDesDaTiCompSeTickCoNaAdPhIDaIti.get(i+1); if("0".compareTo(b.getToolTipText())==0) { ImageIcon img=new ImageIcon("blank.gif"); b.setIcon(img); } else if("1".compareTo(b.getToolTipText())==0) { ImageIcon img=new ImageIcon("booked.gif"); b.setIcon(img); } if("-1".compareTo(b.getToolTipText())==0) { ImageIcon img=new ImageIcon("rejected.gif"); b.setIcon(img); } LeftSide.arrOfPass_ApDesDaTiCompSeTickCoNaAdPhIDaIti.remove(i+1); LeftSide.arrOfPass_ApDesDaTiCompSeTickCoNaAdPhIDaIti.remove(i); LeftSide.arrOfPass_ApDesDaTiCompSeTickCoNaAdPhIDaIti.trimToSize(); } } } public void mouseEntered(MouseEvent me) { } public void mouseExited(MouseEvent me) { } public void mousePressed(MouseEvent me) { } } class LeftSide extends JPanel implements ActionListener { public static ArrayList arrOfPass_ApDesDaTiCompSeTickCoNaAdPhIDaIti=new ArrayList(3); public static ArrayList arrOfScheduledTrain=new ArrayList(3); public static Icon prevIcon; public JPanel leftPanel; public GridBagLayout gbl; public GridBagConstraints gbc; public static JComboBox comboAper; public JLabel labelAper; public static JComboBox comboDest; public JLabel labelDest; public static JComboBox comboDate; public JLabel labelDate; public static JComboBox comboTime; public JLabel labelTime; public JButton buttonSearch; private void addComponent(Container container, Component c,int x, int y, int w, int h) { //gbc.insets=new Insets(5,5,5,5); gbc.gridx = x; gbc.gridy = y; gbc.gridwidth = w; gbc.gridheight = h; container.add(c, gbc); //gbl.setConstraints(c,gbc); //add(c); } public LeftSide() { gbl=new GridBagLayout(); gbc=new GridBagConstraints(); leftPanel=new JPanel(); leftPanel.setLayout(gbl); add(leftPanel,"SOUTH"); labelAper=new JLabel("Aper From"); comboAper=new JComboBox(); comboAper.setEditable(true); comboAper.addItem("Dhaka"); comboDest=new JComboBox(); comboDest.setEditable(true); comboDest.addItem("Chittagong"); labelDest=new JLabel("Destinition"); comboDate=new JComboBox(); comboDate.setEditable(true); comboDate.addItem("7/7/2003"); labelDate=new JLabel("Date"); comboTime=new JComboBox(); comboTime.setEditable(true); comboTime.addItem("6:00AM"); labelTime=new JLabel("Time"); buttonSearch=new JButton("Search"); buttonSearch.addActionListener(this); gbc.weightx = 0; gbc.weighty = 0; gbc.fill = GridBagConstraints.HORIZONTAL; gbc.anchor = GridBagConstraints.EAST; addComponent(leftPanel,labelAper, 0, 0, 1, 1); addComponent(leftPanel,comboAper, 1, 0, 1, 1); addComponent(leftPanel,labelDest, 0, 1, 1, 1); addComponent(leftPanel,comboDest, 1, 1, 1, 1); addComponent(leftPanel,labelDate, 0, 2, 1, 1); addComponent(leftPanel,comboDate, 1, 2, 1, 1); addComponent(leftPanel,labelTime, 0, 3, 1, 1); addComponent(leftPanel,comboTime, 1, 3, 1, 1); addComponent(leftPanel,buttonSearch, 1, 5, 1, 1); doLayout(); } public void actionPerformed(ActionEvent ae) { System.out.println("1"); String aper=((String)comboAper.getSelectedItem()).trim(); System.out.println("11"); String dest=((String)comboDest.getSelectedItem()).trim(); System.out.println("111"); String date=((String)comboDate.getSelectedItem()).trim(); System.out.println("1111"); String time=((String)comboTime.getSelectedItem()).trim(); int flagAper=0,flagDest=0,flagDate=0,flagTime=0; if(ae.getSource()==buttonSearch) { if(dest.compareTo("")!=0)flagDest=1; if(date.compareTo("")!=0)flagDate=1; if(time.compareTo("")!=0)flagTime=1; if(LeftSide.arrOfPass_ApDesDaTiCompSeTickCoNaAdPhIDaIti!=null) for(int i=LeftSide.arrOfPass_ApDesDaTiCompSeTickCoNaAdPhIDaIti.size()-1;i>=0;i--) LeftSide.arrOfPass_ApDesDaTiCompSeTickCoNaAdPhIDaIti.remove(i); // ( 0) Passenger TrainTableName LeftSide.arrOfPass_ApDesDaTiCompSeTickCoNaAdPhIDaIti .add(0,"TrainTable"); // ( 1) Passenger Train //String tableName=(String)RightSide.comboTrain.getSelectedItem(); //int a=tableName.indexOf("Date"); LeftSide.arrOfPass_ApDesDaTiCompSeTickCoNaAdPhIDaIti .add(1,"Train"); // ( 2) Passenger Aperture Station LeftSide.arrOfPass_ApDesDaTiCompSeTickCoNaAdPhIDaIti .add(2,LeftSide.comboAper.getSelectedItem()); // ( 3) Passenger Destination Station LeftSide.arrOfPass_ApDesDaTiCompSeTickCoNaAdPhIDaIti .add(3,LeftSide.comboDest.getSelectedItem()); // ( 4) Passenger Journey Date LeftSide.arrOfPass_ApDesDaTiCompSeTickCoNaAdPhIDaIti .add(4,LeftSide.comboDate.getSelectedItem()); // ( 5) Passenger Journey Time LeftSide.arrOfPass_ApDesDaTiCompSeTickCoNaAdPhIDaIti .add(5,LeftSide.comboTime.getSelectedItem()); // ( 6) Passenger Issue Date LeftSide.arrOfPass_ApDesDaTiCompSeTickCoNaAdPhIDaIti .add(6,"Date"); // ( 7) Passenger Issue Time LeftSide.arrOfPass_ApDesDaTiCompSeTickCoNaAdPhIDaIti .add(7,"Time"); // ( 8) Passenger Ticket Serial LeftSide.arrOfPass_ApDesDaTiCompSeTickCoNaAdPhIDaIti .add(8,"Ticket"); // ( 9) Passenger Cost LeftSide.arrOfPass_ApDesDaTiCompSeTickCoNaAdPhIDaIti .add(9,"Cost"); // (10) Passenger Name LeftSide.arrOfPass_ApDesDaTiCompSeTickCoNaAdPhIDaIti .add(10,"Name"); // (11) Passenger Address LeftSide.arrOfPass_ApDesDaTiCompSeTickCoNaAdPhIDaIti .add(11,"Address"); // (12) Passenger Phone LeftSide.arrOfPass_ApDesDaTiCompSeTickCoNaAdPhIDaIti .add(12,"Phone"); System.out.println("\t"+LeftSide.arrOfPass_ApDesDaTiCompSeTickCoNaAdPhIDaIti.si ze()); try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); String url = "jdbc:odbc:sazib"; String user = "PUBLIC"; String password = "PUBLIC"; Connection conn = DriverManager.getConnection(url, user,password); Statement stat = conn.createStatement( ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); System.out.println("11111"); DatabaseMetaData md = conn.getMetaData(); ResultSet rs = md.getTables(null, null, null, new String[] { "TABLE" }); arrOfScheduledTrain.clear(); while (rs.next()) { arrOfScheduledTrain.add(rs.getString(3)); } rs.close(); for(int i=0;i<arrOfScheduledTrain.size();i++) System.out.println(arrOfScheduledTrain.get(i)); if(flagDest==0 && flagDate==0 && flagTime==0) { for(int i=0;i<arrOfScheduledTrain.size();i++) { if((((String)arrOfScheduledTrain.get(i)).trim()) .indexOf("Date")==-1) { arrOfScheduledTrain.remove(i); i--; } } } if(flagDest==0 && flagDate==0 && flagTime==1) { String s=((String)comboTime.getSelectedItem()).trim(); s=s.replace(':','_'); System.out.println("\t"+s); for(int i=0;i<arrOfScheduledTrain.size();i++) { if((((String)arrOfScheduledTrain.get(i)).trim()) .indexOf("Time"+s)==-1) { arrOfScheduledTrain.remove(i); i--; } } } if(flagDest==0 && flagDate==1 && flagTime==0) { String s=((String)comboDate.getSelectedItem()).trim(); s=s.replace('/','_'); System.out.println("\t"+s); for(int i=0;i<arrOfScheduledTrain.size();i++) { if((((String)arrOfScheduledTrain.get(i)).trim()) .indexOf("Date"+s)==-1) { arrOfScheduledTrain.remove(i); i--; } } } if(flagDest==0 && flagDate==1 && flagTime==1) { String s2=((String)comboDate.getSelectedItem()).trim(); s2=s2.replace('/','_'); String s3=((String)comboTime.getSelectedItem()).trim(); s3=s3.replace(':','_'); System.out.println("\t"+s2+" "+s3); for(int i=0;i<arrOfScheduledTrain.size();i++) { if((((String)arrOfScheduledTrain.get(i)).trim()) .indexOf("Date"+s2+"_Time"+s3)==-1) { arrOfScheduledTrain.remove(i); i--; } } } if(flagDest==1 && flagDate==0 && flagTime==0) { } if(flagDest==1 && flagDate==0 && flagTime==1) { } if(flagDest==1 && flagDate==1 && flagTime==0) { } if(flagDest==1 && flagDate==1 && flagTime==1) { } System.out.println("\t222"); for(int i=0;i<arrOfScheduledTrain.size();i++) System.out.println(arrOfScheduledTrain.get(i)); RightSide.comboTrain.removeAllItems(); for(int i=0;i<arrOfScheduledTrain.size();i++) { RightSide.comboTrain.addItem(arrOfScheduledTrain.get(i)); } } catch(ClassNotFoundException cnfe) { System.out.println("Error " + cnfe); } catch(SQLException sqle) { System.out.println("Error1 " + sqle); } } } } class PopupMenuItem extends PopupMenu implements ActionListener { public static MenuItem menuItemReserve,menuItemEdit,menuItemReturn; public static String passAper; public static String passDest; public static String passName; public static String passAddress; public static String passPhone; public static int passCost; public static String passTicket; public static Date passDate; public static Time passTime; public static Date passIssueDate; public static Time passIssueTime; public static int passFine; public PopupMenuItem() { menuItemReserve=new MenuItem("Reserve"); menuItemEdit=new MenuItem("Edit"); menuItemReturn=new MenuItem("Return"); //menuItemReturn.setMnemonic('B'); menuItemReserve.setEnabled(false); menuItemEdit.setEnabled(false); menuItemReturn.setEnabled(false); menuItemReserve.addActionListener(this); menuItemEdit.addActionListener(this); menuItemReturn.addActionListener(this); add(menuItemReserve); add(menuItemEdit); add(menuItemReturn); } public void actionPerformed(ActionEvent ae) { if(ae.getSource()==menuItemReserve) { JDialog frame1=new InfoOfSeatReserveDialog(FinalResult05.frame,"Ok",true); } if(ae.getSource()==menuItemEdit) { JDialog frame1=new InfoOfSeatEditDialog(FinalResult05.frame,"Ok",true); } if(ae.getSource()==menuItemReturn) { JDialog frame1=new InfoOfSeatReturnDialog(FinalResult05.frame,"Ok",true); } else { for(int j=LeftSide.arrOfPass_ApDesDaTiCompSeTickCoNaAdPhIDaIti.size()-1;j>=13;j--) LeftSide.arrOfPass_ApDesDaTiCompSeTickCoNaAdPhIDaIti.remove(j); } } } class InfoOfSeatReserveDialog extends JDialog implements ActionListener { public static String tableName; public static String passTrainName; public static String passDate; public static String passTime; public static String passAper; public static String passDest; public static String passName; public static String passAddress; public static String passPhone; public static int passCost; public static ArrayList arrPassTrainDateTimeComSeat; public static String passTicket; public static String passIssueDate; public static String passIssueTime; public static int passFine; public JPanel leftPanel; public GridBagLayout gbl; public GridBagConstraints gbc; public static JTextField tfDate; public JLabel labelDate; public static JTextField tfTime; public JLabel labelTime; public static JTextField tfAper; public JLabel labelAper; public static JTextField tfDest; public JLabel labelDest; public static JTextField tfPassSeat; public JLabel labelPassSeat; public static JTextField tfTicket; public JLabel labelTicket; public static JTextField tfName; public JLabel labelName; public static JTextField tfAddress; public JLabel labelAddress; public static JTextField tfPhone; public JLabel labelPhone; public static JTextField tfCost; public JLabel labelCost; public static JButton buttonOk; public static JButton buttonCancel; public String ss; private void addComponent(Container container, Component c,int x, int y, int w, int h) { //gbc.insets=new Insets(5,5,5,5); gbc.gridx = x; gbc.gridy = y; gbc.gridwidth = w; gbc.gridheight = h; container.add(c, gbc); //gbl.setConstraints(c,gbc); //add(c); } public InfoOfSeatReserveDialog(JFrame f,String s,boolean b) { super(f,s,b); gbl=new GridBagLayout(); gbc=new GridBagConstraints(); setSize(300,400); leftPanel=new JPanel(); leftPanel.setLayout(gbl); getContentPane().add(leftPanel); getContentPane().setLayout(gbl); tfDate=new JTextField(); tfTime=new JTextField(); tfAper=new JTextField(); tfDest=new JTextField(); tfPassSeat=new JTextField(); tfTicket=new JTextField(); tfCost=new JTextField(); tfName=new JTextField(); tfAddress=new JTextField(); tfPhone=new JTextField(); labelDate=new JLabel("*Date"); labelTime=new JLabel("*Time"); labelAper=new JLabel("*Aperture"); labelDest=new JLabel("*Dest"); labelPassSeat=new JLabel("*Seat"); labelTicket=new JLabel("Ticket"); labelCost=new JLabel("*Cost"); labelName=new JLabel("Name"); labelAddress=new JLabel("Address"); labelPhone=new JLabel("Phone"); tfDate.setEditable(false); //tfSeat.setEditable(false); tfTime.setEditable(false); //tfTicket.setEditable(false); tfAper.setEditable(false); //tfDest.setEditable(false); tfDest.setEditable(false); //tfCost.setEditable(false); tfPassSeat.setEditable(false); //tfSeat.setEditable(false); tfTicket.setEditable(true); //tfTicket.setEditable(false); tfCost.setEditable(false); //tfCost.setEditable(false); //tfCost.setText("xxx"); buttonOk=new JButton("Ok"); buttonCancel=new JButton("Cancel"); buttonOk.addActionListener(this); buttonCancel.addActionListener(this); gbc.weightx = 0; gbc.weighty = 0; gbc.fill = GridBagConstraints.HORIZONTAL; gbc.anchor = GridBagConstraints.EAST; addComponent(leftPanel,labelDate, 0, 0, 1, 1); addComponent(leftPanel,tfDate, 1, 0, 1, 1); addComponent(leftPanel,labelTime, 0, 1, 1, 1); addComponent(leftPanel,tfTime, 1, 1, 1, 1); addComponent(leftPanel,labelAper, 0, 2, 1, 1); addComponent(leftPanel,tfAper, 1, 2, 1, 1); addComponent(leftPanel,labelDest, 0, 3, 1, 1); addComponent(leftPanel,tfDest, 1, 3, 1, 1); addComponent(leftPanel,labelPassSeat, 0, 4, 1, 1); addComponent(leftPanel,tfPassSeat, 1, 4, 1, 1); addComponent(leftPanel,labelTicket, 0, 5, 1, 1); addComponent(leftPanel,tfTicket, 1, 5, 1, 1); addComponent(leftPanel,labelName, 0, 6, 1, 1); addComponent(leftPanel,tfName, 1, 6, 1, 1); addComponent(leftPanel,labelAddress, 0, 7, 1, 1); addComponent(leftPanel,tfAddress, 1, 7, 1, 1); addComponent(leftPanel,labelPhone, 0, 8, 1, 1); addComponent(leftPanel,tfPhone, 1, 8, 1, 1); addComponent(leftPanel,buttonOk, 0, 9, 1, 1); addComponent(leftPanel,buttonCancel, 1, 9, 1, 1); doLayout(); tfAper.setText((String)LeftSide.arrOfPass_ApDesDaTiCompSeTickCoNaAdPhIDaIti.get (2)); tfDest.setText((String)LeftSide.arrOfPass_ApDesDaTiCompSeTickCoNaAdPhIDaIti.get (3)); tfDate.setText((String)LeftSide.arrOfPass_ApDesDaTiCompSeTickCoNaAdPhIDaIti.get (4)); tfTime.setText((String)LeftSide.arrOfPass_ApDesDaTiCompSeTickCoNaAdPhIDaIti.get (5)); tfTicket.setText((String)LeftSide.arrOfPass_ApDesDaTiCompSeTickCoNaAdPhIDaIti.g et(8)); tfCost.setText((String)LeftSide.arrOfPass_ApDesDaTiCompSeTickCoNaAdPhIDaIti.get (9)); tfName.setText((String)LeftSide.arrOfPass_ApDesDaTiCompSeTickCoNaAdPhIDaIti.get (10)); tfAddress.setText((String)LeftSide.arrOfPass_ApDesDaTiCompSeTickCoNaAdPhIDaIti. get(11)); tfPhone.setText((String)LeftSide.arrOfPass_ApDesDaTiCompSeTickCoNaAdPhIDaIti.ge t(12)); ss="["; System.out.println(LeftSide.arrOfPass_ApDesDaTiCompSeTickCoNaAdPhIDaIti); for(int i=13;i<LeftSide.arrOfPass_ApDesDaTiCompSeTickCoNaAdPhIDaIti.size();i=i+2) { JPanel pa=(JPanel)LeftSide.arrOfPass_ApDesDaTiCompSeTickCoNaAdPhIDaIti.get(i); ss=ss+pa.getName(); JButton bu=(JButton)LeftSide.arrOfPass_ApDesDaTiCompSeTickCoNaAdPhIDaIti.get(i+1); ss=ss+bu.getActionCommand(); if(LeftSide.arrOfPass_ApDesDaTiCompSeTickCoNaAdPhIDaIti.size()-2!=i) ss=ss+", "; } ss=ss+"]"; tfPassSeat.setText(ss); show(); } public void actionPerformed(ActionEvent ae) { if(ae.getSource()==buttonOk) { System.out.println( "Train ::"+(String)LeftSide.arrOfPass_ApDesDaTiCompSeTickCoNaAdPhIDaIti.get(1)+ "\nDate ::"+tfDate.getText()+ "\nTime ::"+tfTime.getText()+ "\nName ::"+tfName.getText()+ "\nAddress ::"+tfAddress.getText()+ "\nPhone ::"+tfPhone.getText()+ "\nAperture::"+tfAper.getText()+ "\nDestin ::"+tfDest.getText()+ "\nCost ::"+tfCost.getText()+ "\nSeat ::"+tfPassSeat.getText()+ "\nTicket ::"+tfTicket.getText()); LeftSide.arrOfPass_ApDesDaTiCompSeTickCoNaAdPhIDaIti.set(8,tfTicket.getText()); LeftSide.arrOfPass_ApDesDaTiCompSeTickCoNaAdPhIDaIti.set(10,tfName.getText()); LeftSide.arrOfPass_ApDesDaTiCompSeTickCoNaAdPhIDaIti.set(11,tfAddress.getText() ); LeftSide.arrOfPass_ApDesDaTiCompSeTickCoNaAdPhIDaIti.set(12,tfPhone.getText()); setVisible(false); try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); // force loading of driver String url = "jdbc:odbc:sazib"; String user = "PUBLIC"; String password = "PUBLIC"; Connection conn = DriverManager.getConnection(url, user,password); Statement stat = conn.createStatement( ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); System.out.println("1"); String update=""; for(int g=13;g<LeftSide.arrOfPass_ApDesDaTiCompSeTickCoNaAdPhIDaIti.size();g=g+2) { update=""; update = "UPDATE "+(String)LeftSide.arrOfPass_ApDesDaTiCompSeTickCoNaAdPhIDaIti.get(0) +"\n SET SeatStatus = '1'" +", Aper = '"+tfAper.getText() +"', Dest = '"+tfDest.getText() +"', TicketId = '"+(String)LeftSide.arrOfPass_ApDesDaTiCompSeTickCoNaAdPhIDaIti.get(8) +"', PassengerName = '"+tfName.getText() +"', Address = '"+tfAddress.getText() +"', Phone = '"+tfPhone.getText() +"', Taka = '"+tfCost.getText() +"'\nWHERE Comp = '"+((JPanel)LeftSide.arrOfPass_ApDesDaTiCompSeTickCoNaAdPhIDaIti.get(g)).getToo lTipText() +"' AND Seat = '"+((JButton)LeftSide.arrOfPass_ApDesDaTiCompSeTickCoNaAdPhIDaIti.get(g+1)).get ActionCommand() +"' AND SeatStatus = '0'"; System.out.println(update); System.out.println("2"); int i = stat.executeUpdate(update); ((JButton)LeftSide.arrOfPass_ApDesDaTiCompSeTickCoNaAdPhIDaIti.get(g+1)).setToo lTipText("1"); ImageIcon img=new ImageIcon("booked.gif"); ((JButton)LeftSide.arrOfPass_ApDesDaTiCompSeTickCoNaAdPhIDaIti.get(g+1)).setIco n(img); //System.out.println("3 "+i); doLayout(); } update=""; update = "UPDATE Ticket \nSET" //+" TicketId = '"+LeftSide.arrOfPass_ApDesDaTiCompSeTickCoNaAdPhIDaIti.get(8) +" IssueDate = '"+(String)LeftSide.arrOfPass_ApDesDaTiCompSeTickCoNaAdPhIDaIti.get(6) +"', IssueTime = '"+(String)LeftSide.arrOfPass_ApDesDaTiCompSeTickCoNaAdPhIDaIti.get(7) +"', JourneyDate = '"+(String)LeftSide.arrOfPass_ApDesDaTiCompSeTickCoNaAdPhIDaIti.get(4) +"', JourneyTime = '"+(String)LeftSide.arrOfPass_ApDesDaTiCompSeTickCoNaAdPhIDaIti.get(5) +"', Train = '"+(String)LeftSide.arrOfPass_ApDesDaTiCompSeTickCoNaAdPhIDaIti.get(1) //+"', '"+((JPanel)LeftSide.arrOfPass_ApDesDaTiCompSeTickCoNaAdPhIDaIti.get(g)).getToo lTipText() //+"', '"+((JButton)LeftSide.arrOfPass_ApDesDaTiCompSeTickCoNaAdPhIDaIti.get(g+1)).get ActionCommand() +"', CompSeat = '"+ss +"', Taka = '"+(String)LeftSide.arrOfPass_ApDesDaTiCompSeTickCoNaAdPhIDaIti.get(9) +"'\nWHERE TicketId = '"+tfTicket.getText() +"'"; System.out.println(update); int i = stat.executeUpdate(update); } catch(ClassNotFoundException cnfe) { System.out.println("Error " + cnfe); } catch(SQLException sqle) { System.out.println("Error1 " + sqle); } Paper paper=new Paper(); paper.setImageableArea(10,10,220,320); paper.setSize(240,340); PrinterJob printJob = PrinterJob.getPrinterJob(); //if (pageFormat == null) // pageFormat = printJob.defaultPage(); PageFormat pageFormat=new PageFormat(); pageFormat.setPaper(paper); PrintPanel printPanel=new PrintPanel(); printJob.setPrintable(printPanel, pageFormat); pageFormat = printJob.pageDialog(pageFormat); //if (printJob.printDialog()) //{ try { printJob.print(); } catch (PrinterException exception) { JOptionPane.showMessageDialog(this, exception); } for(int j=LeftSide.arrOfPass_ApDesDaTiCompSeTickCoNaAdPhIDaIti.size()-1;j>=13;j--) LeftSide.arrOfPass_ApDesDaTiCompSeTickCoNaAdPhIDaIti.remove(j); } if(ae.getSource()==buttonCancel) { //for(int j=LeftSide.arrOfPass_ApDesDaTiCompSeTickCoNaAdPhIDaIti.size()-1;j>=13;j--) // LeftSide.arrOfPass_ApDesDaTiCompSeTickCoNaAdPhIDaIti.remove(j); for(int j=LeftSide.arrOfPass_ApDesDaTiCompSeTickCoNaAdPhIDaIti.size()-1;j>13;j=j-2) { int flag=0; JButton b =(JButton)LeftSide.arrOfPass_ApDesDaTiCompSeTickCoNaAdPhIDaIti.get(j); if("-1".compareTo(b.getToolTipText())==0) { ImageIcon img=new ImageIcon("rejected.gif"); b.setIcon(img); } else if("0".compareTo(b.getToolTipText())==0) { ImageIcon img=new ImageIcon("blank.gif"); b.setIcon(img); } else if("1".compareTo(b.getToolTipText())==0) { ImageIcon img=new ImageIcon("booked.gif"); b.setIcon(img); } LeftSide.arrOfPass_ApDesDaTiCompSeTickCoNaAdPhIDaIti.remove(j); LeftSide.arrOfPass_ApDesDaTiCompSeTickCoNaAdPhIDaIti.remove(j-1); } doLayout(); setVisible(false); } } } class InfoOfSeatEditDialog extends JDialog implements ActionListener ,KeyListener { public static String trainTableName; public static String date; public static String time; //public static String tableName; //public static String passTrainName; //public static String passDate; //public static String passTime; //public static String passAper; //public static String passDest; public static String passName; public static String passAddress; public static String passPhone; //public static int passCost; public static ArrayList arrPassTrainDateTimeComSeat; public static String passTicket; //public static String passIssueDate; //public static String passIssueTime; //public static int passFine; public JPanel leftPanel; public GridBagLayout gbl; public GridBagConstraints gbc; public static JTextField tfTicket; public JLabel labelTicket; public static JTextField tfIssueDate; public JLabel labelIssueDate; public static JTextField tfIssueTime; public JLabel labelIssueTime; public static JTextField tfDate; public JLabel labelDate; public static JTextField tfTime; public JLabel labelTime; public static JTextField tfTrain; public JLabel labelTrain; public static JTextField tfAper; public JLabel labelAper; public static JTextField tfDest; public JLabel labelDest; public static JTextArea taCompSeat; public JLabel labelCompSeat; public static JTextField tfCost; public JLabel labelCost; public static JTextField tfPassName; public JLabel labelPassName; public static JTextField tfPassAddress; public JLabel labelPassAddress; public static JTextField tfPassPhone; public JLabel labelPassPhone; public static JTextField tfNewName; public JLabel labelNewName; public static JTextField tfNewAddress; public JLabel labelNewAddress; public static JTextField tfNewPhone; public JLabel labelNewPhone; //public static JTextField tfCost; public JLabel labelCost; public static JButton buttonSearch; public static JButton buttonOk; public static JButton buttonCancel; //public static JLabel labelQuery; private void addComponent(Container container, Component c,int x, int y, int w, int h) { //gbc.insets=new Insets(5,5,5,5); gbc.gridx = x; gbc.gridy = y; gbc.gridwidth = w; gbc.gridheight = h; container.add(c, gbc); //gbl.setConstraints(c,gbc); //add(c); } public InfoOfSeatEditDialog(JFrame f,String s,boolean b) { super(f,s,b); gbl=new GridBagLayout(); gbc=new GridBagConstraints(); setSize(300,500); leftPanel=new JPanel(); leftPanel.setLayout(gbl); getContentPane().add(leftPanel); getContentPane().setLayout(gbl); tfTicket=new JTextField(12); tfIssueDate=new JTextField(12); tfIssueTime=new JTextField(12); tfDate=new JTextField(12); tfTime=new JTextField(12); tfTrain=new JTextField(12); tfAper=new JTextField(12); tfDest=new JTextField(12); taCompSeat=new JTextArea(2,12); tfCost=new JTextField(12); tfPassName=new JTextField(12); tfPassAddress=new JTextField(12); tfPassPhone=new JTextField(12); tfNewName=new JTextField(12); tfNewAddress=new JTextField(12); tfNewPhone=new JTextField(12); labelTicket=new JLabel("Ticket"); labelIssueDate=new JLabel("Issue Date"); labelIssueTime=new JLabel("Issue Time"); labelDate=new JLabel("Date"); labelTime=new JLabel("Time"); labelTrain=new JLabel("Train"); labelAper=new JLabel("Aperture"); labelDest=new JLabel("Destination"); labelCompSeat=new JLabel("Seat(s)"); labelCost=new JLabel("Cost"); labelPassName=new JLabel("Pass. Name"); labelPassAddress=new JLabel("Pass. Address"); labelPassPhone=new JLabel("Pass. Phone"); labelNewName=new JLabel("New Name"); labelNewAddress=new JLabel("New Address"); labelNewPhone=new JLabel("New Phone"); buttonSearch=new JButton("Search"); buttonOk=new JButton("Ok"); buttonCancel=new JButton("Cancel"); buttonSearch.addActionListener(this); buttonOk.addActionListener(this); buttonCancel.addActionListener(this); //labelDate=new JLabel("*Date"); labelTime=new JLabel("*Time"); //labelAper=new JLabel("*Aperture"); labelDest=new JLabel("*Dest"); //labelPassSeat=new JLabel("*Seat"); //labelTicket=new JLabel("Ticket"); //labelCost=new JLabel("Cost"); //labelName=new JLabel("Name"); //labelAddress=new JLabel("Address"); //labelPhone=new JLabel("Phone"); tfIssueDate.setEditable(false); tfIssueTime.setEditable(false); tfDate.setEditable(false); tfTime.setEditable(false); tfTrain.setEditable(false); tfAper.setEditable(false); tfDest.setEditable(false); taCompSeat.setEditable(false); //tfDest.setEditable(false); tfCost.setEditable(false); //tfCost.setEditable(false); tfPassName.setEditable(false); tfPassAddress.setEditable(false); tfPassPhone.setEditable(false); tfNewName.setEditable(false); tfNewAddress.setEditable(false); tfNewPhone.setEditable(false); labelIssueDate.setEnabled(false); labelIssueTime.setEnabled(false); labelDate.setEnabled(false); labelTime.setEnabled(false); labelTrain.setEnabled(false); labelAper.setEnabled(false); labelDest.setEnabled(false); labelCompSeat.setEnabled(false); //labelDest.setEditable(false); labelCost.setEnabled(false); //tfCost.setEditable(false); labelPassName.setEnabled(false); labelPassAddress.setEnabled(false); labelPassPhone.setEnabled(false); labelNewName.setEnabled(false); labelNewAddress.setEnabled(false); labelNewPhone.setEnabled(false); buttonOk.setEnabled(false); buttonCancel.setEnabled(false); tfTicket.addKeyListener(this); //labelQuery=new JLabel(" "); gbc.weightx = 0; gbc.weighty = 0; gbc.fill = GridBagConstraints.HORIZONTAL; gbc.anchor = GridBagConstraints.EAST; //addComponent(leftPanel,labelDate, 0, 2, 1, 1); //addComponent(leftPanel,tfDate, 1, 2, 1, 1); //addComponent(leftPanel,labelTime, 0, 3, 1, 1); //addComponent(leftPanel,tfTime, 1, 3, 1, 1); //addComponent(leftPanel,labelAper, 0, 4, 1, 1); //addComponent(leftPanel,tfAper, 1, 4, 1, 1); //addComponent(leftPanel,labelDest, 0, 5, 1, 1); //addComponent(leftPanel,tfDest, 1, 5, 1, 1); //addComponent(leftPanel,labelPassSeat, 0, 6, 1, 1); //addComponent(leftPanel,tfPassSeat, 1, 6, 1, 1); //addComponent(leftPanel,labelTicket, 0, 7, 1, 1); addComponent(leftPanel,labelTicket, 0, 0, 1, 1); addComponent(leftPanel,tfTicket, 1, 0, 1, 1); addComponent(leftPanel,buttonSearch, 0, 1, 1, 1); addComponent(leftPanel,labelIssueDate, 0, 2, 1, 1); addComponent(leftPanel,tfIssueDate, 1, 2, 1, 1); addComponent(leftPanel,labelIssueTime, 0, 3, 1, 1); addComponent(leftPanel,tfIssueTime, 1, 3, 1, 1); addComponent(leftPanel,labelDate, 0, 4, 1, 1); addComponent(leftPanel,tfDate, 1, 4, 1, 1); addComponent(leftPanel,labelTime, 0, 5, 1, 1); addComponent(leftPanel,tfTime, 1, 5, 1, 1); addComponent(leftPanel,labelTrain, 0, 6, 1, 1); addComponent(leftPanel,tfTrain, 1, 6, 1, 1); addComponent(leftPanel,labelAper, 0, 7, 1, 1); addComponent(leftPanel,tfAper, 1, 7, 1, 1); addComponent(leftPanel,labelDest, 0, 8, 1, 1); addComponent(leftPanel,tfDest, 1, 8, 1, 1); addComponent(leftPanel,labelCompSeat, 0, 9, 1, 1); addComponent(leftPanel,new JScrollPane(taCompSeat), 1, 9, 1, 1); addComponent(leftPanel,labelCost, 0,10, 1, 1); addComponent(leftPanel,tfCost, 1,10, 1, 1); addComponent(leftPanel,labelPassName, 0,11, 1, 1); addComponent(leftPanel,tfPassName, 1,11, 1, 1); addComponent(leftPanel,labelPassAddress,0,12, 1, 1); addComponent(leftPanel,tfPassAddress, 1,12, 1, 1); addComponent(leftPanel,labelPassPhone, 0,13, 1, 1); addComponent(leftPanel,tfPassPhone, 1,13, 1, 1); addComponent(leftPanel,new JLabel("Enter New Information "),0,14, 1, 1); addComponent(leftPanel,labelNewName, 0,15, 1, 1); addComponent(leftPanel,tfNewName, 1,15, 1, 1); addComponent(leftPanel,labelNewAddress, 0,16, 1, 1); addComponent(leftPanel,tfNewAddress, 1,16, 1, 1); addComponent(leftPanel,labelNewPhone, 0,17, 1, 1); addComponent(leftPanel,tfNewPhone, 1,17, 1, 1); addComponent(leftPanel,buttonOk, 0,18, 1, 1); addComponent(leftPanel,buttonCancel, 1,18, 1, 1); //addComponent(leftPanel,labelQuery, 0, 2, 1, 1); doLayout(); //tfTicket.setEditable(true); //labelPassName.setEnabled(false); //tfPassName.setEnabled(false); //labelPassAddress.setEnabled(false); //tfPassAddress.setEnabled(false); //labelPassPhone.setEnabled(false); //tfPassPhone.setEnabled(false); buttonOk.setEnabled(false); buttonCancel.setEnabled(false); //tfAper.setText((String)LeftSide.arrOfPass_ApDesDaTiCompSeTickCoNaAdPhIDaIti.g et(2)); //tfDest.setText((String)LeftSide.arrOfPass_ApDesDaTiCompSeTickCoNaAdPhIDaIti.g et(3)); //tfDate.setText((String)LeftSide.arrOfPass_ApDesDaTiCompSeTickCoNaAdPhIDaIti.g et(4)); //tfTime.setText((String)LeftSide.arrOfPass_ApDesDaTiCompSeTickCoNaAdPhIDaIti.g et(5)); //tfTicket.setText((String)LeftSide.arrOfPass_ApDesDaTiCompSeTickCoNaAdPhIDaIti .get(8)); //tfCost.setText((String)LeftSide.arrOfPass_ApDesDaTiCompSeTickCoNaAdPhIDaIti.g et(9)); //tfName.setText((String)LeftSide.arrOfPass_ApDesDaTiCompSeTickCoNaAdPhIDaIti.g et(10)); //tfAddress.setText((String)LeftSide.arrOfPass_ApDesDaTiCompSeTickCoNaAdPhIDaIt i.get(11)); //tfPhone.setText((String)LeftSide.arrOfPass_ApDesDaTiCompSeTickCoNaAdPhIDaIti. get(12)); String ss=""; System.out.println(LeftSide.arrOfPass_ApDesDaTiCompSeTickCoNaAdPhIDaIti); for(int i=13;i<LeftSide.arrOfPass_ApDesDaTiCompSeTickCoNaAdPhIDaIti.size();i=i+2) { JPanel pa=(JPanel)LeftSide.arrOfPass_ApDesDaTiCompSeTickCoNaAdPhIDaIti.get(i); ss=ss+pa.getName(); JButton bu=(JButton)LeftSide.arrOfPass_ApDesDaTiCompSeTickCoNaAdPhIDaIti.get(i+1); ss=ss+bu.getActionCommand(); } //tfPassSeat.setText(ss); show(); } public void keyReleased(KeyEvent ke){} public void keyPressed(KeyEvent ke){} public void keyTyped(KeyEvent ke) { tfIssueDate.setText(""); tfIssueTime.setText(""); tfDate.setText(""); tfTime.setText(""); tfTrain.setText(""); tfAper.setText(""); tfDest.setText(""); tfPassName.setText(""); tfPassAddress.setText(""); tfPassPhone.setText(""); taCompSeat.setText(""); tfCost.setText(""); tfNewName.setText(""); tfNewAddress.setText(""); tfNewPhone.setText(""); tfIssueDate.setEditable(false); tfIssueTime.setEditable(false); tfDate.setEditable(false); tfTime.setEditable(false); tfTrain.setEditable(false); tfAper.setEditable(false); tfDest.setEditable(false); taCompSeat.setEditable(false); //tfDest.setEditable(false); tfCost.setEditable(false); //tfCost.setEditable(false); tfPassName.setEditable(false); tfPassAddress.setEditable(false); tfPassPhone.setEditable(false); tfNewName.setEditable(false); tfNewAddress.setEditable(false); tfNewPhone.setEditable(false); labelIssueDate.setEnabled(false); labelIssueTime.setEnabled(false); labelDate.setEnabled(false); labelTime.setEnabled(false); labelTrain.setEnabled(false); labelAper.setEnabled(false); labelDest.setEnabled(false); labelCompSeat.setEnabled(false); //labelDest.setEditable(false); labelCost.setEnabled(false); //tfCost.setEditable(false); labelPassName.setEnabled(false); labelPassAddress.setEnabled(false); labelPassPhone.setEnabled(false); labelNewName.setEnabled(false); labelNewAddress.setEnabled(false); labelNewPhone.setEnabled(false); buttonOk.setEnabled(false); buttonCancel.setEnabled(false); } public void actionPerformed(ActionEvent ae) { if(ae.getSource()==buttonSearch) { try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); // force loading of driver String url = "jdbc:odbc:sazib"; String user = "PUBLIC"; String password = "PUBLIC"; Connection conn = DriverManager.getConnection(url, user,password); Statement stat = conn.createStatement( ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); System.out.println("1"); //public ResultSet rs; //public ResultSet rs1; //if (rs != null) rs.close(); String query = "SELECT * FROM Ticket WHERE TicketId = '" +tfTicket.getText()+"'"; ; System.out.println("2"); ResultSet rs = stat.executeQuery(query); System.out.println("3"); rs.next(); tfIssueDate.setText(rs.getString("IssueDate")); tfIssueTime.setText(rs.getString("IssueTime")); tfDate.setText(rs.getString("JourneyDate")); tfTime.setText(rs.getString("JourneyTime")); tfTrain.setText(rs.getString("Train")); taCompSeat.setText(rs.getString("CompSeat")); tfCost.setText(rs.getString("Taka")); System.out.println("33"); date=tfDate.getText(); time=tfTime.getText(); date=date.replace('/','_'); date="Date"+date; time=time.replace(':','_'); time="Time"+time; rs.close(); } catch(ClassNotFoundException cnfe) { System.out.println("Error " + cnfe); } catch(SQLException sqle) { System.out.println("Error1 " + sqle); } try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); // force loading of driver String url = "jdbc:odbc:sazib"; String user = "PUBLIC"; String password = "PUBLIC"; Connection conn = DriverManager.getConnection(url, user,password); Statement stat = conn.createStatement(); //ResultSet.TYPE_SCROLL_INSENSITIVE, //ResultSet.CONCUR_READ_ONLY); trainTableName=tfTrain.getText()+"_"+date+"_"+time; System.out.println(trainTableName); //if (rs1 != null) rs1.close(); String query=""; query = " SELECT Aper, Dest, PassengerName, Address, Phone " +" FROM "+trainTableName +" WHERE TicketId = '"+tfTicket.getText()+"'"; System.out.println("4\n"+query); ResultSet rs1 = stat.executeQuery(query); //System.out.println("5"); //rs.beforeFirst(); //System.out.println("6"); //System.out.println("7"); rs1.next(); //{ System.out.println("Ok"); //else //{ tfAper.setText(rs1.getString("Aper")); tfDest.setText(rs1.getString("Dest")); tfPassName.setText(rs1.getString("PassengerName")); tfPassAddress.setText(rs1.getString("Address")); tfPassPhone.setText(rs1.getString("Phone")); System.out.println(tfPassName.getText()); tfNewName.setText(tfPassName.getText()); tfNewAddress.setText(tfPassAddress.getText()); tfNewPhone.setText(tfPassPhone.getText()); //System.out.println(queryResult); //labelQuery.setText(queryResult); //break; //} rs1.close(); tfIssueDate.setEditable(false); tfIssueTime.setEditable(false); tfDate.setEditable(false); tfTime.setEditable(false); tfTrain.setEditable(false); tfAper.setEditable(false); tfDest.setEditable(false); taCompSeat.setEditable(false); //tfDest.setEditable(false); tfCost.setEditable(false); //tfCost.setEditable(false); tfPassName.setEditable(false); tfPassAddress.setEditable(false); tfPassPhone.setEditable(false); tfNewName.setEditable(true); tfNewAddress.setEditable(true); tfNewPhone.setEditable(true); labelIssueDate.setEnabled(true); labelIssueTime.setEnabled(true); labelDate.setEnabled(true); labelTime.setEnabled(true); labelTrain.setEnabled(true); labelAper.setEnabled(true); labelDest.setEnabled(true); labelCompSeat.setEnabled(true); //labelDest.setEditable(false); labelCost.setEnabled(true); //tfCost.setEditable(false); labelPassName.setEnabled(true); labelPassAddress.setEnabled(true); labelPassPhone.setEnabled(true); labelNewName.setEnabled(true); labelNewAddress.setEnabled(true); labelNewPhone.setEnabled(true); buttonOk.setEnabled(true); buttonCancel.setEnabled(true); } catch(ClassNotFoundException cnfe) { System.out.println("Error " + cnfe); } catch(SQLException sqle) { System.out.println("Error1 " + sqle); } } else if(ae.getSource()==buttonOk) { try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); // force loading of driver String url = "jdbc:odbc:sazib"; String user = "PUBLIC"; String password = "PUBLIC"; Connection conn = DriverManager.getConnection(url, user,password); Statement stat = conn.createStatement(); //ResultSet.TYPE_SCROLL_INSENSITIVE, //ResultSet.CONCUR_READ_ONLY); System.out.println("1\n"+trainTableName); //public ResultSet rs; //public ResultSet rs1; //if (rs != null) rs.close(); String update = "UPDATE "+trainTableName +" SET PassengerName = '"+tfNewName.getText() +"', Address = '"+tfNewAddress.getText() +"', Phone = '"+tfNewPhone.getText() +"'\nWHERE TicketId = '"+tfTicket.getText()+"'"; System.out.println(update); System.out.println("2"); int i = stat.executeUpdate(update); System.out.println("3"); } catch(ClassNotFoundException cnfe) { System.out.println("Error " + cnfe); } catch(SQLException sqle) { System.out.println("Error1 " + sqle); } for(int j=LeftSide.arrOfPass_ApDesDaTiCompSeTickCoNaAdPhIDaIti.size()-1;j>13;j=j-2) { int flag=0; JButton b =(JButton)LeftSide.arrOfPass_ApDesDaTiCompSeTickCoNaAdPhIDaIti.get(j); if("-1".compareTo(b.getToolTipText())==0) { ImageIcon img=new ImageIcon("rejected.gif"); b.setIcon(img); } else if("0".compareTo(b.getToolTipText())==0) { ImageIcon img=new ImageIcon("blank.gif"); b.setIcon(img); } else if("1".compareTo(b.getToolTipText())==0) { ImageIcon img=new ImageIcon("booked.gif"); b.setIcon(img); } LeftSide.arrOfPass_ApDesDaTiCompSeTickCoNaAdPhIDaIti.remove(j); LeftSide.arrOfPass_ApDesDaTiCompSeTickCoNaAdPhIDaIti.remove(j-1); } } else if(ae.getSource()==buttonCancel) { for(int j=LeftSide.arrOfPass_ApDesDaTiCompSeTickCoNaAdPhIDaIti.size()-1;j>13;j=j-2) { int flag=0; JButton b =(JButton)LeftSide.arrOfPass_ApDesDaTiCompSeTickCoNaAdPhIDaIti.get(j); if("-1".compareTo(b.getToolTipText())==0) { ImageIcon img=new ImageIcon("rejected.gif"); b.setIcon(img); } else if("0".compareTo(b.getToolTipText())==0) { ImageIcon img=new ImageIcon("blank.gif"); b.setIcon(img); } else if("1".compareTo(b.getToolTipText())==0) { ImageIcon img=new ImageIcon("booked.gif"); b.setIcon(img); } LeftSide.arrOfPass_ApDesDaTiCompSeTickCoNaAdPhIDaIti.remove(j); LeftSide.arrOfPass_ApDesDaTiCompSeTickCoNaAdPhIDaIti.remove(j-1); } doLayout(); setVisible(false); } } } class InfoOfSeatReturnDialog extends JDialog implements ActionListener ,KeyListener { public static String trainTableName; public static String date; public static String time; //public static String tableName; //public static String passTrainName; //public static String passDate; //public static String passTime; //public static String passAper; //public static String passDest; public static String passName; public static String passAddress; public static String passPhone; //public static int passCost; public static ArrayList arrPassTrainDateTimeComSeat; public static String passTicket; //public static String passIssueDate; //public static String passIssueTime; //public static int passFine; public JPanel leftPanel; public GridBagLayout gbl; public GridBagConstraints gbc; public static JTextField tfTicket; public JLabel labelTicket; public static JTextField tfIssueDate; public JLabel labelIssueDate; public static JTextField tfIssueTime; public JLabel labelIssueTime; public static JTextField tfDate; public JLabel labelDate; public static JTextField tfTime; public JLabel labelTime; public static JTextField tfTrain; public JLabel labelTrain; public static JTextField tfAper; public JLabel labelAper; public static JTextField tfDest; public JLabel labelDest; public static JTextArea taCompSeat; public JLabel labelCompSeat; public static JTextField tfCost; public JLabel labelCost; public static JList listSeatList; public JLabel labelSeatList; public static JTextField tfPassName; public JLabel labelPassName; public static JTextField tfPassAddress; public JLabel labelPassAddress; public static JTextField tfPassPhone; public JLabel labelPassPhone; //public static JTextField tfNewName; public JLabel labelNewName; //public static JTextField tfNewAddress; public JLabel labelNewAddress; //public static JTextField tfNewPhone; public JLabel labelNewPhone; //public static JTextField tfCost; public JLabel labelCost; public static JButton buttonSearch; public static JButton buttonOk; public static JButton buttonCancel; //public static JLabel labelQuery; private void addComponent(Container container, Component c,int x, int y, int w, int h) { //gbc.insets=new Insets(5,5,5,5); gbc.gridx = x; gbc.gridy = y; gbc.gridwidth = w; gbc.gridheight = h; container.add(c, gbc); //gbl.setConstraints(c,gbc); //add(c); } public InfoOfSeatReturnDialog(JFrame f,String s,boolean b) { super(f,s,b); gbl=new GridBagLayout(); gbc=new GridBagConstraints(); setSize(500,500); leftPanel=new JPanel(); leftPanel.setLayout(gbl); getContentPane().add(leftPanel); getContentPane().setLayout(gbl); tfTicket=new JTextField(12); tfIssueDate=new JTextField(12); tfIssueTime=new JTextField(12); tfDate=new JTextField(12); tfTime=new JTextField(12); tfTrain=new JTextField(12); tfAper=new JTextField(12); tfDest=new JTextField(12); taCompSeat=new JTextArea(2,12); tfCost=new JTextField(12); listSeatList=new JList(); listSeatList.setVisibleRowCount(5); tfPassName=new JTextField(12); tfPassAddress=new JTextField(12); tfPassPhone=new JTextField(12); labelTicket=new JLabel("Ticket"); labelIssueDate=new JLabel("Issue Date"); labelIssueTime=new JLabel("Issue Time"); labelDate=new JLabel("Date"); labelTime=new JLabel("Time"); labelTrain=new JLabel("Train"); labelAper=new JLabel("Aperture"); labelDest=new JLabel("Destination"); labelCompSeat=new JLabel("Seat(s)"); labelCost=new JLabel("Cost"); labelSeatList=new JLabel("Select seat(s) to return ::"); labelPassName=new JLabel("Pass. Name"); labelPassAddress=new JLabel("Pass. Address"); labelPassPhone=new JLabel("Pass. Phone"); buttonSearch=new JButton("Search"); buttonOk=new JButton("Ok"); buttonCancel=new JButton("Cancel"); buttonSearch.addActionListener(this); buttonOk.addActionListener(this); buttonCancel.addActionListener(this); //labelDate=new JLabel("*Date"); labelTime=new JLabel("*Time"); //labelAper=new JLabel("*Aperture"); labelDest=new JLabel("*Dest"); //labelPassSeat=new JLabel("*Seat"); //labelTicket=new JLabel("Ticket"); //labelCost=new JLabel("Cost"); //labelName=new JLabel("Name"); //labelAddress=new JLabel("Address"); //labelPhone=new JLabel("Phone"); tfIssueDate.setEditable(false); tfIssueTime.setEditable(false); tfDate.setEditable(false); tfTime.setEditable(false); tfTrain.setEditable(false); tfAper.setEditable(false); tfDest.setEditable(false); taCompSeat.setEditable(false); //tfDest.setEditable(false); tfCost.setEditable(false); //tfCost.setEditable(false); listSeatList.setEnabled(false); tfPassName.setEditable(false); tfPassAddress.setEditable(false); tfPassPhone.setEditable(false); labelIssueDate.setEnabled(false); labelIssueTime.setEnabled(false); labelDate.setEnabled(false); labelTime.setEnabled(false); labelTrain.setEnabled(false); labelAper.setEnabled(false); labelDest.setEnabled(false); labelCompSeat.setEnabled(false); //labelDest.setEditable(false); labelCost.setEnabled(false); labelSeatList.setEnabled(false); labelPassName.setEnabled(false); labelPassAddress.setEnabled(false); labelPassPhone.setEnabled(false); buttonOk.setEnabled(false); buttonCancel.setEnabled(false); tfTicket.addKeyListener(this); //labelQuery=new JLabel(" "); gbc.weightx = 0; gbc.weighty = 0; gbc.fill = GridBagConstraints.HORIZONTAL; gbc.anchor = GridBagConstraints.EAST; //addComponent(leftPanel,labelDate, 0, 2, 1, 1); //addComponent(leftPanel,tfDate, 1, 2, 1, 1); //addComponent(leftPanel,labelTime, 0, 3, 1, 1); //addComponent(leftPanel,tfTime, 1, 3, 1, 1); //addComponent(leftPanel,labelAper, 0, 4, 1, 1); //addComponent(leftPanel,tfAper, 1, 4, 1, 1); //addComponent(leftPanel,labelDest, 0, 5, 1, 1); //addComponent(leftPanel,tfDest, 1, 5, 1, 1); //addComponent(leftPanel,labelPassSeat, 0, 6, 1, 1); //addComponent(leftPanel,tfPassSeat, 1, 6, 1, 1); //addComponent(leftPanel,labelTicket, 0, 7, 1, 1); addComponent(leftPanel,labelTicket, 0, 0, 1, 1); addComponent(leftPanel,tfTicket, 1, 0, 1, 1); addComponent(leftPanel,buttonSearch, 0, 1, 1, 1); addComponent(leftPanel,labelIssueDate, 0, 2, 1, 1); addComponent(leftPanel,tfIssueDate, 1, 2, 1, 1); addComponent(leftPanel,labelIssueTime, 0, 3, 1, 1); addComponent(leftPanel,tfIssueTime, 1, 3, 1, 1); addComponent(leftPanel,labelDate, 0, 4, 1, 1); addComponent(leftPanel,tfDate, 1, 4, 1, 1); addComponent(leftPanel,labelTime, 0, 5, 1, 1); addComponent(leftPanel,tfTime, 1, 5, 1, 1); addComponent(leftPanel,labelTrain, 0, 6, 1, 1); addComponent(leftPanel,tfTrain, 1, 6, 1, 1); addComponent(leftPanel,labelAper, 0, 7, 1, 1); addComponent(leftPanel,tfAper, 1, 7, 1, 1); addComponent(leftPanel,labelDest, 0, 8, 1, 1); addComponent(leftPanel,tfDest, 1, 8, 1, 1); addComponent(leftPanel,labelCompSeat, 0, 9, 1, 1); addComponent(leftPanel,new JScrollPane(taCompSeat), 1, 9, 1, 1); addComponent(leftPanel,labelCost, 0,10, 1, 1); addComponent(leftPanel,tfCost, 1,10, 1, 1); //addComponent(leftPanel,labelPassName, 0,11, 1, 1); //addComponent(leftPanel,tfPassName, 1,11, 1, 1); //addComponent(leftPanel,labelPassAddress,0,12, 1, 1); //addComponent(leftPanel,tfPassAddress, 1,12, 1, 1); //addComponent(leftPanel,labelPassPhone, 0,13, 1, 1); //addComponent(leftPanel,tfPassPhone, 1,13, 1, 1); //addComponent(leftPanel,new JLabel("Enter New Information "),0,14, 1, 1); addComponent(leftPanel,labelSeatList, 0,11, 3, 1); addComponent(leftPanel,new JScrollPane(listSeatList),0,12, 1, 1); addComponent(leftPanel,buttonOk, 0,18, 1, 1); addComponent(leftPanel,buttonCancel, 1,18, 1, 1); //addComponent(leftPanel,labelQuery, 0, 2, 1, 1); doLayout(); //tfTicket.setEditable(true); //labelPassName.setEnabled(false); //tfPassName.setEnabled(false); //labelPassAddress.setEnabled(false); //tfPassAddress.setEnabled(false); //labelPassPhone.setEnabled(false); //tfPassPhone.setEnabled(false); buttonOk.setEnabled(false); buttonCancel.setEnabled(false); //tfAper.setText((String)LeftSide.arrOfPass_ApDesDaTiCompSeTickCoNaAdPhIDaIti.g et(2)); //tfDest.setText((String)LeftSide.arrOfPass_ApDesDaTiCompSeTickCoNaAdPhIDaIti.g et(3)); //tfDate.setText((String)LeftSide.arrOfPass_ApDesDaTiCompSeTickCoNaAdPhIDaIti.g et(4)); //tfTime.setText((String)LeftSide.arrOfPass_ApDesDaTiCompSeTickCoNaAdPhIDaIti.g et(5)); //tfTicket.setText((String)LeftSide.arrOfPass_ApDesDaTiCompSeTickCoNaAdPhIDaIti .get(8)); //tfCost.setText((String)LeftSide.arrOfPass_ApDesDaTiCompSeTickCoNaAdPhIDaIti.g et(9)); //tfName.setText((String)LeftSide.arrOfPass_ApDesDaTiCompSeTickCoNaAdPhIDaIti.g et(10)); //tfAddress.setText((String)LeftSide.arrOfPass_ApDesDaTiCompSeTickCoNaAdPhIDaIt i.get(11)); //tfPhone.setText((String)LeftSide.arrOfPass_ApDesDaTiCompSeTickCoNaAdPhIDaIti. get(12)); String ss=""; System.out.println(LeftSide.arrOfPass_ApDesDaTiCompSeTickCoNaAdPhIDaIti); for(int i=13;i<LeftSide.arrOfPass_ApDesDaTiCompSeTickCoNaAdPhIDaIti.size();i=i+2) { JPanel pa=(JPanel)LeftSide.arrOfPass_ApDesDaTiCompSeTickCoNaAdPhIDaIti.get(i); ss=ss+pa.getName(); JButton bu=(JButton)LeftSide.arrOfPass_ApDesDaTiCompSeTickCoNaAdPhIDaIti.get(i+1); ss=ss+bu.getActionCommand(); } //tfPassSeat.setText(ss); show(); } public void keyReleased(KeyEvent ke){} public void keyPressed(KeyEvent ke){} public void keyTyped(KeyEvent ke) { tfIssueDate.setText(""); tfIssueTime.setText(""); tfDate.setText(""); tfTime.setText(""); tfTrain.setText(""); tfAper.setText(""); tfDest.setText(""); tfPassName.setText(""); tfPassAddress.setText(""); tfPassPhone.setText(""); taCompSeat.setText(""); tfCost.setText(""); tfIssueDate.setEditable(false); tfIssueTime.setEditable(false); tfDate.setEditable(false); tfTime.setEditable(false); tfTrain.setEditable(false); tfAper.setEditable(false); tfDest.setEditable(false); taCompSeat.setEditable(false); //tfDest.setEditable(false); tfCost.setEditable(false); //tfCost.setEditable(false); listSeatList.setEnabled(false); tfPassName.setEditable(false); tfPassAddress.setEditable(false); tfPassPhone.setEditable(false); labelIssueDate.setEnabled(false); labelIssueTime.setEnabled(false); labelDate.setEnabled(false); labelTime.setEnabled(false); labelTrain.setEnabled(false); labelAper.setEnabled(false); labelDest.setEnabled(false); labelCompSeat.setEnabled(false); //labelDest.setEditable(false); labelCost.setEnabled(false); //tfCost.setEditable(false); labelSeatList.setEnabled(false); labelPassName.setEnabled(false); labelPassAddress.setEnabled(false); labelPassPhone.setEnabled(false); buttonOk.setEnabled(false); buttonCancel.setEnabled(false); } public void actionPerformed(ActionEvent ae) { if(ae.getSource()==buttonSearch) { try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); // force loading of driver String url = "jdbc:odbc:sazib"; String user = "PUBLIC"; String password = "PUBLIC"; Connection conn = DriverManager.getConnection(url, user,password); Statement stat = conn.createStatement(); //ResultSet.TYPE_SCROLL_INSENSITIVE, //ResultSet.CONCUR_READ_ONLY); System.out.println("1"); //public ResultSet rs; //public ResultSet rs1; //if (rs != null) rs.close(); String query = "SELECT * FROM Ticket WHERE TicketId = '" +tfTicket.getText()+"'"; ; System.out.println("2"); ResultSet rs = stat.executeQuery(query); System.out.println("3"); rs.next(); tfIssueDate.setText(rs.getString("IssueDate")); tfIssueTime.setText(rs.getString("IssueTime")); tfDate.setText(rs.getString("JourneyDate")); tfTime.setText(rs.getString("JourneyTime")); tfTrain.setText(rs.getString("Train")); taCompSeat.setText(rs.getString("CompSeat")); tfCost.setText(rs.getString("Taka")); date=tfDate.getText(); time=tfTime.getText(); date=date.replace('/','_'); date="Date"+date; time=time.replace(':','_'); time="Time"+time; System.out.println("33 "+date+" "+time); rs.close(); } catch(ClassNotFoundException cnfe) { System.out.println("Error " + cnfe); } catch(SQLException sqle) { System.out.println("Error1 " + sqle); } try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); // force loading of driver String url = "jdbc:odbc:sazib"; String user = "PUBLIC"; String password = "PUBLIC"; Connection conn = DriverManager.getConnection(url, user,password); Statement stat = conn.createStatement(); //ResultSet.TYPE_SCROLL_INSENSITIVE, //ResultSet.CONCUR_READ_ONLY); trainTableName=tfTrain.getText()+"_"+date+"_"+time; System.out.println(trainTableName); //if (rs1 != null) rs1.close(); String query=""; query = " SELECT Aper, Dest, PassengerName, Address, Phone " +" FROM "+trainTableName +" WHERE TicketId = '"+tfTicket.getText()+"'"; System.out.println("4\n"+query); ResultSet rs1 = stat.executeQuery(query); //System.out.println("5"); //rs.beforeFirst(); //System.out.println("6"); //System.out.println("7"); rs1.next(); //{ System.out.println("Ok"); //else //{ tfAper.setText(rs1.getString("Aper")); tfDest.setText(rs1.getString("Dest")); tfPassName.setText(rs1.getString("PassengerName")); tfPassAddress.setText(rs1.getString("Address")); tfPassPhone.setText(rs1.getString("Phone")); System.out.println(tfPassName.getText()); //System.out.println(queryResult); //labelQuery.setText(queryResult); //break; //} rs1.close(); StringBuffer passSeat=new StringBuffer(taCompSeat.getText()); passSeat.deleteCharAt(0); passSeat.deleteCharAt(passSeat.length()-1); ArrayList arrSeat=new ArrayList(1); //String tableName=(String)comboTrain.getSelectedItem(); //int a=tableName.indexOf("Date"); //LeftSide.arrOfPass_ApDesDaTiCompSeTickCoNaAdPhIDaIti // .add(1,tableName.substring(0,a-1)); //arrSeat.add(); int s=0,e=0; while(true) { e=passSeat.indexOf(",", e); if(e<0)break; arrSeat.add((passSeat.substring(s,e).trim())); passSeat.delete(s,e+1); } //passSeat.delete(s,e+1); arrSeat.add((passSeat.substring(s).trim())); Object ob[]=new Object[500]; for(int j=0;j<arrSeat.size();j++) ob[j]=arrSeat.get(j); listSeatList.setListData(ob); doLayout(); System.out.println(arrSeat); tfIssueDate.setEditable(false); tfIssueTime.setEditable(false); tfDate.setEditable(false); tfTime.setEditable(false); tfTrain.setEditable(false); tfAper.setEditable(false); tfDest.setEditable(false); taCompSeat.setEditable(false); //tfDest.setEditable(false); tfCost.setEditable(false); //tfCost.setEditable(false); listSeatList.setEnabled(true); tfPassName.setEditable(false); tfPassAddress.setEditable(false); tfPassPhone.setEditable(false); labelIssueDate.setEnabled(true); labelIssueTime.setEnabled(true); labelDate.setEnabled(true); labelTime.setEnabled(true); labelTrain.setEnabled(true); labelAper.setEnabled(true); labelDest.setEnabled(true); labelCompSeat.setEnabled(true); //labelDest.setEditable(false); labelSeatList.setEnabled(true); labelCost.setEnabled(true); //tfCost.setEditable(false); labelPassName.setEnabled(true); labelPassAddress.setEnabled(true); labelPassPhone.setEnabled(true); buttonOk.setEnabled(true); buttonCancel.setEnabled(true); } catch(ClassNotFoundException cnfe) { System.out.println("Error " + cnfe); } catch(SQLException sqle) { System.out.println("Error1 " + sqle); } } else if(ae.getSource()==buttonOk) { Object selectedListItem[]=listSeatList.getSelectedValues(); //String str[]=selectedListItem.toString(); //for(int g=0;g<selectedListItem.length;g++) // System.out.print("\t"+selectedListItem[g]); try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); // force loading of driver String url = "jdbc:odbc:sazib"; String user = "PUBLIC"; String password = "PUBLIC"; Connection conn = DriverManager.getConnection(url, user,password); Statement stat = conn.createStatement(); //ResultSet.TYPE_SCROLL_INSENSITIVE, //ResultSet.CONCUR_READ_ONLY); System.out.println(); //public ResultSet rs; //public ResultSet rs1; for(int g=0;g<selectedListItem.length;g++) { String compSeat=""; String comp="",seat=""; if(((String)selectedListItem[g]).indexOf('C')!=-1) { int index=((String)selectedListItem[g]).indexOf('C'); comp=((String)selectedListItem[g]).substring(0,index); seat=((String)selectedListItem[g]).substring(index); System.out.println(comp+"\t"+seat); } else if(((String)selectedListItem[g]).indexOf('W')!=-1) { int index=((String)selectedListItem[g]).indexOf('W'); comp=((String)selectedListItem[g]).substring(0,index); seat=((String)selectedListItem[g]).substring(index); System.out.println(comp+"\t"+seat); } String update = "UPDATE "+trainTableName +"\nSET SeatStatus='0', Aper='', Dest=''," +" TicketId='', PassengerName='', Address = ''," +" Phone='', Taka='0.00'" +"\nWHERE Comp='"+comp+"'" +" AND Seat='"+seat+"'" +" AND TicketId = '"+tfTicket.getText()+"'"; System.out.println(update); System.out.println("2"); int i = stat.executeUpdate(update); System.out.println("3"); update = "UPDATE Ticket " +"\nSET IssueDate='', IssueTime=''" +", JourneyDate='', JourneyTime='', Train=''" +", CompSeat=''" +", Taka=''" +" WHERE TicketId='"+tfTicket.getText()+"'"; System.out.println(update); System.out.println("2"); i = stat.executeUpdate(update); System.out.println("3"); } } catch(ClassNotFoundException cnfe) { System.out.println("Error " + cnfe); } catch(SQLException sqle) { System.out.println("Error1 " + sqle); } for(int j=LeftSide.arrOfPass_ApDesDaTiCompSeTickCoNaAdPhIDaIti.size()-1;j>13;j=j-2) { int flag=0; JButton b =(JButton)LeftSide.arrOfPass_ApDesDaTiCompSeTickCoNaAdPhIDaIti.get(j); if("1".compareTo(b.getToolTipText())==0) { b.setToolTipText("0"); ImageIcon img=new ImageIcon("blank.gif"); b.setIcon(img); } LeftSide.arrOfPass_ApDesDaTiCompSeTickCoNaAdPhIDaIti.remove(j); LeftSide.arrOfPass_ApDesDaTiCompSeTickCoNaAdPhIDaIti.remove(j-1); } } else if(ae.getSource()==buttonCancel) { for(int j=LeftSide.arrOfPass_ApDesDaTiCompSeTickCoNaAdPhIDaIti.size()-1;j>13;j=j-2) { int flag=0; JButton b =(JButton)LeftSide.arrOfPass_ApDesDaTiCompSeTickCoNaAdPhIDaIti.get(j); if("-1".compareTo(b.getToolTipText())==0) { ImageIcon img=new ImageIcon("rejected.gif"); b.setIcon(img); } else if("0".compareTo(b.getToolTipText())==0) { ImageIcon img=new ImageIcon("blank.gif"); b.setIcon(img); } else if("1".compareTo(b.getToolTipText())==0) { ImageIcon img=new ImageIcon("booked.gif"); b.setIcon(img); } LeftSide.arrOfPass_ApDesDaTiCompSeTickCoNaAdPhIDaIti.remove(j); LeftSide.arrOfPass_ApDesDaTiCompSeTickCoNaAdPhIDaIti.remove(j-1); } doLayout(); setVisible(false); } } } class PrintPanel extends JPanel implements Printable { public void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2 = (Graphics2D)g; drawPage(g2); } public int print(Graphics g, PageFormat pf, int page) throws PrinterException { if (page >= 1) return Printable.NO_SUCH_PAGE; Graphics2D g2 = (Graphics2D)g; g2.setPaint(Color.black); g2.translate(pf.getImageableX(), pf.getImageableY()); g2.draw(new Rectangle2D.Double(0, 0, pf.getImageableWidth(), pf.getImageableHeight())); drawPage(g2); return Printable.PAGE_EXISTS; } public void drawPage(Graphics2D g2) { FontRenderContext context = g2.getFontRenderContext(); Font f = new Font("Times", Font.ROMAN_BASELINE, 10); GeneralPath clipShape = new GeneralPath(); TextLayout layout = new TextLayout("TicketId | "+(InfoOfSeatReserveDialog.tfTicket).getText(), f, context); AffineTransform transform = AffineTransform.getTranslateInstance(0, 72); Shape outline = layout.getOutline(transform); clipShape.append(outline, false); layout = new TextLayout("Train"+(String)LeftSide .arrOfPass_ApDesDaTiCompSeTickCoNaAdPhIDaIti.get(1), f, context); transform= AffineTransform.getTranslateInstance(0, 92); outline = layout.getOutline(transform); clipShape.append(outline, false); layout = new TextLayout("Aper | "+(InfoOfSeatReserveDialog.tfAper).getText()+" || Dest | " +(InfoOfSeatReserveDialog.tfDest).getText(), f, context); transform= AffineTransform.getTranslateInstance(0, 112); outline = layout.getOutline(transform); clipShape.append(outline, false); layout = new TextLayout("JourneyDate | "+(InfoOfSeatReserveDialog.tfDate).getText()+" || JourneyTime | " +(InfoOfSeatReserveDialog.tfTime).getText(), f, context); transform= AffineTransform.getTranslateInstance(0, 132); outline = layout.getOutline(transform); clipShape.append(outline, false); layout = new TextLayout("CompSeat | "+(InfoOfSeatReserveDialog.tfPassSeat).getText(), f, context); transform= AffineTransform.getTranslateInstance(0, 152); outline = layout.getOutline(transform); clipShape.append(outline, false); layout = new TextLayout("IssueDate | "+(String)LeftSide.arrOfPass_ApDesDaTiCompSeTickCoNaAdPhIDaIti.get(6) +" || IssueTime | "+(String)LeftSide.arrOfPass_ApDesDaTiCompSeTickCoNaAdPhIDaIti.get(7), f, context); transform= AffineTransform.getTranslateInstance(0, 172); outline = layout.getOutline(transform); clipShape.append(outline, false); layout = new TextLayout("Taka | "+(InfoOfSeatReserveDialog.tfCost).getText(), f, context); transform= AffineTransform.getTranslateInstance(0, 192); outline = layout.getOutline(transform); clipShape.append(outline, false); layout = new TextLayout("Name | "+(InfoOfSeatReserveDialog.tfName).getText(), f, context); transform= AffineTransform.getTranslateInstance(0, 212); outline = layout.getOutline(transform); clipShape.append(outline, false); layout = new TextLayout("Address | "+(InfoOfSeatReserveDialog.tfAddress).getText(), f, context); transform= AffineTransform.getTranslateInstance(0, 232); outline = layout.getOutline(transform); clipShape.append(outline, false); layout = new TextLayout("Phone | "+(InfoOfSeatReserveDialog.tfPhone).getText(), f, context); transform= AffineTransform.getTranslateInstance(0, 252); outline = layout.getOutline(transform); clipShape.append(outline, false); g2.draw(clipShape); g2.clip(clipShape); final int NLINES =50; Point2D p = new Point2D.Double(0, 0); for (int i = 0; i < NLINES; i++) { double x = (2 * getWidth() * i) / NLINES; double y = (2 * getHeight() * (NLINES - 1 - i)) / NLINES; Point2D q = new Point2D.Double(x, y); g2.draw(new Line2D.Double(p, q)); } System.out.println("Printing"); } } Thanks in advanced