import java.applet.Applet; import java.awt.event.*; import java.awt.*; import java.awt.geom.*; /*This is a basic class for a rectangular button button*/ public class ListenSquare { public double x,y,w,h; public int on; public Color C; public ListenSquare () {} /*square*/ public ListenSquare(double x,double y,double r,Color C) { this.x=x; this.y=y; this.C=C; this.w=r; this.h=r; this.on=0; } /*rectangle*/ public ListenSquare(double x,double y,double w,double h,Color C) { this.x=x; this.y=y; this.C=C; this.w=w; this.h=h; this.on=0; } public int inside(Point p) { int test=0; if((p.x>x)&&(p.xy)&&(p.y=1) g.setColor(CC); g.fillRect((int)(x),(int)(y),(int)(w),(int)(h)); g.setColor(C); if(on!=0) g.setColor(Color.white); g.drawRect((int)(x),(int)(y),(int)(w),(int)(h)); } public void render(Graphics g,Color CC,String S) { if(on==0) g.setColor(new Color(0,0,0)); if(on>=1) g.setColor(CC); g.fillRect((int)(x),(int)(y),(int)(w),(int)(h)); g.setColor(C); if(on!=0) g.setColor(Color.white); g.drawRect((int)(x),(int)(y),(int)(w),(int)(h)); g.setColor(Color.white); g.drawString(S,(int)(x+5),(int)(y+12)); } public void render2(Graphics g,Color CC) { if(on==0) g.setColor(new Color(0,0,0)); if(on>=1) g.setColor(CC); g.fillRect((int)(x),(int)(y),(int)(w),(int)(h)); g.setColor(Color.white); g.drawRect((int)(x),(int)(y),(int)(w),(int)(h)); } public void render2(Graphics g,Color CC,Color C2) { if(on==0) g.setColor(new Color(0,0,0)); if(on>=1) g.setColor(CC); g.fillRect((int)(x),(int)(y),(int)(w),(int)(h)); g.setColor(C2); g.drawRect((int)(x),(int)(y),(int)(w),(int)(h)); } public void infoRender(Graphics g) { g.setColor(new Color(0,0,0)); g.fillRect((int)(x),(int)(y),(int)(w),(int)(h)); g.setColor(Color.white); g.drawRect((int)(x),(int)(y),(int)(w),(int)(h)); g.setFont(new Font("Helvetica",Font.PLAIN,10)); g.drawString("?",(int)(x+4),(int)(y+10)); } /**These routines interact with the enhanced 2D graphics class*/ public void renderSmooth(Graphics2D g,Color C1,Color C2) { Polygon P=new Polygon(); float X[]={(float)(this.x),(float)(this.x+0),(float)(this.x+this.w),(float)(this.x+this.w)}; float Y[]={(float)(this.y),(float)(this.y+this.h),(float)(this.y+this.h),(float)(this.y+0)}; GeneralPath path=new GeneralPath(); path.moveTo(X[0],Y[0]); for(int i=1;i<4;++i) path.lineTo(X[i],Y[i]); path.closePath(); g.setColor(C1); g.fill(path); g.setColor(C2); g.draw(path); } public void renderSmooth(Graphics2D g) { Polygon P=new Polygon(); float X[]={(float)(this.x),(float)(this.x+0),(float)(this.x+this.w),(float)(this.x+this.w)}; float Y[]={(float)(this.y),(float)(this.y+this.h),(float)(this.y+this.h),(float)(this.y+0)}; GeneralPath path=new GeneralPath(); path.moveTo(X[0],Y[0]); for(int i=1;i<4;++i) path.lineTo(X[i],Y[i]); path.closePath(); g.setColor(Color.white); g.setStroke(new BasicStroke(3)); g.draw(path); g.setStroke(new BasicStroke(1)); } }