Results 1 to 4 of 4
  1. #1
    ai_2007 is offline Member
    Join Date
    Jun 2007
    Posts
    21
    Rep Power
    0

    Default 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);
    }
    }

  2. #2
    JavaBean's Avatar
    JavaBean is offline Moderator
    Join Date
    May 2007
    Posts
    1,270
    Rep Power
    9

    Default

    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!

  3. #3
    ai_2007 is offline Member
    Join Date
    Jun 2007
    Posts
    21
    Rep Power
    0

    Default 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);
    }
    }

  4. #4
    JavaBean's Avatar
    JavaBean is offline Moderator
    Join Date
    May 2007
    Posts
    1,270
    Rep Power
    9

    Default

    I mean something like this:

    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");
    }
    }
    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!

Similar Threads

  1. How To Edit/Add JSP Pages in NetBeans IDE
    By JavaForums in forum NetBeans
    Replies: 2
    Last Post: 02-17-2009, 12:14 PM
  2. Can't edit JTextField after modal dialog
    By JavaNerd in forum Java Applets
    Replies: 0
    Last Post: 02-07-2008, 10:11 PM
  3. Replies: 3
    Last Post: 12-26-2007, 07:42 AM
  4. Replies: 5
    Last Post: 08-11-2007, 04:14 AM
  5. how to edit lines.
    By jason27131 in forum New To Java
    Replies: 1
    Last Post: 08-01-2007, 05:41 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •