// CSE 142, Spring 2010, Marty Stepp // This program demonstrates the use of DrawingPanel to create // simple 2-D graphics. // You need to download DrawingPanel.java from our course web site // to the same folder as this program in order to compile/run it. import java.awt.*; // so that I can use Graphics g public class DrawFun { public static void main(String[] args) { // create a window on the screen DrawingPanel panel = new DrawingPanel(600, 300); panel.setBackground(Color.YELLOW); Graphics g = panel.getGraphics(); g.setColor(Color.GREEN); // x y w h g.fillRect(10, 30, 70, 60); g.setColor(new Color(192, 128, 64)); // brown - custom color g.drawRect(10, 30, 70, 60); g.setColor(Color.BLUE); g.drawOval(70, 40, 90, 50); g.drawRect(70, 40, 90, 50); // draw a 2D grid of enlarging filled circles g.setColor(Color.CYAN); for (int j = 1; j <= 3; j++) { for (int i = 1; i <= 10; i++) { // x y w h g.fillOval(120 + 30*i, 40 + 50*j, 20 + 2*i, 20 + 2*i); } } } }