// Demonstrates fish and canvas features import java.awt.*; import javax.swing.*; import java.io.*; import java.util.*; public class FishDemo { // main(): application entry point public static void main(String[] args) throws IOException { JFrame window = new JFrame("Fish still life"); window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); window.setSize(1000, 1000); window.setVisible(true); Canvas canvas = new Canvas(); canvas.setSize(1000, 1000); canvas.setBackground(Color.BLUE); Container c = window.getContentPane(); FlowLayout manager = new FlowLayout(); c.setLayout(manager); c.add(canvas); int x = 300; int y = 300; System.out.print("Enter any character when ready."); char inChar; Graphics g = canvas.getGraphics(); do { inChar = (char)System.in.read(); g.clearRect(0, 0, 1000, 1000); Fish fish1 = new Fish(); Fish fish2 = new Fish(); switch (inChar){ case 'k': { x = x + 10; System.out.println("x = " + x); break; } case 'j': { x = x - 10; System.out.println("x = " + x); break; } case 'i': { y = y - 10; System.out.println("y = " + y); break; } case 'm': { y = y + 10; System.out.println("y = " + y); break; } } Random die = new Random(); fish1.setPosition(x, y); fish1.paint(g); fish2.setPosition(x + 50 + die.nextInt(60), y + 50 + die.nextInt(60)); fish2.paint(g); }while(inChar !='e'); } }