![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Apr 2005
Posts: 8
Rep Power: 0
![]() |
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. |
|
|
|
|
|
#2 |
|
Professional Programmer
|
Well, this is how i see it:
while (found != false) {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 ! |
|
|
|
|
|
#3 |
|
Newbie
Join Date: Apr 2005
Posts: 8
Rep Power: 0
![]() |
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. |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|