//import java.applet.*; // applet stuff import javax.swing.*; import java.awt.*; // Abstract Windowing Toolkit: graphics stuff public class Ovals extends JApplet { public void paint (Graphics g) { drawOvals(g, 10,10); } public void drawOvals (Graphics g, int rows, int cols) { Dimension screenSize = getSize(); // Get the applet's size int cellWidth = (screenSize.width - (cols + 1))/cols; // subtract off grid lines int cellHeight = (screenSize.height - (rows + 1))/rows; // subtract off grid lines // Draw grid lines g.setColor(Color.black); for (int x = 0; x <= screenSize.width-1 ; x = x + cellWidth + 1) { g.drawLine(x, 0, x, screenSize.height-1); // Vertical grid lines } for (int y = 0; y <= screenSize.height-1; y = y + cellHeight + 1) { g.drawLine(0, y, screenSize.width-1, y); // Horizontal grid lines } g.setColor(Color.red); for (int row = 1; row <= rows; row++) { for (int col = 1; col <= cols; col++) { g.setColor(new Color(row * 255/rows, 0, col * 255/cols)); g.fillOval((col - 1)*(cellWidth + 1) + 1, (row - 1)*(cellHeight + 1) + 1, (col * cellWidth)/cols, (row * cellHeight)/rows); } } } }