Page 2 of 5 FirstFirst 1234 ... LastLast
Results 21 to 40 of 87
  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
    19

    Default

    Quite simple that is.

    Java Code:
            ArrayList<String> atl = new ArrayList<String>();
            atl.add("One");
            atl.add("Two");
            atl.add("Three");
            atl.add("Four");
            atl.add("Five");
            for(int i = 0; i < atl.size(); i++) {
                jTextArea1.append(atl.get(i).toString()+"\n");
            }

  2. #22
    Sarinam is offline Senior Member
    Join Date
    Jun 2008
    Posts
    121
    Rep Power
    0

    Default

    Quote Originally Posted by Eranga View Post
    Quite simple that is.

    Java Code:
            ArrayList<String> atl = new ArrayList<String>();
            atl.add("One");
            atl.add("Two");
            atl.add("Three");
            atl.add("Four");
            atl.add("Five");
            for(int i = 0; i < atl.size(); i++) {
                jTextArea1.append(atl.get(i).toString()+"\n");
            }
    Sir i am use like this but not geting plz help me
    Java Code:
    else if (evt.target == ADD) {
    				if (ADDSERVER.getText() != "")  
    					SERVERS.addItem(ADDSERVER.getText());
    				
    				
    				try {
            			
        				String str ="xeee.txt";
        				File f = new File(str);
        				if(f.exists()){
        					BufferedWriter out = new BufferedWriter(new FileWriter("xeee.txt",true));
        					if(ADDSERVER.getText().equals("")){
        						ADDSERVER.requestFocus();
        					}
        					else{
        						out.write(ADDSERVER.getText());
        						if(f.canWrite()){
        					   
        							ADDSERVER.setText("");
        						     out.newLine();
        						
        						
        						}
        						
        						else{
        						
        						}
        						out.close();
        						}
        					 try{
    
        							FileInputStream fstream = new FileInputStream("xeee.txt");
    
        							DataInputStream in = new DataInputStream(fstream);
        					        BufferedReader br = new BufferedReader(new InputStreamReader(in));
        							String strLine;
        							 ArrayList<String>	arp = new ArrayList<String>();
        							 while ((strLine = br.readLine()) != null) 	{
        								
        								 arp.add(strLine);
        								
    								        for(int i = 0; i < arp.size(); i++) {
    								        	ADDSERVER.setText(arp.get(i).toString()+"\n");
    								        }
        								    
        								}
    
        							 
    									
    									
        							in.close();
        							}catch (Exception e){
        								System.err.println("Error: " + e.getMessage());
        							}
    
        					}
        					else{
        						}
        				}
        			
        			catch(Exception x){
        				x.printStackTrace();
        			}
        		}
    
    					return true;
    			}

  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
    19

    Default

    Do the things separately. First add data to the list, and completing it get the data and add them to the text area.

  4. #24
    Sarinam is offline Senior Member
    Join Date
    Jun 2008
    Posts
    121
    Rep Power
    0

    Default

    Quote Originally Posted by Eranga View Post
    Do the things separately. First add data to the list, and completing it get the data and add them to the text area.
    sir

    now i add in listbox in separately.Now what happen only "two" add in this list. Plz help me

    Java Code:
     ArrayList<String> asl=new ArrayList<String>();
        							 asl.add("one");
        							 asl.add("Two");
        							 
        							 for(int i=0;i<asl.size();i++)
        							 {
        								 ADDSERVER.setText(asl.get(i).toString());
        								
    
        							 }

  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
    19

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

    Default

    Oh, you have made a mistake. You can't setText() on text are. Because in that case only the text displayed find finally. What you have to do is, append data.

    Change this,

    Java Code:
    ADDSERVER.setText(asl.get(i).toString());
    like this

    Java Code:
    ADDSERVER.append(asl.get(i).toString() + "\n");

  7. #27
    Sarinam is offline Senior Member
    Join Date
    Jun 2008
    Posts
    121
    Rep Power
    0

    Default

    Quote Originally Posted by Eranga View Post
    Oh, you have made a mistake. You can't setText() on text are. Because in that case only the text displayed find finally. What you have to do is, append data.

    Change this,

    Java Code:
    ADDSERVER.setText(asl.get(i).toString());
    like this

    Java Code:
    ADDSERVER.append(asl.get(i).toString() + "\n");
    Ok sir

    Now it is working...

    What a next step sie..

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

    Default

    What you mean? You want to add data to the text area from the array list which are collected from a file. It's working. So how I know that your next step, you should know it.

  9. #29
    Sarinam is offline Senior Member
    Join Date
    Jun 2008
    Posts
    121
    Rep Power
    0

    Default

    Quote Originally Posted by Eranga View Post
    Display all read line to a text area first, at the same time keep them recorded in ArrayList. Then remove the selected line from the text are and refer the selected item index to remove from the List.
    Last Day you told me that you do like this..That i was asking to you what's next step..

    And Now


    Quote Originally Posted by Eranga View Post
    What you mean? You want to add data to the text area from the array list which are collected from a file. It's working. So how I know that your next step, you should know it.
    Sorry sir but i think you just forget about this thraed..I am kiding sir..

    I hope you will give me good responce..

  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
    19

    Default

    Ah, you know actually sometimes I forget whats going on a thread. Because on a day I deal with large number of threads. And also I have to deal with my works at office.

    You really want to do is, read a file, remove duplicates and display the rest on text ares, right?

  11. #31
    Sarinam is offline Senior Member
    Join Date
    Jun 2008
    Posts
    121
    Rep Power
    0

    Default

    Quote Originally Posted by Eranga View Post
    Ah, you know actually sometimes I forget whats going on a thread. Because on a day I deal with large number of threads. And also I have to deal with my works at office.

    You really want to do is, read a file, remove duplicates and display the rest on text ares, right?
    i think you forget my main question.My main question is i want add add through add button,which is working and delete particular data through delete button.

    Right now code is store data through add button and also store in arraylist and display in textarea.

    Now main problem is that how i remove from the .txt file and textarea.

    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
    19

    Default

    Seems I'm mess with this too. :)

    Anyway, get the selected text from the text area. Remove that line from the array list. Then populated the text are with new values from the list. Write data to the file after that.

    Are you doing this just to learn? Because you are going to dead soon. ;) Because you use the wrong component here. Don't worry at the time. Try what I say.

  13. #33
    Sarinam is offline Senior Member
    Join Date
    Jun 2008
    Posts
    121
    Rep Power
    0

    Default

    Quote Originally Posted by Eranga View Post
    Seems I'm mess with this too. :)

    Anyway, get the selected text from the text area. Remove that line from the array list. Then populated the text are with new values from the list. Write data to the file after that.

    Are you doing this just to learn? Because you are going to dead soon. ;) Because you use the wrong component here. Don't worry at the time. Try what I say.
    can you give me some code sir..

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

    Default

    Try man something, you can do it. ;)

    Anyway, you have to do something like this.

    Java Code:
        private void removeDuplicates(String str) {
            ArrayList<String> temp = new ArrayList<String>();
            if(temp.isEmpty()) {
                temp.add(str);
            }
            else {
                for(int i = 0; i < temp.size(); i++) {
                    if(!str.equals(temp.get(i))) {
                        temp.add(str);
                    }
                }
            }
        }

  15. #35
    Sarinam is offline Senior Member
    Join Date
    Jun 2008
    Posts
    121
    Rep Power
    0

    Default

    Quote Originally Posted by Eranga View Post
    Try man something, you can do it. ;)

    Anyway, you have to do something like this.

    Java Code:
        private void removeDuplicates(String str) {
            ArrayList<String> temp = new ArrayList<String>();
            if(temp.isEmpty()) {
                temp.add(str);
            }
            else {
                for(int i = 0; i < temp.size(); i++) {
                    if(!str.equals(temp.get(i))) {
                        temp.add(str);
                    }
                }
            }
        }
    Sir

    this is remove only duplicate values from file.But i need to delete the values from file..

    Plz help me

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

    Default

    Hang on man. Move step by step.

    Now you have a list without duplicates. So write them back to the file. That's it.

  17. #37
    Sarinam is offline Senior Member
    Join Date
    Jun 2008
    Posts
    121
    Rep Power
    0

    Default

    Quote Originally Posted by Eranga View Post
    Hang on man. Move step by step.

    Now you have a list without duplicates. So write them back to the file. That's it.
    Ok i am trying..

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

  19. #39
    Sarinam is offline Senior Member
    Join Date
    Jun 2008
    Posts
    121
    Rep Power
    0

    Default

    Quote Originally Posted by Eranga View Post
    Ok, try and see what happened.
    Sir

    I am not geting plz help me ..

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

Page 2 of 5 FirstFirst 1234 ... LastLast

Similar Threads

  1. [SOLVED] Delete Current line from file
    By Azndaddy in forum New To Java
    Replies: 2
    Last Post: 04-06-2012, 08:00 AM
  2. Can we lift the images restriction?
    By Cyorxamp in forum Suggestions & Feedback
    Replies: 30
    Last Post: 07-01-2008, 08:32 AM
  3. Replies: 0
    Last Post: 04-05-2008, 10:13 AM
  4. problem when I try to delete a file
    By tommy in forum Advanced Java
    Replies: 2
    Last Post: 07-31-2007, 02:44 PM
  5. How to delete a file
    By Alpha in forum New To Java
    Replies: 1
    Last Post: 05-26-2007, 08:11 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
  •