/** This program shows how ConsoleGraphics does the hard work of "rendering" your drawing commands onto the console. @author Charlie McDowell */ class CGTest { public static void main(String[] args) throws java.io.IOException { // ConsoleGraphics cg = new ConsoleGraphics(70,30); SwingGraphics cg = new SwingGraphics(70,30); // put something in the frame drawBox(cg,2,3,50,25); drawLine(cg,15,5,40,10); cg.render(); // notice that the outline of the ConsoleGraphics is already included System.in.read(); // pause cg.render(); // notice how it forgets drawBox(cg,2,3,50,25); // notice this doesn't display if not followed by render System.in.read(); // pause cg.render(); // now it shows up } /** Draw a box on the specified graphics device. */ static void drawBox(TGraphics graphics, int left, int top, int width, int height) { graphics.drawLine(left, top, left+width, top); graphics.drawLine(left, top+height, left+width, top+height); graphics.drawLine(left, top, left, top+height); graphics.drawLine(left+width, top, left+width, top+height); } /** Draw a line on the specified graphics device. */ static void drawLine(TGraphics graphics, int x1, int y1, int x2, int y2) { graphics.drawLine(x1, y1, x2, y2); } }