☰ Contents The Main Thing

Main and Pict

Student: OK, I think I see how main is the starting point for programs we run from the terminal. So how do I print an image?
Prof: If you just print a Pict value, you’ll get its record-style printing:
Prof: That’s because System.out.println only knows about text – it turns every value it gets into a string and prints that. There’s a different function that comes with the image library to show images. It’s called ImageIO_.show(...) and it takes a Pict:
Prof: That shows the image in the book the way we’ve been doing it right along. If you run it from somewhere else, like Visual Studio Code’s terminal, it should pop up in a separate window. If you’re in a web browser or somewhere that can’t show you a new window, it will save it to a file.
Student: I see. So different kinds of output require different kinds of methods. What does ImageIO mean?
Prof: The IO stands for “input/output”, which is a common abbreviation in libraries. It’s the way provided with images to output them (we’ll see some other ways to input them later, like reading in an image from a file).
Student: OK, I think I get it.

Practice

fr is the French flag from before. Finish main so that running this file shows it.
void main() {
Pict fr = new Beside(new Rect(30, 60, "blue"),
new Beside(new Rect(30, 60, "white"),
new Rect(30, 60, "red")));

}