Code:
import java.applet.Applet;
import java.awt.Color;
import java.awt.Graphics;
public class Rect extends Applet {
int x, y, h, w;
@Override
public void init() {
// TODO Auto-generated method stub
super.init();
setSize(500, 500);
x = 10;
y = 100;
h = 300;
w = 200;
}
@Override
public void paint(Graphics g) {
// TODO Auto-generated method stub
super.paint(g);
for (int i = 0; i < 20; i++) {
x = x + 5;
y = y + 5;
h = h - 10;
w = w - 10;
if (i % 2 == 0) {
g.setColor(Color.black);
g.fillRect(x, y, h, w);
} else {
g.setColor(Color.white);
g.fillRect(x, y, h, w);
}
}
}
}
Output
Coding By Sumit Bamania
Thanks ;)
import java.applet.Applet;
import java.awt.Color;
import java.awt.Graphics;
public class Rect extends Applet {
int x, y, h, w;
@Override
public void init() {
// TODO Auto-generated method stub
super.init();
setSize(500, 500);
x = 10;
y = 100;
h = 300;
w = 200;
}
@Override
public void paint(Graphics g) {
// TODO Auto-generated method stub
super.paint(g);
for (int i = 0; i < 20; i++) {
x = x + 5;
y = y + 5;
h = h - 10;
w = w - 10;
if (i % 2 == 0) {
g.setColor(Color.black);
g.fillRect(x, y, h, w);
} else {
g.setColor(Color.white);
g.fillRect(x, y, h, w);
}
}
}
}
Output
Coding By Sumit Bamania
Thanks ;)
vahiyat coding
ReplyDelete