Results 1 to 6 of 6
  1. #1
    MR bruto's Avatar
    MR bruto is offline Senior Member
    Join Date
    May 2013
    Location
    The Netherlands
    Posts
    127
    Rep Power
    0

    Default Reading and outputtin multiple lines with a BufferedReader.

    hey.
    i am creating an application for myself in which you can do tasks in the Command prompt, and then shows the result in a JTextArea.
    such as a "MyIP" button, "Systeminfo", "ipconfig" etc.
    although im having a little problem here.
    im trying to program the "systeminfo" and "ipconfig" button.

    the problem:
    i can't seem to get the full system information displayed in the text area.
    i only get the very very last line of the system info displayed in the text area.

    anyways, im not really familiar with textarea's yet since i haven't used them a lot before.

    here is the code for the button:
    Java Code:
    JButton btnNewButton = new JButton("System Info");
    		btnNewButton.addActionListener(new ActionListener() {
    			public void actionPerformed(ActionEvent e) {
    				try 
    				{ 
    				Process p=Runtime.getRuntime().exec("cmd /c systeminfo"); 
    				BufferedReader reader=new BufferedReader(new InputStreamReader(p.getInputStream()));
    				
    				
    				String line=reader.readLine(); 
    				while(line!=null) 
    				{ 
    				
    				textArea.setText(line);
    				line=reader.readLine(); 
    				
    				
    				
    				
    				} 
    				
    
    				} 
    				catch(IOException e1) {
    					e1.printStackTrace();
    				} 
    				
    				
    			}
    		});

    i'm guessing that it has something to do with .readLine(), i think that it only reads one line. but i currently dont know how to read multiple lines and then display them in the textarea.

    i also tried displaying the systeminfo in a JOptionPane, but that results in about 80 JOptionPanes popping up.

    i hope anyone can help me,

    thanks in advance.
    Never give up.

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,452
    Rep Power
    20

    Default Re: Reading and outputtin multiple lines with a BufferedReader.

    Quote Originally Posted by MR bruto View Post
    i'm guessing that it has something to do with .readLine(), i think that it only reads one line.
    No, it has to do with the setText(...). What do you expect that method does?
    Quote Originally Posted by MR bruto View Post
    but i currently dont know how to read multiple lines and then display them in the textarea.
    Read the API for JText Area. You'll want the first method listed.

    And when you get that sorted out, don't forget to add the newlines that readLine() skips over.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  3. #3
    MR bruto's Avatar
    MR bruto is offline Senior Member
    Join Date
    May 2013
    Location
    The Netherlands
    Posts
    127
    Rep Power
    0

    Default Re: Reading and outputtin multiple lines with a BufferedReader.

    Quote Originally Posted by DarrylBurke View Post
    No, it has to do with the setText(...). What do you expect that method does?

    Read the API for JText Area. You'll want the first method listed.

    And when you get that sorted out, don't forget to add the newlines that readLine() skips over.

    db
    i THINK that that method sets the text that the readLine() collects. which in this case is probably the very last line.

    anyways, im going to read the API first now.
    Never give up.

  4. #4
    MR bruto's Avatar
    MR bruto is offline Senior Member
    Join Date
    May 2013
    Location
    The Netherlands
    Posts
    127
    Rep Power
    0

    Default Re: Reading and outputtin multiple lines with a BufferedReader.

    Quote Originally Posted by DarrylBurke View Post
    No, it has to do with the setText(...). What do you expect that method does?

    Read the API for JText Area. You'll want the first method listed.

    And when you get that sorted out, don't forget to add the newlines that readLine() skips over.

    db
    Thanks a hella lot man!

    i used the append method.

    but im now struggling with my JScrollBar, which is not scrolling through the textarea
    Last edited by MR bruto; 07-04-2013 at 11:44 PM.
    Never give up.

  5. #5
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,452
    Rep Power
    20

    Default Re: Reading and outputtin multiple lines with a BufferedReader.

    Quote Originally Posted by MR bruto View Post
    im now struggling with my JScrollBar, which is not scrolling through the textarea
    If you need help with that, start a new thread in the Swing/AWT section. Have you gone through the tutorial linked from the JScrollPane API?

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  6. #6
    MR bruto's Avatar
    MR bruto is offline Senior Member
    Join Date
    May 2013
    Location
    The Netherlands
    Posts
    127
    Rep Power
    0

    Default Re: Reading and outputtin multiple lines with a BufferedReader.

    Quote Originally Posted by DarrylBurke View Post
    If you need help with that, start a new thread in the Swing/AWT section. Have you gone through the tutorial linked from the JScrollPane API?

    db
    oops sorry man, got it working already. i just have to read more often ;)

    Thanks anyways
    Never give up.

Similar Threads

  1. Reading part of file with BufferedReader
    By mattgavin in forum New To Java
    Replies: 2
    Last Post: 11-13-2010, 03:44 AM
  2. Reading a file from Applet (BufferedReader)
    By Java Tip in forum Java Tip
    Replies: 1
    Last Post: 06-22-2008, 11:51 PM
  3. Reading file contents (BufferedReader)
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 02-07-2008, 10:00 AM
  4. Reading int values using BufferedReader
    By Java Tip in forum Java Tip
    Replies: 2
    Last Post: 01-24-2008, 08:26 PM
  5. Reading text from a URL using BufferedReader
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 12-26-2007, 11:17 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
  •