Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Apr 29th, 2005, 6:26 PM   #1
Vengeance
Newbie
 
Join Date: Apr 2005
Posts: 8
Rep Power: 0 Vengeance is on a distinguished road
Unhappy Problem with a while loop. (Worked it out ;p)

public void searchBtn_actionPerformed(ActionEvent e) {

        String searchfilmName = searchtxtbox.getText().toLowerCase();
        boolean found = false;


        try {
            store.setFileName("FilmDatabase.jds");
            store.setUserName("odeon");
            store.setPassword("1234");
            table.setStoreName("FILMTABLE");
            table.setStore(store);
            table.open();

            table.setSort(new SortDescriptor(new String[] {"FILMID"}));
            table.first();

            while (found != false) {

                table.getInt("FILMID");
                String filmName;

                filmName = table.getString("FILMNAME").toLowerCase();

                if (filmName.equals(searchfilmName.toLowerCase())) {
                    displayInfo();
                    found = true;
                    break;
                }

                else {
                    Frame4 form = new Frame4();
                    form.setSize(500, 550);
                    form.setVisible(true);
                    this.hide();
                }
                table.next();
            }

        } catch (DataSetException dse) {
            dse.printStackTrace();
        } finally {
            try {
                store.close();
                table.close();
            } catch (DataSetException dse) {
                dse.printStackTrace();
            }
        }

    }


    public void displayInfo() {

    Frame2 form = new Frame2();
    form.setSize(500,550);
    form.setVisible(true);
    this.hide();

    }

Sorry for posting the same program again but I'm having a diff problem with it now :/. Ok, this program is supposed to allow a user to enter a movie name and search for it. Once they've clicked the button, the program should then check the database for that movie, if it's not there then go to frame4(error page), if it's found then open frame2.

Now, when I put table.inbounds() in the while statement. The program opens the frame if the movie is found, however, it also opens frames to the error page (frame 4) for any film that is not what they were searching for after the corrent film in the collumn.

Meaning that if I search for "hitch" which is like number 4 in the table then it will open frame 2 and then open about 4 frame4 (error page)

So, I decided to use the boolean found so that it would end if the movie was found. For some reason which I don't know, when I hit search NO windows open, even if the film is in the database or not...

I have no idea why no frames open up...confused :/.

Any help would be much appreciated.

Last edited by Vengeance; Apr 30th, 2005 at 11:21 AM. Reason: Worked the problem out.
Vengeance is offline   Reply With Quote
Old Apr 30th, 2005, 1:01 AM   #2
xavier
Professional Programmer
 
xavier's Avatar
 
Join Date: Oct 2004
Location: .ro
Posts: 406
Rep Power: 5 xavier is on a distinguished road
Send a message via Yahoo to xavier
Well, this is how i see it:

while (found != false) {
is not correct cause it will only go into the while loop if found == true. So change that to : found != true.
Next it enters the while loop. If your film is fourth, it will show the notFound window 3 times i believe.
if(film found on step 1)break;else (error);
if(film found on step 2)break;else (error);
and so on.

What you should do is in my opinion
if (filmName.equals(searchfilmName.toLowerCase())) {
                    displayInfo();
                    found = true;
                    break;
                }

if(endOfTable){
                    Frame4 form = new Frame4();
                    form.setSize(500, 550);
                    form.setVisible(true);
                    this.hide();
                }

You have to somehow determine if there are any more entries in your movie table, and if you have reached the end and you haven't yet found the movie, so no break happend .... show the error paged.

I hope i explained it right
__________________
Don't take life too seriously, it's not permanent !
xavier is offline   Reply With Quote
Old Apr 30th, 2005, 10:39 AM   #3
Vengeance
Newbie
 
Join Date: Apr 2005
Posts: 8
Rep Power: 0 Vengeance is on a distinguished road
Nvm, thanx, I worked it out myself. You helped me a lot, thanx.

(btw, I'm talking about working the 2nd prob out, you helped me solve the first prob ;p.)

Thanks!

Last edited by Vengeance; Apr 30th, 2005 at 11:47 AM.
Vengeance is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 11:16 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC