Results 1 to 4 of 4
Thread: Doubt in edit and delete methods
- 07-01-2007, 10:03 AM #1
Member
- Join Date
- Jun 2007
- Posts
- 21
- Rep Power
- 0
Doubt in edit and delete methods
Are these edit and delete methods correct?
Java Code:**To delete bus number of any buses*/ public void deleteRecord(String busnum){ for(int i=0; i><buses.size(); i++){ Bus b = (Bus)buses.get(i); if((b.getBusnum()).compareTo(busnum)==0) buses.removeElementAt(i); } }
Java Code:/**To edit record in the file*/ public void editRecord(String busnum){ for(int i=0; i><buses.size(); i++){ Bus b = (Bus)buses.get(i); if((b.getBusnum()).compareTo(busnum)==0){ buses.removeElementAt(i); } buses.insertElementAt((Object)i,1); } }
- 07-01-2007, 10:09 AM #2
The first one looks correct.
For the second one: instead of removing and reinserting a bus you should directly call object methods to change its properties!
- 07-01-2007, 10:55 AM #3
Member
- Join Date
- Jun 2007
- Posts
- 21
- Rep Power
- 0
Correction
I am not sure of how to do that. But is the below correct?
Java Code:/**To edit record in the file*/ public void editRecord(String busnum){ for(int i=0; i><buses.size(); i++){ Bus b = (Bus)buses.get(i); if((b.getBusnum()).compareTo(busnum)==0){ buses.insertElementAt((Object)i,1); } }
- 07-01-2007, 11:40 AM #4
I mean something like this:
So in this example, i access the name property of a bus and change its name by calling its setName(String name) method. The method you need to call all depends on what you mean by editing!Java Code:/**To edit record in the file*/ public void editRecord(String busnum){ for(int i=0; i><buses.size(); i++){ Bus b = (Bus)buses.get(i); if((b.getBusnum()).compareTo(busnum)==0){ b.setName("New Bus"); } }
Similar Threads
-
How To Edit/Add JSP Pages in NetBeans IDE
By JavaForums in forum NetBeansReplies: 2Last Post: 02-17-2009, 11:14 AM -
Can't edit JTextField after modal dialog
By JavaNerd in forum Java AppletsReplies: 0Last Post: 02-07-2008, 09:11 PM -
I need help with my java servlet homework(add,edit and delete)
By jellyfish888 in forum Java ServletReplies: 3Last Post: 12-26-2007, 06:42 AM -
Edit JPanel Text During Runtime...from another class
By bdn1404 in forum New To JavaReplies: 5Last Post: 08-11-2007, 03:14 AM -
how to edit lines.
By jason27131 in forum New To JavaReplies: 1Last Post: 08-01-2007, 04:41 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks