This Java program draws different shapes - ovals and rectangles - at the location of mouse clicks within a window. Each mouse click increments a counter, and the shape drawn depends on the counter value modulo 4, alternating between ovals of different sizes and rectangles of different aspect ratios. The window is resized to 500x500 pixels.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
38 views
Program 11
This Java program draws different shapes - ovals and rectangles - at the location of mouse clicks within a window. Each mouse click increments a counter, and the shape drawn depends on the counter value modulo 4, alternating between ovals of different sizes and rectangles of different aspect ratios. The window is resized to 500x500 pixels.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 3
11.
SHAPES
SOURCE CODE
import java.awt.*;
class MouseShapes extends Frame {
int mouseX=0,mouseY=0; static int count=0; public boolean mouseDown(Event evtObj,int x,int y) { mouseX=x; mouseY=y; count++; repaint(); return true; }
public void paint(Graphics g) {
switch(count%4) { case 0:g.drawOval(mouseX,mouseY,mouseX+100,mouseY+100); break; case 1:g.drawOval(mouseX,mouseY,mouseX+50,mouseY+100); break; case 2:g.drawRect(mouseX,mouseY,mouseX+50,mouseY+50); break; case 3:g.drawRect(mouseX,mouseY,mouseX+50,mouseY+100); }