Programming Projects 1. Write a program that draws the patterns shown in Figure 3G.33 onto a DrawingPanel. Dinwn y Fauel
java program of following attachment
import java.awt.*;
import javax.swing.*;
import java.io.*;
import java.util.*;
import java.lang.*;
public class TestDrawing extends JFrame {
int initialx,initialy;
public TestDrawing(int x,int y){
this.initialx=x;
this.initialy=y;
}
public void Display()
{
setBackground(Color.CYAN);
setTitle("Drawing Panel");
setSize(400+initialx,400+initialy);
setVisible(true);
setLocationByPlatform(true);
setDefaultCloseOperation(EXIT_ON_CLOSE);
}
@Override
public void paint(Graphics g)
{
Graphics2D g2d = (Graphics2D)g;
drawSquaresD(g,"TL",0,0,100,5,1,1);
drawSquaresD(g,"BL",10,100,20,4,7,7);
drawSquaresD(g,"TR",20,20,30,5,6,6);
drawSquaresD(g,"BR",100,30,30,4,4,4);
}
public void drawSquaresD(Graphics g,String p,int x,int y, int size,int n, int r,int c){
int ir,ic,in;
switch(p){
case "BL":
y=getHeight()-(y+(size*r))-initialy;
break;
case "TR":
x=getWidth()-(x+(size*c))-initialx;
break;
case "BR":
x=getWidth()-(x+(size*c))-initialx;
y=getHeight()-(y+(size*r))-initialy;
break;
case "TL": default:
break;
}
x=x+initialx;
y=y+initialy;
for(ir=0;ir<r;ir++){
for(ic=0;ic<c;ic++){
g.setColor(Color.GREEN);
int x1,y1;
x1=x+(ic*size);
y1=y+(ir*size);
g.fillRect(x1,y1,size,size);
int j=0;
for(in=n;in>0;in--){
int sizec=(size/n)*in;
int sizecc=((size/2)/n)*j;
g.setColor(Color.YELLOW);
g.fillOval(x1+sizecc,y1+sizecc,sizec,sizec);
g.setColor(Color.BLACK);
g.drawOval(x1+sizecc,y1+sizecc,sizec,sizec);
j++;
Trending now
This is a popular solution!
Step by step
Solved in 2 steps