Page 4 of 5 FirstFirst ... 2345 LastLast
Results 61 to 80 of 87
  1. #61
    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. #62
    Sarinam is offline Senior Member
    Join Date
    Jun 2008
    Posts
    121
    Rep Power
    0

    Default

    Quote Originally Posted by Eranga View Post
    I'm not delete content on the file directly. Delete content from the list and write data from list to the file. That's way you have to follow.
    i do it sir

    Thxs for help

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

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

    Default

    Quote Originally Posted by Eranga View Post
    Is that everything is working fine?
    yes sir just i comment on that line and fixed the values of i=1; and it is working fine..

    Java Code:
    //int j = Integer.parseInt(dataScan.nextLine());
     int  i=1;
    arp.remove(itemIndexes[i-1]);
    Sir one more question what i want when my code run that time all data show in list box...

    How can i do tha..

  5. #65
    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

    In that case you remove the first element of the list. Not the selected line on list box. Just check it.

    I'm not clear your question also.

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

    Default

    Quote Originally Posted by Eranga View Post
    In that case you remove the first element of the list. Not the selected line on list box. Just check it.

    I'm not clear your question also.
    See my question is:-- In My file10 items presents.And when code is run then i want to show autometically in list boxt or we can say auto load in list box..

    Plz help me

  7. #67
    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

    As you done, all components of the GUI are initialized in load time of the frame. Everything is done on the constructor. So what you have to do is call the text set method on the list box in the constructor too.

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

    Default

    Quote Originally Posted by Eranga View Post
    As you done, all components of the GUI are initialized in load time of the frame. Everything is done on the constructor. So what you have to do is call the text set method on the list box in the constructor too.
    Sir when i use

    Java Code:
    public abc (Frame parent) 
    {
    SERVERS.addItem("One");
    
    }
    then it is working but when i use

    Java Code:
    public abc (Frame parent) 
    {
     for(int i=0;i<arp.size();i++)
     {  							 SERVERS.addItem(arp.get(i).toString());
    }
    }
    then it is not working

    help me

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

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

    Default

    Quote Originally Posted by Eranga View Post
    No, it should work. Ok send me the new code you have at this point to see.
    Ok Sir

    Java Code:
    public class ABCDlg extends Dialog
    {
    
    
    	/**
    	 * 
    	 */
    	private static final long serialVersionUID = 1L;
    
    	private Frame      parent;
    	
    	private Button     OK;
    	private Button     CANCEL;
    	private List       SERVERS;	
    	private TextField  ADDSERVER;	
    	private Button	   ADD;
    	private Button     DELET;
    	private ArrayList<String> data;
        private Scanner dataScan;
        private String strLine;
    	private ArrayList<String> arp;
    
    
    	@SuppressWarnings("deprecation")
    	public ABCDlg (Frame parent) 
    	{
    		super(parent, "IP Block", true);
    
    		 data = new ArrayList<String>();
    		 arp = new ArrayList<String>();	
    		OK = new Button("OK");
    		CANCEL = new Button("CANCEL");
    		SERVERS = new List(10, true);
    		ADDSERVER = new TextField(15);	
    		ADD = new Button("<<Add");
    		DELET = new Button("Delete");
    		
    	 	setLayout(new GridBagLayout());
    		addToBag(this, SERVERS,    	0, 0, 1, 3, 1.0,0.0);
    		addToBag(this, ADD,        	1, 0, 1, 1, 0.0,0.0);
    		addToBag(this, ADDSERVER,  	2, 0, 2, 1, 0.0,0.0);
    		addToBag(this, DELET,     	1, 1, 1, 1, 0.0,0.0);
    		addToBag(this, CANCEL,	   	2, 4, 1, 1, 0.0,0.0);
    		addToBag(this, OK,         	3, 4, 1, 1, 0.0,0.0);
    		
    			
    		pack();
    
    		Point location = parent.location();
    		Point fatherLocation = location;
    		move(fatherLocation.x + 100,fatherLocation.y + 100);
    		show();
    
    	}
    
    
    	private void addToBag(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);
    	}
    
    
    	@SuppressWarnings("deprecation")
    	public boolean action(Event evt, Object arg) 
    	{
    		
    		if (evt.target instanceof Button) {
    			if (evt.target == OK) {
    				return updateDB();
    			}
    			else if (evt.target == CANCEL) {
    				hide();
    				dispose();
    				return true;
    			}
    
                   // Here writing in file
    			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()){
        					  FileWriter fstreama = new FileWriter("xeee.txt", true);
        					  BufferedWriter out = new BufferedWriter(fstreama);
        					if(ADDSERVER.getText().equals("")){
        						ADDSERVER.requestFocus();
        					}
        					else{
        						out.write(ADDSERVER.getText());
        						if(f.canWrite()){
        					   
        							ADDSERVER.setText("");
        						    out.newLine();
        					
        						}
        					    else{
        					    	
        							}
        						out.close();
    
                    // Here reading from file
        						FileInputStream fis = null;
        				        try {
        				            fis = new FileInputStream("xeee.txt");
        				            BufferedReader br = new BufferedReader(new InputStreamReader(fis));
        				            
        				            String line = null;
        				            while((line = br.readLine()) != null){
        				                      arp.add(line);
        				            }
        				        } 
        				        catch (IOException ex) {
        				            System.out.println(ex.getMessage());
        				        }        
        				        finally {
        				            try {
        				                fis.close();
        				            } 
        				            catch (IOException ex) {
        				                System.out.println(ex.getMessage());
        				            }
        				        }
        				       
        				        for(int i=0;i<arp.size();i++)
        						 {
        					    	
        							 SERVERS.addItem(arp.get(i).toString());
    
        						 }
    						}
        					}
    					else{
    						}
        				
    				}
    			
    			catch(Exception x){
    				x.printStackTrace();
    			}
    		
    			
    				return true;
    			}
        				
    			else if (evt.target == DELET) {
    				
    				removeData();
    				return true;
    			}
    		
    		}
    		return false;
    	}
    
    // deleting from file 
    	 private void removeData() {
    		 int[] itemIndexes = SERVERS.getSelectedIndexes();
    			
    			
    			for (int i = itemIndexes.length-1; i>=0; i--)
    			{
    				SERVERS.delItem(itemIndexes[i]);
    				
    			}
    	        dataScan = new Scanner(System.in);
    	    
    	      
    	        int  j=1;
    	     
    	        arp.remove(itemIndexes[j-1]);
    	        
    	     
    		    	
    	        	 
    			
    	        writeDataBack();
    	    }
    
    // here again write back in same file
    	 private void writeDataBack() {
    	        FileWriter fw = null;
    	        int x = 0;
    	        try{
    	            fw = new FileWriter("xeee.txt");
    	            BufferedWriter out = new BufferedWriter(fw);
    
    	            while(x < arp.size()) {
    	            
    	                out.write(arp.get(x));
    	                out.newLine();
    	                x++;
    	            }
    
    	            out.close();
    	        }
    	        catch(IOException ioex){
    	            System.out.println(ioex.getLocalizedMessage());
    	        }        
    	    }
    Last edited by Sarinam; 06-27-2008 at 11:39 AM.

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

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

    Default

    Quote Originally Posted by Eranga View Post
    Please use code tags correctly next time. :)
    Sorry sir next time i will send in proper formate..
    Sir you have found solution of my problem..

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

    Default

    Quote Originally Posted by Eranga View Post
    Please use code tags correctly next time. :)
    sir give me tips to solve that problem

  14. #74
    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 have no idea what you have done in your code. You just coding here and there, I can't figure out whats going on. You have to learn a lot my friend. :)

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

    Default

    Quote Originally Posted by Eranga View Post
    I have no idea what you have done in your code. You just coding here and there, I can't figure out whats going on. You have to learn a lot my friend. :)
    Sir what i have writen in code i give,i know you are right but i know you have also solution.So plz help out

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

    Default

    Quote Originally Posted by Eranga View Post
    I have no idea what you have done in your code. You just coding here and there, I can't figure out whats going on. You have to learn a lot my friend. :)
    in post
    Java Code:
    #70 (permalink)
    i have add some commect like..Plz check it and help me

  17. #77
    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

    Read data and right data, better to implement in two methods and call them in the correct event. That's the better way, concepts in OO quite follows that.

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

    Default

    Quote Originally Posted by Eranga View Post
    Read data and right data, better to implement in two methods and call them in the correct event. That's the better way, concepts in OO quite follows that.
    ok sir

    just i do it...

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

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

    Default

    Quote Originally Posted by Eranga View Post
    Hey, did you have tried anything until now?
    Yes sir no benifit.I have still same problem..

Page 4 of 5 FirstFirst ... 2345 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
  •