Page 2 of 3 FirstFirst 123 LastLast
Results 21 to 40 of 42
  1. #21
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

  2. #22
    Mir
    Mir is offline Senior Member
    Join Date
    Mar 2008
    Posts
    447
    Rep Power
    7

    Default

    Quote Originally Posted by Eranga View Post
    Only call the file creation part within that event.
    in which event.On New Button or Delete All Button...

  3. #23
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Oh man, you have to decide on which button you want to do it. You are the person who knows what you want.

  4. #24
    Mir
    Mir is offline Senior Member
    Join Date
    Mar 2008
    Posts
    447
    Rep Power
    7

    Default

    Quote Originally Posted by Eranga View Post
    Oh man, you have to decide on which button you want to do it. You are the person who knows what you want.
    Sir file creation code all ready have in deleteAllFromFile().So where i call once more time..Plz tell help me sir...

  5. #25
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    On new button, you want to clear the existing file and create a new one. So, call that function in new button event.

  6. #26
    Mir
    Mir is offline Senior Member
    Join Date
    Mar 2008
    Posts
    447
    Rep Power
    7

    Default

    Quote Originally Posted by Eranga View Post
    On new button, you want to clear the existing file and create a new one. So, call that function in new button event.
    Sir i do that no changes in out put.....

    Plz help me sir

    Java Code:
    private void addUserData() {
    	        SERVERS.clear();
    	        
    	        try{
    	    		// Create file 
    	    		FileWriter fstream = new FileWriter("px.txt");
    	            BufferedWriter out = new BufferedWriter(fstream);
    	    		//out.write("Hello Java");
    	    		//Close the output stream
    	    		out.close();
    	    		}catch (Exception e){//Catch exception if any
    	    			System.err.println("Error: " + e.getMessage());
    	    		}
    	        populateData();
    	  //   String temp = ADDSERVER.getText();
    	       
    	        String temp=JOptionPane.showInputDialog("ENTER Name");
    	       
    	       
    	       if(!temp.equals("")) 
    	       {
    	    	   SERVERS.addItem(temp);
    	            recordData(temp);
    	       }
    	        
    	      
    	        writeFile();
    	}

  7. #27
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Try to debug and see what happened, and in which is the place that data added to the file. What the populateData() method do in your application?

  8. #28
    Mir
    Mir is offline Senior Member
    Join Date
    Mar 2008
    Posts
    447
    Rep Power
    7

    Default

    Quote Originally Posted by Eranga View Post
    Try to debug and see what happened, and in which is the place that data added to the file. What the populateData() method do in your application?
    ok sir i am going to debug it.then i will tell you updated..

  9. #29
    Mir
    Mir is offline Senior Member
    Join Date
    Mar 2008
    Posts
    447
    Rep Power
    7

    Default

    Quote Originally Posted by Eranga View Post
    Try to debug and see what happened, and in which is the place that data added to the file. What the populateData() method do in your application?
    Sir each and evry thing i try whatever you told me.But i am not abel to get it.Sir i send you code which is given by you.Plz help me ..

    Java Code:
    import java.awt.*;
    import java.awt.event.*;
    import java.io.*;
    import java.util.ArrayList;
    
    /**
     *
     * @author Eranga Tennakoon
     */
    public class SarinamDemo extends Dialog {
    
        private Button ok, cancel, add, delete;
        private TextField textField;
        private List list;
        private ArrayList<String> data;
        private boolean isFind;
        
        public SarinamDemo(Frame perent) {
            super(perent, "Demo" , true);
            
            readFile();
            
            ok = new Button("Ok");
            cancel = new Button("Cancel");
            add = new Button("<<Add");
            delete = new Button("Delete");
            textField = new TextField(15);
            list = new List(10, true);
            
            setLayout(new GridBagLayout());
            addToContainer(this, list, 0, 0, 1, 3, 1,0);
            addToContainer(this, add, 1, 0, 1, 1, 0, 0);
            addToContainer(this, textField, 2, 0, 2, 1, 0,0);
            addToContainer(this, delete, 1, 1, 1, 1, 0, 0);
            addToContainer(this, cancel, 2, 4, 1, 1, 0, 0);
            addToContainer(this, ok, 3, 4, 1, 1, 0, 0);
            
            populateData();        
            pack();
            addWindowListener(new WindowAdapter() {
                @Override
                public void windowClosing(WindowEvent e) {
                    System.exit(0);
                }
            });
            setResizable(true);
            setVisible(true);
    
        }
    
        private void addToContainer(Container container, Object arg, 
                int x, int y, int w, int h, double weightx, double weighty) {
            GridBagLayout gbl = (GridBagLayout)container.getLayout();
            GridBagConstraints c = new GridBagConstraints();
            Component component;
    
            c.fill = GridBagConstraints.BOTH;
            c.gridx = x;
            c.gridy = y;
            c.gridwidth = w;
            c.gridheight = h;
            c.weightx = weightx;
            c.weighty = weighty;
    
            component = (Component)arg;
            container.add(component);
            gbl.setConstraints(component, c);
        }
        
        @Override
        public boolean action(Event evt, Object arg) {
            if(evt.target == add) {
                addUserData();
                return true;
            }
            else if(evt.target == delete) {
                removeUserData();
            }
            else if(evt.target == ok) {
                
            }
            else {
                System.exit(0);
                return true;
            }
            return false;
        }
        
        private void readFile() {
            data = new ArrayList<String>();
            FileInputStream fileIn = null;
            String line;
    
            try {
                fileIn = new FileInputStream("files/demo.txt");
                InputStreamReader inReader = new InputStreamReader(fileIn);
                BufferedReader bufReader = new BufferedReader(inReader);
                
                while((line = bufReader.readLine()) != null) {
                    recordData(line);
                }
                bufReader.close();
            }
            catch(IOException ex) {
                ex.printStackTrace();
            }
        }
        
        private void writeFile() {
            FileWriter fw = null;
            try {
                fw = new FileWriter("files/demo.txt");
                BufferedWriter bufWriter = new BufferedWriter(fw);
                
                for(int i = 0; i < data.size(); i++) {
                    bufWriter.write(data.get(i).toString());
                    bufWriter.newLine();
                }
                bufWriter.close();
            }
            catch(IOException e) {
                e.printStackTrace();
            }
        }
        
        private void recordData(String str) {
            if(data.isEmpty()) {
               data.add(str);
            }
            else if(isDuplicate(str)) {
                data.add(str);
            }
        }
        
        private boolean isDuplicate(String str) {
            String temp;
            for(int i = 0; i < data.size(); i++) {
                temp = data.get(i).toString();
                if(!str.equals(temp)) {
                    isFind = true;
                }
                else {
                    return false;
                }
            }
            return isFind;
        }
        
        private void populateData() {
            for(int i = 0; i < data.size(); i++) {
                list.add(data.get(i));
            }
        }
        
        private void addUserData() {
            list.removeAll();
            populateData();
            String temp = textField.getText();
            if(!temp.isEmpty()) {
                list.add(temp);
                recordData(temp);
            }
            writeFile();
        }
        
        private void removeUserData() {
            String temp = list.getSelectedItem();
            list.removeAll();
            data.remove(temp);
            populateData();
            writeFile();
        }
        
        public static void main(String[] args) {
            Frame f = new Frame();
            new SarinamDemo(f);
        }
    }

  10. #30
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

  11. #31
    Mir
    Mir is offline Senior Member
    Join Date
    Mar 2008
    Posts
    447
    Rep Power
    7

    Default

    Quote Originally Posted by Eranga View Post
    There I can't see and deletion of a file. Is it?
    yes sir you are right...But you can do there very easy..So plz sir help me..

    I think you like kidding....

    Plz plz help me

  12. #32
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    I don't want to do it pal. I gave the way and you have to try it. I'm not a person who codding for others here in the forum, ok.

  13. #33
    Mir
    Mir is offline Senior Member
    Join Date
    Mar 2008
    Posts
    447
    Rep Power
    7

    Default

    Quote Originally Posted by Eranga View Post
    I don't want to do it pal. I gave the way and you have to try it. I'm not a person who codding for others here in the forum, ok.
    ok just you told me on that where i call file creation and deletion ..Nothing more..

  14. #34
    Mir
    Mir is offline Senior Member
    Join Date
    Mar 2008
    Posts
    447
    Rep Power
    7

    Default

    Quote Originally Posted by Eranga View Post
    There I can't see and deletion of a file. Is it?
    plz give me idea in that code which one i post(your code)....Plz help me

  15. #35
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Add your new method in that class, and call it in the correct event. How many times I told you this. But seems to me you don't have make an attempt to do it.

  16. #36
    Mir
    Mir is offline Senior Member
    Join Date
    Mar 2008
    Posts
    447
    Rep Power
    7

    Default

    Quote Originally Posted by Eranga View Post
    Add your new method in that class, and call it in the correct event. How many times I told you this. But seems to me you don't have make an attempt to do it.
    Sir i attem all those things.I fallow you each step but i cann't get solution.I am saying you are right but it's my problem i havn't get solution becouse i am wrong.

    your direction is 100% right...

  17. #37
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

  18. #38
    Nicholas Jordan's Avatar
    Nicholas Jordan is offline Senior Member
    Join Date
    Jun 2008
    Location
    Southwest
    Posts
    1,018
    Rep Power
    8

    Exclamation cann't get ants to crawl ....

    Quote Originally Posted by Mir View Post
    Sir I attempted all those things.......
    I tried to read all of the posts, got dizzy. I keep seeing if ( ! File.exists() ) which says if file does not exist, then we have an if delete.

    Well, to start off with, real file deletion would be coded if file exists: RandomAccessFile AntsCantCrawl = new Random access file. While next byte ~ byte == scambled byte. Then set length == 0, then go to the shell and do the delete:
    Java Code:
    if(file.exists())return file.delete();
    else throw  new Exception ( " No file to delete " );//
    Introduction to Programming Using Java.
    Cybercartography: A new theoretical construct proposed by D.R. Fraser Taylor

  19. #39
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    We need a real work from Nic, form our thread starter here. How many times I told the same thing to test, but no sign of doing it.

  20. #40
    Mir
    Mir is offline Senior Member
    Join Date
    Mar 2008
    Posts
    447
    Rep Power
    7

    Default

    Quote Originally Posted by Eranga View Post
    We need a real work from Nic, form our thread starter here. How many times I told the same thing to test, but no sign of doing it.
    Hi

    After all i got solution.Eranga code was right but small thing i was missing.ArrayList data was not clear.So i use [code]data.clear()[code] in DeleteAll Button and code is working fine..

    Thxs for Help..Once Again you are 100% right..


    Thxs

Page 2 of 3 FirstFirst 123 LastLast

Similar Threads

  1. Remove duplicate lines from a text file
    By Dirt.Diver in forum New To Java
    Replies: 15
    Last Post: 06-25-2008, 02:08 PM
  2. read the file from different line number
    By vaskarbasak in forum Advanced Java
    Replies: 3
    Last Post: 06-02-2008, 01:31 PM
  3. Replies: 0
    Last Post: 01-20-2008, 06:07 AM
  4. Reading in data from file line by line
    By bluekswing in forum New To Java
    Replies: 1
    Last Post: 10-02-2007, 12:19 AM
  5. How to remove Control Characters from an input file?
    By renjan in forum Advanced Java
    Replies: 0
    Last Post: 08-01-2007, 03:33 PM

Posting Permissions

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