/*
*/
import java.awt.*;
import java.applet.*;
import java.util.*;
import java.awt.event.*;
import ManagePanel;
public class BoxPerim extends Applet {
Graphics h;
ManagePanel mp;
Image offscreenImg, backImg;
boolean bob;
String perim;
static int blocksize = 25;
public void init() {
bob = true;
mp = new ManagePanel();
backImg = getImage(getCodeBase(),"back.jpg");
offscreenImg = createImage(this.size().width, this.size().height);
h = offscreenImg.getGraphics();
perim = "";
repaint();
}
public void paint(Graphics g){
h.drawImage(backImg,0,0,this);
if (bob) {
// g.setFont(new Font("TimesRoman",Font.BOLD,14));
h.drawString("Show",36,132);
h.drawString("Perimeter",25,146);
h.drawString("Area:", 20, 197);
} else {
// g.setFont(new Font("TimesRoman",Font.BOLD,36));
h.drawString("Perimeter:",25,132);
h.drawString("" + perim, 46, 147);
h.drawString("Area:", 20, 197);
}
mp.show(h);
g.drawImage(offscreenImg,0,0,this);
g.drawString("" + Grid.count, 50, 197);
}
public void update(Graphics g) {
paint(g);
}
public boolean mouseUp(Event evt, int x, int y) {
mp.up(x,y);
repaint();
return true;
}
public boolean mouseDown(Event evt, int x, int y) {
bob = true;
System.out.println("X: "+x+" Y: "+y);
mp.down(x,y);
if (x >= 31 && x <=56)
if (y>=57 && y <=82)
mp.addObj(new Box(31,57,x,y));
if (x >= 47 && x <=64)
if (y>=269 && y <= 300){
blocksize += 2;
for (int i = 1; i<=Grid.count; i++){
mp.up(x,y);
}
}
if (x >= 21 && x <=38)
if (y>=269 && y <= 300){
blocksize -= 2;
for (int i = 1; i<=Grid.count; i++){
mp.up(x,y);
}
}
if (x >= 11 && x <=75)
if (y>=114 && y <=175) {
bob = false;
perim = ""+mp.enterGrid();
}
repaint();
return true;
}
public boolean mouseDrag(Event evt, int x, int y) {
mp.drag(x,y);
repaint();
return true;
}
} // End class
///////////////////
class Box {
int x, y, pointOnImageX,pointOnImageY;
boolean select;
public Box(int x, int y,int pointOnImageX, int pointOnImageY) {
this.x = x;
this.y = y;
this.pointOnImageX = x-pointOnImageX;
this.pointOnImageY = y-pointOnImageY;
select = true;
}
public int getX() {
return x;
}
public int getY() {
return y;
}
public void setX(int x) {
this.x = x;
}
public void setY(int y) {
this.y = y;
}
public void show (Graphics g) {
int colorinc;
if (BoxPerim.blocksize <= 0)
colorinc = 250;
else
colorinc = 250 / BoxPerim.blocksize;
for (int i=0;i= x && x1 <= x+BoxPerim.blocksize) {
if (y1 >= y && y1 <=y+BoxPerim.blocksize) {
return true;
}
}
select = false;
return false;
}
public void deselect() {
setX( ( (getX()-13) /BoxPerim.blocksize) *BoxPerim.blocksize+13);
setY( ( (getY()-13) /BoxPerim.blocksize) *BoxPerim.blocksize+13);
select = false;
}
public void select(int pointOnImageX1,int pointOnImageY1) {
pointOnImageX = x-pointOnImageX1;
pointOnImageY = y-pointOnImageY1;
select = true;
}
public void objectDrag(int x, int y) {
if (select) {
this.x=(x+pointOnImageX);
this.y=(y+pointOnImageY);
}
}
} // End class
////////////////////////////////////////////////////////////////////////
class Grid {
boolean [][] a;
int max;
static int count;
public Grid(int max) {
this.max = max;
a = new boolean [max][max];
reset();
}
public void reset() {
count = 0;
for (int i=0;i < max;i++) {
for (int j=0;j < max;j++) {
a[i][j] = false;
}
}
}
public void addBox(int x, int y){
a[x][y] = true;
}
public void deselectBox(int x, int y){
a[x][y] = false;
}
public void count() {
int x=0;
for(int i=0; i