Title
Author
Link http://thunked.org/p/view/pub/
Created 2012-05-29 03:14:51
Expires never
Filename
Language Java
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
45.
46.
47.
48.
49.
50.
51.
52.
53.
54.
55.
56.
57.
58.
59.
60.
61.
62.
63.
64.
65.
66.
67.
68.
69.
70.
71.
72.
73.
74.
75.
76.
77.
78.
79.
80.
81.
82.
83.
84.
85.
86.
87.
88.
89.
90.
public class BookSearchView extends FrameView {

    ArrayList <String> books = new ArrayList <String>();
    String bookList[] = null;
    int bookNum[] = null;
    String fileName = "/home/opnet/BookList.txt";

[cut a bunch of code]

private void getBooks(ArrayList <String> arrayList, int numArray[], String strArray[], String file)
    {
        BufferedReader readIn = null;

        try {
            readIn = new BufferedReader(new FileReader(file));

            // loop until all lines have been read in
            while(readIn.ready())
                arrayList.add(readIn.readLine());

        } catch(IOException e) {
            e.printStackTrace();
        } finally {
            try {
                readIn.close();
            } catch(IOException e) {
                    e.printStackTrace();
            }
        }

        numArray = new int[arrayList.size()/2];
        strArray = new String[arrayList.size()/2];

        if(numArray == null)
            System.out.println("array is emtpy");

        // loop through the entire arraylist seperating
        // all the strings and integers into different
        // arrays.
        for(int i = 0; i < books.size(); i++)
        {
            int count1 = 0;
            int count2 = 0;

            if(i%2 == 0)
            {
                numArray[count1] = Integer.parseInt(arrayList.get(i));
                count1++;
            }

            else
            {
                strArray[count2] = arrayList.get(i);
                count2++;
            }

        }
    }

    private void findTitleButtonActionPerformed(java.awt.event.ActionEvent evt) {
        int ID = 0;
        String bookName = "";

        if(books.isEmpty())
            getBooks(books, bookNum, bookList, fileName);

        if(bookNum == null)
            System.out.println("ARRAY IS NULL!");
       
        ID = Integer.parseInt(inputField.getText());

        for(int i = 0; i < bookNum.length; i++)
        {
            if(ID == bookNum[i])
                bookName = bookList[i];
            else
                bookName = "REFERENCE NUMBER NOT FOUND!";
        }

        outputLinear.setText(bookName);

        if(binarySearch(bookNum, ID))
            bookName = bookList[ID];

        else
            bookName = "REFERENCE NUMBER NOT FOUND!";
       
        outputBinary.setText(bookName);
    }
}