You are on page 1of 4

Hi Manmay, I have done the Window Search Project which basically consists of two clas s files.

They are : 1) MainFrame - This is class which consists of the Design Part. 2) FileSearch - This is class which consists of the Business Logic Part. Thus by this the advantage is that Design part and the Business Logic are i ndependent of each other. The functionality of the project is to intially run the MainFrame class whi ch provides us the Frame to search the files in the directory. Just place the name of the folder which you want to search in the fir st text field(Enter Search) and in the other text field give the root directory of where to search the folder or file(Search In) and hit the key Search. The code mainly consists of the recursive manner to search the files and fo lders in the current directory given. It goes into all the directories and gets the result the Text Area provided.

http://www.java2s.com/Code/Java/Collections-Data-Structure/Getthesizeofanarrayli stafterandbeforeaddandremovemethods.htm import java.awt.*; import java.io.*; import javax.swing.table.*; import javax.swing.*; import java.sql.*; import java.awt.Graphics; import java.awt.event.*; import java.util.*; public class first extends JFrame implements ActionListener { String s1="Welcome to Chennai Library"; JPanel p1=(JPanel)getContentPane(); JButton b1=new JButton("Search books by title"); JButton b2=new JButton("exit"); public first() { try { JLabel jl1=new JLabel(" WELCOME TO LIBRARY INFORMATION SYSTEMS "); jl1.setFont(new Font("Comic Sans",Font.BOLD,28)); p1.add(jl1); p1.setLayout(new FlowLayout(100,100,100)); b1.addActionListener(this); b2.addActionListener(this); p1.add(b1); p1.add(b2); myactions my=new myactions(); addWindowListener(my); } catch(Exception ex){} }

class myactions extends WindowAdapter { public void windowClosing(WindowEvent e) { System.exit(0); } } class seconds extends JFrame { public seconds() { try { JPanel p2=(JPanel)getContentPane(); p2.setLayout(new FlowLayout()); JLabel jl2=new JLabel("Enter the book title"); String s2="Text"; final JTextField jt2=new JTextField(s2,25); final JButton jb2=new JButton("Search"); final JButton jb21=new JButton("Cancel"); p2.add(jl2); p2.add(jt2); p2.add(jb2); p2.add(jb21); setSize(500,500); setVisible(true); setTitle("search books by title"); p2.repaint(); jb21.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent ae) { if(ae.getSource()==jb21) { dispose(); } } }); jb2.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent ae) { if(ae.getSource()==jb2) { try { DefaultTableModel dt=new DefaultTableModel(); JTable jt=new JTable(dt); Object[] data=new Object[6]; try{ Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection cp=DriverManager.getConnection("jdbc:odbc:data1","",""); Statement st=cp.createStatement(); ResultSet rs=st.executeQuery("select booktitle,author from booklist where bookti tle=jt2.getText()");

ResultSetMetaData rt=rs.getMetaData(); int row=rt.getColumnCount(); for(int j=1;j<=row;j++) { System.out.println(rt.getColumnName(j)); dt.addColumn(rt.getColumnName(j)); } while(rs.next()) { for(int j=0;j<row;j++) { data[j]=rs.getString(j+1); } dt.addRow(data); } JTableHeader header = jt.getTableHeader(); header.setBackground(Color.yellow); JScrollPane pane = new JScrollPane(jt); //Container cp1=getContentPane(); frame2=new JFrame("book list"); frame2.add(pane); frame2.setVisible(true); frame2.setBounds(610,0,400,200); } catch(Exception e){} }

catch(Exception exe){} } } }); } catch(Exception exe){} } } public void actionPerformed(ActionEvent e) { if(e.getSource()==b1) { seconds s=new seconds(); } else if(e.getSource()==b2) { System.exit(0); } } public static void main(String args[]) { first f=new first(); f.setTitle("home"); f.setSize(500,500);

f.setVisible(true); } }

You might also like