This site requires JavaScript, please enable it in your browser!
Greenfoot back
vicbuenaventura
vicbuenaventura wrote ...

2016/3/30

How to display text from file in the World class

vicbuenaventura vicbuenaventura

2016/3/30

#
The following code reads text from file and displays it in the console via System.out.println command. Instead of displaying it in the console, how do you display it in the Greenfoot World?
public void showExpertMessage ()
    {

        try{

FileInputStream fstream = new FileInputStream("gatekeeperoutput.txt");
  // Get the object of DataInputStream
DataInputStream in = new DataInputStream(fstream);
  BufferedReader br = new BufferedReader(new InputStreamReader(in));
  String strLine;
  //Read File Line By Line
  while ((strLine = br.readLine()) != null)   {
  // Print the content on the console
  System.out.println (strLine);
  
  }
  //Close the input stream
  in.close();
    }catch (Exception e){//Catch exception if any
  System.err.println("Error: " + e.getMessage());
    
    
    }
        
}    
Sir_brandon_ Sir_brandon_

2016/3/30

#
.
danpost danpost

2016/3/30

#
vicbuenaventura wrote...
How to display text from file in the World class how do you display it in the Greenfoot World?
Do you want to have the text drawn onto the world background image (will it fit there?) or do you want to use an Actor object with text on its image?
davmac davmac

2016/3/30

#
Perhaps take a look at this example.
vicbuenaventura vicbuenaventura

2016/4/1

#
Thank you all for your feedback. I just needed to display the last line of text in the World. I was able to do this using the showText method from the World class.
You need to login to post a reply.